Local Memory Garbage Collection

The garbage collection engine for AI agent memory.

Vector databases retrieve similar text, but cannot resolve contradiction or time. Sieve scores memories, supersedes outdated facts, and prunes stale context with ~0.2ms local latency—without burning tokens on per-turn LLM calls.

$ pip install sieve-memory
Memory Lifecycle Demo
Step 1 of 3: Baseline Context
Step 1: Baseline Context
Agent records 2 facts into memory. Both PostgreSQL config and staging task are active in the LLM's system prompt (280 tokens).
turn 1 · id: mem_01 decision · active
Our primary database is configured as PostgreSQL 15 on port 5432.
importance: 0.65 status: in active prompt
turn 2 · id: mem_02 task · active
TODO: Deploy staging cluster before Friday's investor presentation.
actionable: 0.85 status: in active prompt
Active System Prompt Context (Fed to LLM)
280 tokens · 0 conflicts
- [DECISION] Our primary database is configured as PostgreSQL 15 on port 5432.
- [TASK] TODO: Deploy staging cluster before Friday's investor presentation.
~0.2ms
Local Scoring Latency
$0.00
API Cost per Turn
100%
Synthetic Benchmark Accuracy
42.7%
Context Bloat Pruned

Score → Supersede → Prune Pipeline #

How Sieve manages agent memories in three simple stages. It runs locally in your Python agent loop or as a background service with ~0.2ms latency in local mock benchmarks.

STAGE 01 / SCORE

Filter Out Noise

Every memory an agent records is scored in ~0.2ms. Sieve separates key decisions and tasks from casual conversation ("hello", "thanks", small talk), keeping only what truly matters.

✓ Cuts conversational bloat by up to 40% upfront
STAGE 02 / SUPERSEDE

Spot Changing Facts

When a user updates instructions (like switching from PostgreSQL to MongoDB), standard vector search gets confused. Sieve compares facts pairwise and immediately identifies that the older record is now outdated.

✓ Automatically links old facts to new updates (superseded_by)
STAGE 03 / PRUNE

Keep Prompts Clean

Before calling your LLM, Sieve evicts all outdated facts from the prompt. Your agent only sees the latest single source of truth—preventing hallucinations and slashing token costs by up to 70%.

✓ History stays safe in SQLite, but never pollutes prompt tokens
❌ Without Sieve (Raw Chat Logs / Standard Vector Search) 620 tokens · Conflicting
- [DECISION] Primary database configured as PostgreSQL 15 on port 5432.
- [DECISION] AWS ECS Fargate container selected for deployment runtime.
- [CHAT] haha yeah sounds good, let's connect later today!
- [TASK] TODO: Deploy staging cluster before Friday's investor demo.
- [DECISION] Actually, we migrated to MongoDB 7.0 for document schemas.
⚠️ Hallucination Risk: Prompt contains both PostgreSQL and MongoDB. The LLM has no way of knowing which database is current, causing wrong SQL queries and wasting tokens.
✅ With Sieve (Garbage-Collected Memory) 140 tokens · 77% Pruned
- [DECISION] Actually, we migrated to MongoDB 7.0 for document schemas.
- [TASK] TODO: Deploy staging cluster before Friday's investor presentation.
🎯 Clean Context: Outdated PostgreSQL fact was automatically superseded and pruned via deterministic pipeline behavior (~0.2ms). Zero ambiguity, faster responses, and 77% lower token bills.

Honest Performance & Scale #

Evaluated across 1,000 conversational turns simulating evolving architecture decisions and tasks. Tests run on Apple M-Series and Linux x86_64.

Architecture Approach Contradiction Resolution Per-Turn Latency 10k Turn API Cost Context Window Impact
Vector Stores (Chroma, Pinecone) Blind to Time 15ms $0.00 Returns both outdated and current facts
Generative LLM Triage (Mem0, Letta) 95% Accurate 850ms – 2,200ms ~$13.50 Constrained, introduces latency bottlenecks
Sieve (Local Heuristic Engine) Deterministic Pipeline ~0.18ms $0.00 Pruned & bounded locally without GPU
Sieve (Neural Laya Model on GPU) Calibrated ModernBERT ~25ms $0.00 True probability-calibrated supersession

Watch Supersession Detection in Real-Time #

Watch an autonomous agent session execute below in real time. As new conversation turns arrive and facts change, Sieve's deterministic pairwise engine instantly supersedes stale memories and prunes the prompt.

LIVE AGENT SIMULATOR | Turn 1 & 2 Active
Ingested Memory Stream (SQLite Store) 2 Items Active
turn: 1 · id: mem_01 decision · active
We decided to deploy PostgreSQL as our primary database engine.
importance: 0.65 status: in prompt
turn: 2 · id: mem_02 task · active
TODO: Provision staging cluster environment before Friday's demo.
actionable: 0.85 status: in prompt
Clean Injected Prompt Context (What LLM Sees) 2 Items · 180 Tokens
- [DECISION] We decided to deploy PostgreSQL as our primary database engine.
- [TASK] TODO: Provision staging cluster environment before Friday's demo.
● Turn 1 & 2 recorded. Agent operating with baseline context.
Latency: 0.16ms

Engineered for Your Existing Stack #

Drop Sieve into Python agent loops, LangChain LCEL chains, Chroma vector stores, or run as a standalone FastAPI microservice.

Embedded drop-in curation in 4 lines. Runs locally with zero external network or database dependencies.
# 1. Initialize persistent memory store (pure Python, SQLite + FTS5)
from sieve import SieveMemory

memory = SieveMemory("agent_memory.db")

# 2. Record conversation turns scoped to a session/tenant
memory.remember("Primary database is PostgreSQL.", namespace="user_88")
memory.remember("TODO: Email weekly summary to team.", namespace="user_88")

# User updates their architecture preference later in the session:
memory.remember("Actually, we migrated to MongoDB instead of PostgreSQL.", namespace="user_88")

# 3. Sweep prunes outdated PostgreSQL note (superseded_by: MongoDB)
memory.sweep(namespace="user_88")

# 4. Formatted, clean context string ready for system prompt
system_prompt_context = memory.get_context(namespace="user_88")
Link copied to clipboard