Agent memory on Postgres: a table, not a new service
Agent memory is stored information that an agent can look up later, and a Postgres table can hold it. Each fact is a row, each source or link is a foreign key or an edge, and the agent finds facts by meaning and then follows the links. Mem0, Zep and Letta add things a table does not, such as automatic extraction and hosted APIs, and they are the better choice when you want those.
Checked against current documentation on 16 November 2026.
What agent memory actually is
A model forgets everything between conversations. Agent memory is whatever you store so the next conversation can pick up where the last one stopped. It might be a user's preferred tone, the decision a team made on Tuesday, or the fix that worked last time.
Strip away the branding and you need four things. A place to write a fact. A way to say where the fact came from. A way to connect it to other facts. A way to find it again from a vague question. Databases have done the first three for decades. The fourth is new: finding by meaning, not by exact words.
That fourth part is what vector search gives you. If you want the mechanics, semantic search on Postgres with pgvector covers it. This guide is about what you build on top.
Memory as rows and foreign keys
Here is a plain design. One table holds the facts. A second holds the sources, such as a chat message, a document or a support ticket. A foreign key from fact to source says where it came from. A link table joins facts to other facts, with a label such as "replaces" or "contradicts".
CREATE TABLE sources ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), kind text NOT NULL, -- 'chat', 'document', 'ticket' uri text, created_at timestamptz NOT NULL DEFAULT now() ); CREATE TABLE facts ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), user_id text NOT NULL, source_id uuid REFERENCES sources (id), body text NOT NULL, valid_to timestamptz, -- set when a fact stops being true created_at timestamptz NOT NULL DEFAULT now() ); CREATE TABLE fact_links ( from_fact uuid NOT NULL REFERENCES facts (id) ON DELETE CASCADE, to_fact uuid NOT NULL REFERENCES facts (id) ON DELETE CASCADE, label text NOT NULL, -- 'replaces', 'mentions', 'contradicts' PRIMARY KEY (from_fact, to_fact, label) ); CREATE INDEX facts_user_idx ON facts (user_id); CREATE INDEX fact_links_to_idx ON fact_links (to_fact);
This gives you things that agent memory services often make hard. You can delete everything about one user with one statement. You can see why the agent believes something, by following source_id. You can back it up with the rest of your data, and restore it. And your existing permissions apply, since it is just another table.
Retrieval is two steps. First, search by meaning to find the few most relevant facts. Then traverse from them along the links, a hop or two, to pull in related facts. The guide to Postgres as a graph database shows how a recursive query does the second step.
What Mem0, Zep and Letta add
A table is the storage. It is not the whole job. Three well-known projects do more, and they do it differently. Each fact below comes from the project's own documentation, read on 16 November 2026.
| Project | Approach | Hosting | What a plain table does not give you |
|---|---|---|---|
| Mem0 | Sends messages through an LLM that pulls out facts, decisions and preferences to remember. Its add step is additive and does not overwrite existing memories. | Hosted Platform, or open source as a library or Docker stack. The self-hosted server defaults to Postgres with pgvector. | Automatic extraction from raw conversation |
| Zep | Organises context in temporal context graphs. Graphiti, its open-source framework, builds entities and edges as it ingests data and records when facts change. | Zep runs its own graph database service, called Konig. Graphiti runs on Neo4j, FalkorDB or Amazon Neptune. | Extraction, plus a time-aware graph that invalidates contradicted facts |
| Letta | Agents keep memory in blocks that sit in the system prompt and that the agent edits through memory tools. | Letta Cloud, or run the app server yourself. | An agent runtime where the agent manages its own memory |
Read the first row again. Mem0's self-hosted server uses Postgres and pgvector by default, so even the tool built around memory often stores it in the same place a table would. What Mem0 adds is the extraction step and a ready-made API. See the Mem0 add documentation and its open source overview.
Zep's difference is time. Its Graphiti documentation says graph edges carry temporal metadata, and that contradicting facts are handled by invalidating edges. If a user moves city, the old fact is marked as no longer current rather than deleted. See Zep's overview and Graphiti.
Letta is a different kind of thing. It is a platform for building stateful agents, and memory is one part of it. Its documentation says memory blocks are pinned to the system prompt, and that an agent can change its own memories through tools. See Letta's memory guide.
When each is the better choice
- Pick Mem0 if you want facts pulled out of raw conversations for you, and you would rather call an API than write the extraction prompt, the dedupe logic and the schema yourself.
- Pick Zep if how facts change over time is central, such as a customer's circumstances or a project's status, and you want a temporal graph maintained for you.
- Pick Letta if you want a full agent runtime in which the agent edits its own memory, and you are happy to build around that platform.
- Pick a table in your own Postgres if your facts already have a natural home in your data model, you need tight control over who can see what, you want deletion and audit to be simple, or you do not want another vendor holding your users' information.
You can also mix them. A table can be the store of record while an extraction step, which you write or buy, decides what to put in it. The table does not care whether a person, a script or a model wrote the row.
The cost of the table route is real. You write the extraction prompt. You decide when two facts are duplicates. You decide what happens when a fact changes. None of that is hard, but none of it is free. If your agents mostly need to recall a handful of facts per user, a table is plenty. If you need sophisticated consolidation across millions of conversations, one of the services will save you work.
Design choices that matter more than the tool
Whatever you store memory in, a few decisions decide whether it helps or hurts. Make them on purpose.
- Scope every memory. Each row should belong to a user, a team or a project, and every search should filter by that scope. Memory that leaks from one customer to another is a worse bug than memory that forgets.
- Store short, self-contained facts. "Prefers email to calls" is easy to find and easy to check. A pasted chat transcript is neither.
- Keep the source. When an agent acts on a memory, you want to be able to ask where it came from. A foreign key or a link back to the original is enough.
- Plan for change. People move, plans shift and facts expire. Decide whether you mark an old fact as no longer valid, delete it, or link the new one to it. Zep's design shows the value of keeping the history.
- Plan for deletion. Someone will ask you to forget them. With rows scoped to a user, that is one delete statement. Check that any copies, such as backups or logs, are covered by your policy too.
None of this depends on a vendor. It is data modelling, and a database is good at it.
Helm7 and the memory.items template
Helm7 offers the table route as a template. It does not extract facts for you. Your app or agent writes the rows, and Helm7 makes them searchable and linkable.
Calling database_semantic_enable with template set to agent_memory creates memory.items in your own database. The columns are id, scope_id, kind, title, body, tags, valid_to, created_at and updated_at. It makes title and body searchable by meaning and by words, and it turns relationships on. The scope_id column is how you keep one user's, team's or product's memory apart from another's.
// Preview first. Nothing is created.
database_semantic_enable
{ "productId": "prd_...", "databaseId": "DATABASE_ID",
"template": "agent_memory", "dry_run": true }-- Your app writes a memory with plain SQL. Helm7 notices the new row
-- and embeds it within about a minute.
INSERT INTO memory.items (scope_id, kind, title, body, tags)
VALUES ('customer-42', 'preference', 'Prefers email to calls',
'Asked on 3 March to be contacted by email only, never by phone.',
ARRAY['contact', 'preference']);To recall, one database_search call finds items by meaning within a scope, then follows links outward. The where field limits it to one scope. The traverse field takes the top few hits as seeds and brings back their neighbours, with each hop scored lower than the last.
database_search
{ "productId": "prd_...", "databaseId": "DATABASE_ID",
"table": "memory.items",
"query": "how does this customer like to be contacted?",
"where": { "scope_id": "customer-42" },
"k": 5,
"traverse": { "seeds": 3, "max_depth": 2 },
"explain": true }database_edge_upsert
{ "productId": "prd_...", "databaseId": "DATABASE_ID",
"from": { "table": "memory.items", "pk": "NEW_ITEM_ID" },
"to": { "table": "memory.items", "pk": "OLD_ITEM_ID" },
"label": "replaces" }Optionally, database_graph_infer can suggest links by comparing rows and asking a model to judge pairs. Suggestions are stored as proposed and ignored until you approve them.
Everything lives in your Postgres, in a schema Helm7's own role owns and your app role can read but not alter. Backups and restores include it. Retrieval runs as your app's role, so row level security applies. Since it is only a table, you can read it with any SQL tool, export it, or move it to another host. The databases page lists the other switches, and Helm7 for agents explains how agents use the platform.
Common questions
What is agent memory?
Information stored so an AI agent can use it in later conversations: facts about a user, decisions, past results. It needs somewhere to write, a way to say where a fact came from, links between facts, and a way to find them by meaning.
Do I need a vector database for agent memory?
No. Postgres with pgvector can store the vectors next to the rows, and you can filter by user in the same query. A separate vector database is worth it only when you outgrow what one Postgres handles.
Is a table a good Mem0 alternative?
For storage and retrieval, yes. You also write the extraction, deduplication and update logic that Mem0 provides. If you want extraction done for you, Mem0 is the better choice. Its self-hosted server uses Postgres with pgvector by default anyway.
How is Zep different from a Postgres table?
Zep builds a temporal graph of entities and relationships from your data, and invalidates facts when newer ones contradict them. In a table you would model that yourself, for example with a valid_to column and a replaces link.
Does Helm7 extract memories automatically?
No. Your app or agent writes the rows. Helm7 makes them searchable by meaning and by words, lets you link them, and can suggest links that you approve.