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.19ms
Local Scoring Latency
$0.00
API Cost per Turn
100%
Staleness Precision (0 False Alarms)
21% – 43%
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 & Labeled Evaluation #

Evaluated against 1,000 conversational turns and 14 adversarial ground-truth pairs testing hard negatives (clarification questions, orthogonal updates, and revisions). Verified with 60 passing tests across Apple Silicon and Linux x86_64.

Architecture Approach Contradiction Strategy Staleness Precision Staleness F1 Scoring Latency 10k Turn API Cost Context Window Impact
Vector Stores (Chroma, Pinecone) Topical Similarity (Blind to Time) ~0% (Returns Both) N/A 15ms $0.00 High hallucination risk; returns conflicting facts
Generative LLM Triage (Mem0, Letta) Autoregressive Prompts (GPT-4o) ~95.0% ~92–95% 850ms – 2,200ms ~$13.50 Prunes memory, but adds 1–2s per-turn user latency
Sieve (Local Heuristic Engine) Deterministic Overlap + Interrogative Guard 100.0% (0 false alarms) 88.9% ~0.19ms $0.00 20–43% bloat pruned locally via SQLite FTS5
Sieve (Neural Laya Model) Calibrated ModernBERT Cross-Encoder 100.0% (0 false alarms) 75.0% ~33ms GPU / ~390ms CPU $0.00 True probability-calibrated supersession without cloud API
GROUND-TRUTH EVALUATION
Adversarial Hard-Negative Resilience
Evaluated against 14 adversarial pairs in benchmarks/eval_dataset.py. Clarification questions ("What port is Postgres on?") and orthogonal architecture decisions ("Deploying Redis alongside Postgres") achieve a 0% false positive rate, ensuring critical facts are never accidentally pruned.
False Alarm Rate 0.0% (100% Precision)
DUAL SCORER ARCHITECTURE
Microsecond Heuristics & Neural Models
MockScorer (Default): Pure Python rule heuristics scoring in ~0.19ms with >5,300 items/sec throughput for zero-dependency CI and high-throughput production.

LayaScorer: Calibrated non-autoregressive ModernBERT cross-encoder with calibrated probability scores on GPU/CPU.
Scoring Latency ~0.19ms (Mock) / ~33ms (GPU)
TESTED & VERIFIED
60 Automated Tests & Concurrency
Comprehensive test suite (60 passed, 0 skipped, 0 failed) validating thread-safe SQLite operations via reentrant locks (RLock), sticky user restoration immunity, automatic FTS5 trigger cleanup on purges, and cached pairwise sweeps to eliminate redundant O(N) evaluations.
Test Suite Status 60 Passed · 0 Skipped

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