Four layers
- Working memory
- Session memory
- Long-term memory
- Knowledge graph
An agent’s live scratch pad during one invocation — tool results across
reasoning-loop iterations, intermediate outputs, self-correction
history. Lives entirely in the worker process heap; never queried by
anything else. A 50MB soft cap triggers truncation of the oldest tool
results before the next LLM turn, rather than an OOM.
Vector search (pgvector)
Embeddings live in PostgreSQL viapgvector, indexed with HNSW
(hierarchical navigable small world) for approximate nearest-neighbor
search — no separate vector database to operate. ADR-002
documents a real correctness fix here: the HNSW index must not be wrapped
in a subquery, and the embedding model version must be filtered at query
time, not assumed constant.
Hybrid retrieval
Three search modalities combine via Reciprocal Rank Fusion:- Vector search — semantic similarity via pgvector
- Keyword search — BM25-style full-text search (PostgreSQL’s native FTS)
- Graph search — relationship traversal through the knowledge graph
Embedding providers
Memory writes never hard-depend on one vendor.EmbeddingProvider is a
protocol (mirroring LLMProvider) with OpenAI, vLLM, and Ollama
implementations — selected via Settings.embedding_provider (default
openai, so existing deployments are unaffected). An Anthropic-only or
air-gapped deployment can run memory entirely on a local embedding model.
PII and confidence
The memory service scrubs PII before persistence and attaches aconfidence_score to long-term and graph writes, so retrieval can weight
or filter on how trustworthy a stored fact actually is — a keyword
decision made from a single data point is not treated the same as one
backed by 90 days of GSC data.