SQL AI memory vs vector database
SQL-backed AI memory vs. vector-only memory
Why embeddings improve recall but do not replace structure, constraints, provenance, or exact queries.
Vector memory retrieves semantically similar text. SQL-backed memory can also represent identity, scope, status, time, provenance, and relationships under enforceable constraints. The strongest design often combines them: relational data for truth and governance, embeddings for fuzzy recall, and a graph layer where explicit connections matter.
What vector search does well
Embeddings map text into a space where similar meanings are near each other. This helps an agent retrieve “production location” when the stored phrase says “deployment region.”
Vector search is useful for:
- paraphrased questions;
- unstructured notes and conversations;
- broad thematic recall;
- ranking many possible passages;
- retrieving across vocabulary differences.
It is a powerful access path. It is not a complete data model.
What vector-only storage leaves implicit
A vector and a metadata object can carry many fields, but the application must still define and enforce their relationships.
Questions that become awkward in a vector-only design include:
- Which workspace is allowed to read this memory?
- Which fact superseded another?
- Which source supports this sentence?
- Which pages cite a deleted or archived observation?
- Who may invite a member or move shared memory?
- What changed between two dates?
- Which exact identifier or error code matches?
Similarity does not answer these questions. Structure does.
What SQL contributes
Constraints
Foreign keys, unique indexes, checks, and triggers keep invalid states from entering the store.
Access control
Row-level security can scope every query to workspace membership. Grants can prevent an agent from deleting or changing schema even if a prompt asks it to.
Exact retrieval
Names, IDs, dates, statuses, and counts remain first-class queryable values.
Provenance
Typed links can connect a consolidated claim to a source entry and exact quote.
Portability
The schema and content can leave as a standard database dump rather than an application-specific vector index.
Why relational does not mean rigid
Agent memory contains irregular material. A relational core can still use JSON for loose source metadata, full-text indexes for language, vector columns for embeddings, and polymorphic links for graphs.
The goal is not to normalize every sentence. It is to make the boundaries that matter explicit.
The hybrid approach
OceanDB stores entries, pages, projects, tags, insights, and typed links in Postgres. Full-text search handles exact language. Gemini embeddings provide semantic similarity. A reciprocal-rank-fusion query combines lexical and vector candidates.
The Dreamer maintains the semantic layer in ordinary rows. Embeddings can be regenerated without losing the memory because they are an index over the text, not the only representation of it.
A query the agent can inspect
SQL remains available through OceanDB’s restricted execute_sql tool:
select title, content, created_at
from entries
where entry_type = 'decision'
and content ilike '%deployment%'
order by created_at desc
limit 10;
For a paraphrased question, the agent can use hybrid recall instead. The two paths serve different information needs without hiding either behind one opaque ranking call.
When vector-only memory is enough
A vector-first system can be the right choice when:
- the corpus is low-risk and mostly unstructured;
- approximate recall matters more than relational questions;
- tenancy and revision are handled elsewhere;
- the memory is disposable or easy to rebuild;
- simplicity matters more than a complete audit trail.
Do not add a graph or relational workflow merely because the architecture sounds more advanced.
When structure becomes necessary
Add explicit structure when memory affects permissions, money, commitments, shared work, or long-lived decisions. Add provenance when a person may need to challenge the answer. Add history when the truth changes. Add SQL when exact questions and operational control are part of the product.
Embeddings help memory find. Structure helps memory remain trustworthy.