SokkoSokko
← Back to blog

Vector Database for AI Agent Memory: Do You Need One?

Sokko Team8 min read

What people mean by a vector database for AI agent memory

There is a reflex in agent projects: the moment memory comes up, someone reaches for a vector database. Pinecone, Weaviate, Qdrant, or pgvector go into the stack before anyone has asked what the agent actually needs to remember. Often that is premature. A vector database for AI agent memory solves one specific problem, semantic retrieval over a large pile of unstructured text, and if that is not your problem, you are adding a moving part you do not need.

This post separates two ideas that get merged into the word "memory": state the agent must keep, and knowledge the agent might look up. They call for different tools. Getting the split right saves you money, latency, and a database you have to operate.

Memory vs retrieval: they are not the same thing

Here is the distinction that resolves most of the confusion.

Agent state (memory)Knowledge retrieval
Question it answers"What was I doing?""What do I know about X?"
DataTask progress, decisions, user factsDocuments, past conversations, a corpus
SizeSmall, structuredLarge, unstructured
Access patternRead/write by keySearch by meaning
Right toolA plain database or key-value storeA vector database, sometimes
Loss on restartBreaks the agentDegrades quality

State is what the agent needs to not lose its place: the current task, what it already tried, the user's name and preferences. It is small and structured. You store it by key in Postgres, SQLite, or Redis and read it back exactly. A vector database is the wrong tool for this, because you are not searching by meaning, you are looking up a known record.

Retrieval is different. When the agent needs to answer from a large body of text it cannot fit in the prompt, thousands of docs, a year of past chats, a knowledge base, then searching by meaning is exactly what a vector database does well. That is the real job for a vector database for AI agent memory.

When you do NOT need a vector database

Skip it, and save yourself an extra service, when:

  • Your knowledge fits in the context window. If everything the agent needs to know is a few thousand tokens, put it in the prompt. No retrieval layer, no database, no embedding step. This is the case people most often overbuild past.

  • You look things up by key, not by meaning. "Get this user's settings" is a primary-key read. A plain database answers it faster and cheaper than any vector search.

  • You have fewer than a few hundred documents. At that size, a keyword search or even a linear scan with embeddings in memory beats standing up a dedicated vector store. pgvector inside a Postgres you already run covers this without a new dependency.

  • The data is structured. Rows, columns, filters, and joins are a relational database's home turf. Do not force structured queries through semantic search.

The honest default for a new agent is: keep state in the database you already have, and only add retrieval when the agent visibly needs knowledge it cannot hold in context.

When you genuinely DO need one

A vector database earns its place when all of these are true:

  • You have a large corpus, tens of thousands of chunks or more, that will not fit in a prompt.

  • The agent needs to find the relevant parts by meaning, not by exact keyword.

  • Queries are open-ended, so you cannot predict which records matter ahead of time.

Classic fits: a support agent searching a big documentation set, a research agent over a large archive, or an agent that recalls relevant snippets from months of past conversations. In those cases semantic search is the feature, and a vector database is the right home for it.

Even then, start with pgvector inside your existing Postgres before reaching for a separate managed vector service. One fewer system to run, and it scales further than most people expect. Graduate to a dedicated store like Qdrant or Pinecone when your vector count and query volume actually outgrow Postgres, not before.

How retrieval-augmented memory works, minimally

The pattern, stripped down, is: embed your documents once, embed the query at runtime, find the nearest chunks, and put them in the prompt.

# One-time: turn documents into vectors and store them
for chunk in split(documents):
    vector = embed(chunk)              # an embedding model call
    db.insert(id=chunk.id, vector=vector, text=chunk.text)

# At query time: find the chunks closest in meaning
def retrieve(question, k=5):
    q = embed(question)
    hits = db.nearest(q, limit=k)      # vector similarity search
    return [h.text for h in hits]

context = retrieve(user_question)
answer = model.respond(user_question, context=context)

The vector database is only the db.nearest step. Everything else, chunking, embedding, and stuffing the results into the prompt, is your code. That is worth saying because the database is the easy part to swap and the least of your design decisions. Chunk size and what you retrieve matter far more than which vector store you pick.

The cost angle nobody mentions

Retrieval is also a cost tool, not only a capability. Every token you send to the model costs money, so an agent that dumps its entire knowledge base into the prompt on every call is both slower and more expensive than one that retrieves the five relevant chunks. Good retrieval means smaller prompts, which means a smaller token bill. We covered how that line dominates spend in AI agent pricing. A vector database, used well, pays for itself by shrinking what you send the model.

Memory that persists is a hosting problem too

Whatever you store memory in, state or vectors, it has to survive the agent restarting. An agent that keeps its memory in a process variable loses everything the moment it crashes or redeploys. Persistence means durable storage: a database and volumes that outlive the process. That is an infrastructure requirement, and it is the same one that what is an AI agent runtime describes for the execution layer. For coding agents in particular, the memory that matters is context about your codebase, which we cover in persistent memory for AI coding agents.

If you are running an agent on Sokko, your Postgres, your pgvector index, or your key-value state is saved automatically and stays put across restarts, with no extra plumbing.

What actually determines retrieval quality

If you do add a vector database for AI agent memory, a warning: the database is rarely why your retrieval is bad. Teams swap Pinecone for Qdrant hoping for better results and get the same mediocre answers, because the quality levers are upstream of the store:

  • Chunk size. Too large and each chunk is diluted with irrelevant text; too small and it loses the context that made it meaningful. This one decision moves retrieval quality more than the choice of database.

  • What you embed. Embedding raw text versus a cleaned, summarized version changes what "similar" means. Garbage in, similar garbage out.

  • How many chunks you retrieve. Return too few and you miss the answer; too many and you bury the model in noise and pay for the extra tokens. Tune this per use case.

  • Re-ranking. A cheap first pass to fetch candidates, then a smarter re-rank of the top results, often beats a single similarity search. The vector store does the first step; your logic does the second.

Spend your effort here, not on comparing vector databases. The store is a commodity. The retrieval design is where the quality lives.

Hybrid: when you need both state and retrieval

Real agents often need both kinds of memory at once, and the clean design keeps them separate rather than forcing everything through one system:

# State: exact lookups in a plain database
state = db.get(f"agent:{agent_id}:task")     # "what was I doing?"

# Retrieval: semantic search only when the agent needs knowledge
if needs_knowledge(user_question):
    context = vector_store.search(user_question, k=5)
else:
    context = None

answer = model.respond(user_question, state=state, context=context)

The mistake is routing state lookups through the vector store because it is "the memory system." State is a keyed read and belongs in a relational or key-value store. Retrieval is a semantic search and belongs in the vector store. Two tools, two jobs. Keeping them distinct is faster, cheaper, and far easier to reason about than a single store pretending to be both.

The decision, in three questions

Before you add a vector database for AI agent memory, ask:

  1. Does the knowledge fit in the context window? If yes, stop. Put it in the prompt.

  2. Do I look things up by key or by meaning? By key means a plain database. By meaning, over a large corpus, means retrieval.

  3. Is my corpus large and open-ended? Only a yes here justifies a dedicated vector store, and even then, try pgvector first.

Most agents need durable state and never need a vector database. A smaller set need retrieval, and for them a vector store is the right tool. The mistake is starting with the heavy option. Build the state layer first, watch what the agent actually reaches for, and add semantic retrieval when a real query pattern demands it, not because the architecture diagram looked incomplete without it.