docs(adr): 0003 — Memory contract (v1)#271
Merged
EmersonBraun merged 2 commits intomainfrom Apr 15, 2026
Merged
Conversation
Formalizes Memory as two independent contracts: ChatMemory (6 invariants, CM1-CM6): - load() is a snapshot, no streaming - save() is replace-all, not append - ordering preserved, atomic from consumer view - empty memory returns [], clear is opt-in VectorMemory (8 invariants, VM1-VM8): - store is upsert by id (no duplicate errors) - dimensionality is a constructor concern, not contract - search returns descending-scored, threshold exclusive - topK is upper bound, no padding - metadata opaque, JSON-serializable docs - delete is opt-in (compliance scenarios) EmbedFn (3 invariants, E1-E3): - stable output per input+model - no side effects beyond caching - error-as-rejection Splitting ChatMemory and VectorMemory rather than unifying (as LangChain does) matches real backends: Redis is a great chat store, mediocre vector store; pgvector is the opposite. Forcing one interface produces implementations that half-fulfill both sides. Unblocks 8 new memory backends in Fase 3 (#178) and stable RAG (#175). Memory graph (#180) will be a third contract, not a replacement. Refs #214
This was referenced Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third ADR of Phase 0 — formalizes Memory as two independent contracts (ChatMemory + VectorMemory) plus a standalone
EmbedFnprimitive.Builds on ADR 0001 (Adapter) and ADR 0002 (Tool).
What's included
docs/architecture/adrs/0003-memory-contract.md— 17 invariants total (6 chat + 8 vector + 3 embed), stability tierstable, rationale, trade-offs.Key decision: split, don't unify
LangChain's unified
Memoryinterface produces implementations that half-fulfill both chat and vector concerns. Real backends are asymmetric — Redis great for chat, mediocre for vectors; pgvector the opposite. We split them so a backend implements only what it does well.Highlight invariants
ChatMemory
VectorMemory
EmbedFn
Trade-offs accepted
Unlocks
load → savefor chat,search(topK=large) → storefor vectorsTest plan
Refs #214 #211