Semantic / Vector / Graph Memory

What the agent knows, indexed for retrieval.

Long-term knowledge is stored structurally, as embeddings, or as entities and relations, independently of single conversations. Match the store to the access pattern and start simple: vector DBs for similarity recall, key-value (Redis) for fast exact lookup, relational for structured/auditable querying, and graph DBs only once vector-plus-relational becomes the bottleneck.

In practiceA support assistant stores the fact that a customer is on the Enterprise plan, and recalls it in a conversation weeks later without the user repeating it.

Level
04 · Production
Subdomain
Memory Architecture
Also known as
Knowledge Memory, Vector Store Memory, Knowledge Graph Memory, Knowledge Retrieval, RAG
Trade-off
Reusable, highly structured knowledge is achieved against significant updating, modeling, and ranking challenges.
Native in
LangGraph, OpenAI Vector Stores, Microsoft Agent Framework, Google ADK, Cognee
The mechanism

How it works.

Knowledge is written once, outside any conversation, and read whenever a question needs it. The model stays as it is; to change what the agent knows, you change the store.

1 · Write, when knowledge arrives

  1. SourceA document, a fact, a preference
  2. Split into passagesSmall enough to be retrieved alone
  3. Embed and indexOne vector per passage

2 · Read, when a question comes

  1. QuestionEmbedded with the same encoder
  2. Nearest passagesThe top k by inner product
  3. Into the promptPassages first, then the question
  4. Grounded answerThe model answers from the passages
Vector store
Finds passages by similarity of meaning. The default for recall.
Key-value or relational store
Finds an exact record: a profile, a plan, a timestamp. Use it when the lookup key is known.
Graph store
Follows relations between entities over several hops. Worth its cost only when similarity search stops answering the questions.
Walk it through

A real run, step by step.

TaskA support assistant is asked: “Can Acme use single sign-on?” The store holds four passages; the two nearest go into the prompt.
Illustrative similarity values, k = 2.
Stored passageWrittenSimilarityLoaded
Single sign-on is included from the Enterprise planProduct documentation0.88Yes
Acme is on the Enterprise planA conversation six weeks ago0.82Yes
Setting up single sign-on takes about one hourProduct documentation0.74No
Acme's billing contact has changedA conversation last week0.41No
What this shows: neither passage answers the question alone; the model joins them. That works here because both passages resemble the question. Ask “Which customers can use single sign-on?” and similarity returns passages about single sign-on, not the list of Enterprise customers. That is a question about a relation, and the case for a relational or graph store.
In code

The pattern in code.

Plain Pythonpython
def remember(text):
    for chunk in split(text, words=100):
        index.add(embed(chunk), chunk)

def recall(question, k=5):
    return index.search(embed(question), k)  # maximum inner product search

def answer(question):
    passages = recall(question)
    return model(f"Use only these passages:\n{passages}\n\nQuestion: {question}")
Fit

Use it, or not.

When to reach for it

  • The agent must utilize domain-specific knowledge long-term.
  • Facts and preferences are reused.
  • Relationships between entities are crucial.

When it backfires

  • Knowledge updates too rapidly.
  • Governance for storage content is lacking.
  • Simple prompt context is sufficient.
Pitfalls

Two ways this pattern will hurt you.

Retrieval returns relevant-looking but stale facts

Embeddings score by surface similarity. A high-similarity match can be a year-old answer to a question whose ground truth has since changed.

Countermeasure

Include a freshness signal in ranking and reject documents past a recency cutoff. Re-embed when the source updates, not on a schedule.

Duplicate and contradictory facts accumulate

Each write appends. The store ends up holding both 'the customer is on Free' and 'the customer is on Enterprise', and retrieval may surface either, so the agent contradicts itself between sessions.

Countermeasure

Upsert facts by a stable entity key rather than appending, and resolve conflicts on write (latest-wins or explicit reconciliation) instead of at read time.

Threat exposure

What this pattern exposes

Adopting this pattern opens these attack surfaces. Each links to its entry in the threat model.

Full threat model →

EU law

Regulation

Duties from EU law that this pattern helps meet, or that land on it. A reading aid, not legal advice.

  • GDPR Art. 15A person can obtain confirmation that their data is processed, access to it, and the recipients it was disclosed to.Controllers · since 25 May 2018
  • GDPR Art. 17Personal data is erased without undue delay when a ground for erasure applies.Controllers · since 25 May 2018

An engineer's reading aid, not legal advice. The legal texts and their interpretation are authoritative.

Framework support

Where Semantic / Vector / Graph Memory is native.

LangGraphvector store + retrieverNative
OpenAI Vector StoresServicemanaged vector storesNative
Microsoft Agent Frameworkknowledge storeNative
Google ADKmemory bank / RAGNative
CogneeLibraryOpen-source knowledge-graph memory built from unstructured data.Native

Search

Search patterns, frameworks, and pages.