Post-retrieval correctness for AI agent memory.
Use it after your memory store retrieves candidates. It removes stale, wrong-scope, contradicted, or low-quality memories before they enter the LLM context.
Use Python 3.10+.
python -m pip install memory-correctnessOptional integrations:
python -m pip install "memory-correctness[mem0,openai,postgres]"
python -m pip install "memory-correctness[all]"from memory_correctness import MemoryCorrectnessCompiler
from memory_correctness.sidecar.sqlite import SQLiteSidecar
from memory_correctness.stores.dict_store import DictStore
memories = [
{
"id": "old",
"text": "User prefers detailed explanations.",
"score": 0.91,
"metadata": {
"subject": "user.answer_style",
"predicate": "prefers",
"object": "detailed",
"source": "explicit_user_statement",
"scope": {"user_id": "u1"},
},
},
{
"id": "new",
"text": "User now prefers short technical answers.",
"score": 0.86,
"metadata": {
"subject": "user.answer_style",
"predicate": "prefers",
"object": "short",
"source": "explicit_user_correction",
"scope": {"user_id": "u1"},
},
},
]
compiler = MemoryCorrectnessCompiler(
store=DictStore(memories),
sidecar=SQLiteSidecar(":memory:"),
)
result = compiler.compile(
user_id="u1",
message="Explain the architecture.",
context={"domain": "tech", "token_budget": 700},
)
print(result.memory_context) # text to pass to the LLM
print(result.suppressed) # memories removed, with reasonsUse any store implementing MemoryStore. Built-in adapters include DictStore,
Mem0, Zep, Supermemory, Qdrant, ChromaDB, Weaviate, Pinecone, and pgvector.
from mem0 import MemoryClient
from memory_correctness import MemoryCorrectnessCompiler
from memory_correctness.stores.mem0 import Mem0Store
client = MemoryClient(api_key="...")
compiler = MemoryCorrectnessCompiler(store=Mem0Store(client=client))Smoke-test third-party adapters against the exact SDK/API version you deploy.
Best results need subject, predicate, object, source, and scope on
each memory. Add them yourself, use compiler.add_memory(), or use an extractor
such as OpenAIExtractor during writes/backfills.
python -m pip install -e ".[dev]"
pytestMore details live in docs/.
MIT