What is a context graph?
Context graphs · 6 min read
A context graph is the working memory of an AI system, stored as a graph: the entities it's dealing with, the facts it has learned about them, where each fact came from, and when. Where a knowledge graph is a curated library, a context graph is operational — agents write to it as they work and read from it by traversing, so the context an LLM receives is retrieved, not re-sent.
A context graph, defined
Take everything an agent or AI application currently knows — the user it's helping, the systems it touched, the decisions made so far, the documents it consulted — and store each of those as a node, with typed relationships between them: (:Fact)-[:ABOUT]->(:Entity), (:Fact)-[:SOURCED_FROM]->(:Document), (:Decision)-[:SUPERSEDES]->(:Decision).
That structure is the context graph. It's not the model's training data and it's not a prompt template; it's a live database of the situation, small enough to traverse in milliseconds and precise enough to cite.
How it differs from a knowledge graph
The two are often conflated because both store entities and relationships. The difference is posture. A knowledge graph is an organisational asset: curated, reviewed, slowly changing, meant to be true for everyone. A context graph is an operational record: written continuously by agents mid-task, scoped to a user, session or fleet, stamped with sources and timestamps, and allowed to contain observations that are later superseded.
You can build one from the other — promote hardened facts from context graphs into the knowledge graph, or seed a context graph with a slice of org knowledge — but they answer different questions: "what does the organisation know?" versus "what does this agent know right now, and how does it know it?"
What goes in one
The schema that keeps working across teams is small: Entity nodes for the things that matter (people, services, accounts, tickets), Fact nodes carrying a statement with an observed_at timestamp, ABOUT edges from facts to entities, and SOURCED_FROM edges from facts to where they were learned — a document, a conversation, an API response.
You don't design the full ontology up front. Relationship types accrete as the agent's questions demand them, which is exactly the property-graph model's strength: adding DEPENDS_ON next month doesn't invalidate what's already stored.
How agents read and write it
Writes happen as the agent observes: extract entities and facts from what just occurred and MERGE them, so re-observing the same fact is idempotent rather than duplicating. Reads are traversals: start from the entities in the current query and walk their neighbourhood — facts, sources, related entities — rather than replaying history.
That's what keeps the token budget flat. Dumping a 2,000-entity knowledge base into an LLM's context costs about 202,285 tokens per query; traversing to the relevant subgraph costs about 2,668. The retrieved neighbourhood stays roughly constant as the graph grows, because the query bounds the walk, not the corpus.
MATCH (e:Entity)<-[:ABOUT]-(f:Fact)-[:SOURCED_FROM]->(src)
WHERE e.name IN $entities
RETURN e.name, f.statement, src.title, f.observed_at
ORDER BY f.observed_at DESC
LIMIT 50Provenance is the point
Every fact in a context graph arrives with its lineage: which source produced it, when it was observed, what superseded it. When an agent answers, the traversal it ran is the citation trail — you can inspect exactly which nodes produced the answer. For anything customer-facing, regulated, or simply debuggable, that auditability is the difference between "the model said so" and "here's why."
Running a context graph on CognoDB
CognoDB is built to be this layer. Instances provision in seconds and bill for what you use, so a graph per agent, per session or per tenant is an architectural choice rather than a cost decision — isolation by database, not by WHERE clause. Agents connect two ways: any Bolt driver with Cypher, or the built-in MCP server, which lets Claude, Cursor and other MCP clients read the schema and traverse directly. Full-text BM25 search inside the database covers the "find the entry point by keyword" step without a separate service.
At a glance
Knowledge graph vs context graph
| Knowledge graph | Context graph | |
|---|---|---|
| Purpose | Curated organisational knowledge | Working memory for AI systems |
| Written by | Pipelines and curators | Agents, continuously, mid-task |
| Rate of change | Slow, reviewed | Every observation |
| Scope | Whole organisation | A user, session, agent or fleet |
| Truth model | Meant to be canonical | Time-stamped, supersedable |
| Core query | What do we know? | What does this agent know right now? |
Questions
Common questions.
Is a context graph the same as a knowledge graph?
No. They share the graph data model, but a knowledge graph is curated, org-wide and slowly changing, while a context graph is operational: written continuously by agents, scoped to a session or fleet, and stamped with provenance and time. One is a library; the other is working memory.
Why use a graph instead of stuffing context into the prompt?
Prompt-stuffing costs grow with the size of your knowledge base — every query pays for everything. Graph retrieval walks only the neighbourhood relevant to the current question, so the token cost stays bounded as the graph grows, and every retrieved fact carries its source.
Do I need a separate context graph per agent?
It's the cleanest pattern when agents must not see each other's context: one CognoDB instance per agent, session or tenant gives real database isolation with its own credentials. For collaborating agents, a shared graph works as a blackboard they all read and write.
How does an LLM actually query the context graph?
Two ways. Your application can run Cypher over Bolt and place the results in the prompt, or the agent can query the graph itself through CognoDB's MCP server — reading the schema and writing its own traversals, with the query trace doubling as the citation.
What schema should a context graph start with?
Entities, facts with timestamps, ABOUT edges from facts to entities, and SOURCED_FROM edges to sources. That minimal shape answers most recall questions, and property graphs let you add relationship types later without migrating what exists.
Keep reading
Context graphs
AI agent memory
Persistent memory for AI agents, built as a graph: why transcripts don't scale, the entity–fact–source schema that does, the write and read paths in Cypher, and how multi-agent memory stays sane.
ReadContext graphs
Cut LLM token costs
Context-stuffing costs grow with your knowledge base; graph retrieval stays bounded by the neighbourhood you traverse. The measured numbers: 202,285 tokens per query down to 2,668, at 2,000 entities.
ReadGraphRAG
What is GraphRAG?
GraphRAG grounds an LLM by traversing a context graph instead of retrieving text chunks by similarity alone. Here's how it works, why it improves multi-hop answers, and how to build it.
ReadStart now
~98.7%
token efficiency at 2,000 entities (see the footnotes above)
Try the ideas on a real graph.
A free instance takes about a minute and no card. Every Cypher snippet on this page runs against it unchanged.
First-graph path
LiveCreate a free instance
No card. Ready in about a minute.
Connect your driver
bolt+s:// URI into the driver you already use.
Write two MERGEs
That's the entire shape of agent memory.
Point an agent at it
One MCP config block. No integration code.