Memory, Conversations, and Context Engineering
AI memory is governed data selected for a future task, not everything ever said. Short-term conversation state, durable user preferences, semantic facts, episodic events, and procedural instructions have different authority and retention. A reliable backend records provenance, consent, confidence, scope, expiry, and deletion while keeping system policy separate from remembered content.
What will you be able to do?
- classify memory by purpose and authority;
- assemble context within token, privacy, and relevance budgets;
- validate summaries and prevent cross-tenant contamination;
- support correction, retention, and deletion.
What memory types are useful?
Do not infer sensitive attributes or persist speculative model conclusions as facts. A model summary is a derived artifact, not the original record.
How should context be assembled?
- Authenticate and authorize the current task.
- Start with immutable system and organization policy.
- Add the current request.
- Retrieve only memories whose tenant, user, purpose, access, and retention match.
- Rank by relevance, freshness, authority, and diversity.
- Fit within a token budget while preserving source identifiers.
- Delimit all memory as untrusted context unless it is explicitly versioned policy.
- Record which memory versions were used.
Recent conversation can be summarized when long, but preserve critical user commitments and source links. Run invariants after summarization, compare against a small factual checklist, and let users view or correct durable memories.
Where should memory live?
PostgreSQL owns durable memory metadata, source links, consent, and deletion. A vector index may support semantic recall under access filters. Redis may hold short-lived conversation assembly or stream state with TTL, but it must not be the only place for user-approved durable preferences.
Why does this matter in AI-native systems?
More context can reduce quality by adding conflict, stale facts, and injection. Context engineering is selective data architecture. Every stored memory increases privacy, security, and deletion obligations; collect less and expire aggressively.
Common mistakes
- Entire chat history is always appended until limits fail.
- Model-generated memory is stored without user consent or provenance.
- Summary overwrites source history and cannot be audited.
- User preference leaks across organizations or purposes.
- Deleting a conversation leaves summaries and embeddings.
- Procedural policy is retrieved like ordinary similarity text.
AI Pair-Programmer Prompt
Exercise
Design conversation memory for a user who supports two organizations with different policies. Include a corrected preference and a deleted conversation.
Acceptance criteria: no organization policy or memory crosses contexts, correction wins with traceable history, deletion reaches every derivative, and context assembly stays within a measured token budget.
Knowledge check
- Is a model-generated summary authoritative fact?
- Why scope memory by purpose?
- Can Redis be the only store for approved durable preferences?
Answers
- No; it is a derived artifact requiring provenance and validation.
- Data appropriate for one task may be irrelevant or unauthorized for another.
- No; durable consented memory and lineage belong in the system of record.
Completion checklist
Primary references