Graph Database Schema for AI Memory Across Sessions

Session memory breaks when an agent stores facts without their relationships. A graph database schema for AI memory preserves context by linking timestamped event nodes to entities, so later sessions can retrieve what happened and who or what it involved. MERGE operations prevent duplicate nodes while allowing memories to be updated incrementally.
Vector stores are useful for finding semantically similar content, but similarity alone does not capture how people, events, and facts connect. A graph adds that structure, letting an agent follow relationships instead of rebuilding context from disconnected text.
This guide explains how to model persistent agent memory, combine graph retrieval with an existing vector store, and shape a schema for natural-language queries. Learn how entity and event nodes, relationship properties, and traversal depth affect retrieval, and where a self-hosted memory layer fits in the architecture.
Key Takeaways
- Compare graph databases by write latency, traversal behavior, and how they handle concurrent agent workloads, not by storage features alone.
- Keep real-time agent traversals focused: limiting graph searches to 3-4 hops helps control retrieval scope.
- Combine vector search for semantically similar content with graph traversal to recover connected facts and context.
- Translate natural-language questions into explicit entities, relationships, and filters so memory queries return traceable results.
- Choose a schema that supports incremental updates and clear retrieval provenance, then align it with your existing memory infrastructure.
Which open-source graph databases work best with AI agents?
Choose an open-source graph database by testing query latency, traversal limits, and concurrent writes against your agent workload. To design and implement an AI memory graph schema, define entities and relationships, set retrieval boundaries, index write keys, and test updates under concurrent access.
Traversal Latency and Agent Concurrency
Traversal latency measures how long an agent waits while following graph relationships to retrieve context. Keep real-time agent traversals to 3-4 hops to limit unnecessary expansion and keep results focused. Disk-based graph stores have write latency of 5-20 milliseconds, depending on durability settings. That range is a useful reference, not a substitute for testing the engine, query shape, and write pattern your agents will use.
Concurrency changes the test. Run representative reads and persistent memory writes at the same time, then inspect latency under contention. For example, several agents updating shared entities may compete for the same records. Index node properties used in MERGE operations to prevent full-graph scans during writes. Measure the effects of durability settings and index choices using your actual mix of agent queries.
Schema Introspection for Agents
Schema introspection lets an agent inspect node labels, relationship types, and properties before generating a query. This gives the model a map of valid paths, rather than making it guess whether a fact belongs on a Person node or an INTERACTED_WITH edge. Expose only the schema details needed for the task. A concise schema helps agents create targeted queries and reduces malformed traversal requests.
Document the meaning and types of important properties, including timestamps, confidence, and source identifiers. An agent can use a timestamp to filter older events or a source identifier to trace a retrieved fact. Keep property names stable as the graph evolves. When the schema changes, refresh the description available to agents so query generation reflects the current node and relationship structure.
Scaling Graph Databases for Agents
Scaling means maintaining useful query performance as stored memories, writes, and simultaneous agents grow. Compare engines such as Memgraph against your workload rather than selecting by name alone. Test the same representative graph shape, query patterns, and write volume. A prototype insert took 1.9 milliseconds with 100 records, 2.1 milliseconds with 10,000 records, and 2.5 milliseconds with 1 million records. Those results describe that prototype, not every graph database.
Batching can also change write throughput: a prototype processed 10,000 records per second for batches of 100 on a 100-record dataset, and 9,000 records per second for batches of 100 on a 1,000-record dataset. Treat these figures as workload-specific reference points. For production evaluation, test both batch and single-record writes while agents read, and track queueing, index maintenance, and traversal latency as the graph expands.
Designing and Implementing a Memory Schema
Start with the facts agents must recall, then model the entities and relationships needed to answer those questions. Represent episodic memory as timestamped event nodes linked to entity nodes. Add properties for filtering and provenance, such as event time and source. Use MERGE operations to prevent duplicate nodes while enabling incremental updates. This lets an agent add an event without replacing the entire history.
Next, define traversal boundaries and the properties agents may query. Index node properties used in MERGE operations, then test creation, updates, and retrieval with representative questions. Include linked context only when it supports the task. Validate concurrent reads and writes before expanding the workload. A portable memory format can keep schema and stored context usable across systems, while an MCP-Native Memory Server can expose memory access through MCP.
How do graph database AI agents maintain memory across sessions?
Agents maintain context by storing durable events and linking them to entities. Later queries follow those relationships to recover relevant facts and their origins.
Multi-Hop Reasoning and Retrieval Provenance
Multi-hop reasoning follows connected relationships to answer questions that a single stored fact cannot resolve. Provenance records where each retrieved fact came from, helping an application distinguish a source document from an inference. For example, an agent can connect a project, its owner, and a decision event, then return the event and its source.
Keep the path explicit. Store source identifiers and timestamps on event nodes, and preserve links to the supporting evidence. A reviewer can then trace a response from the final relationship back to its originating document. During traversal, limit the returned neighborhood to relationships relevant to the query. This keeps working context focused without losing the path behind an answer.
Entity-Centric Memory Retrieval
Entity-centric retrieval starts from a known person, project, or concept, then follows its connected memories. Represent episodic memory as timestamped event nodes linked to entity nodes. If a user asks what changed after a design review, the agent can find the review event, follow its project relationship, and retrieve later decisions attached to that project.
Store confidence as an explicit property when memories can be uncertain. The MemoriesDB edge schema defines a confidence range of 0.0 to 1.0 and a strength range of -1.1 to 1.1. These values let queries rank or filter relationships without treating every connection as equally reliable. Entity-centered paths also help agents avoid returning unrelated memories that happen to share broad terms.
For multiple tenants, attach a tenant identifier to relevant entities and events, then scope every query to that tenant. Apply access rules during retrieval as well as writes. For example, a customer-support agent should traverse only records permitted in its application context. Explicit scoping reduces the risk that a valid relationship exposes another tenant’s stored memory.
GraphRAG Relationships
GraphRAG combines retrieved text with graph relationships, letting an agent reason across connected entities instead of relying on isolated passages. A query about a product issue can connect a customer, a support event, and a documented resolution. Returning linked evidence gives the answer a traceable structure that a plain-text match may not provide.
Large GraphRAG corpora can generate millions of entity-extraction calls, so extraction and graph writes need clear boundaries. Resolve entity identity before creating relationships, and use incremental updates to avoid duplicate nodes. Keep retrieved subgraphs relevant to the question, then pass their evidence into the generation step. For a practical reference, explore this graph memory implementation and examine how persistent context can be represented across sessions.
Can I use a graph database alongside my existing vector store?
Yes. Keep vector search for semantic similarity and use graph traversal to recover connected facts. A hybrid retrieval flow combines both sets of results into one grounded context.
Combining Vector and Graph Retrieval
Hybrid retrieval uses a vector index to find relevant records, then a graph to expand their relationships. This pairing helps when a question needs both semantic matching and structured context. For example, vector search can find a meeting note about a launch, while graph traversal connects that note to the product, team, and later decision.
Keep the vector store as the source for similarity ranking and embeddings. Store entities, events, and typed relationships in the graph. Connect both systems with a stable record identifier so a vector hit resolves to its graph node. A temporal filter can then prioritize recent events without treating semantic similarity as proof of chronology.
Define a clear handoff between retrieval stages. First, embed the question and retrieve relevant records. Next, resolve their identifiers in the graph and fetch only relationships that support the question. Finally, combine the matching text with linked facts. This avoids duplicating every document in both stores and gives each system a distinct role: fuzzy matching or relational context.
Cypher Generation and Subgraph Retrieval
Cypher generation turns a natural-language request into a graph query that returns a relevant subgraph. The query determines which connected facts enter the agent’s context. Give the model the graph’s node labels, relationship types, and property names. For a question about a launch decision, it can identify a project node, related event nodes, and their source records.
Constrain generated queries to known labels and relationship patterns. A query should match the vector result’s record identifier, then traverse only relevant links. Return selected properties rather than entire nodes, including source references when available. This makes results easier to interpret and keeps unrelated fields out of the prompt.
Graph-aware retrieval needs a firm traversal boundary. Limit real-time agent traversals to 3-4 hops, then inspect whether each added relationship improves the answer. For example, a project-to-decision-to-document path may provide enough evidence; continuing into every colleague or adjacent project adds noise. Keep temporal conditions explicit when a question asks about the latest decision, and preserve the source record alongside each retrieved fact.
Test the combined flow with queries that require different evidence. A semantic question may need vector results alone, while a relationship question may require graph expansion. Compare returned records, paths, and source references. If the graph returns a connection that does not support the question, tighten the relationship pattern or temporal filter before expanding retrieval.

Querying memory with natural language
A natural-language query pipeline turns a request into graph operations, retrieves matching memories, then ranks evidence for an answer. For example, “What did Maya decide about Project Orion?” requires entities, a decision event, and its supporting record.
From Language to Query
First, an AI agent identifies the request’s intent, entities, and constraints. In the Project Orion example, it extracts Maya, the project, and the decision as key concepts. It also detects whether the user wants the latest decision or a specific event. These details shape the query before it reaches the graph engine.
Next, ground those concepts in the schema. Map Maya to a Person node, Project Orion to a Project node, and the decision to a timestamped Event node. The agent can then generate a Cypher query using known labels and relationships. Schema grounding matters: a model that invents a relationship type may return no results or follow the wrong path.
Keep query generation separate from execution. Validate labels, properties, and permitted relationship patterns before sending the query to the engine. For example, reject a query that requests an undefined property, then regenerate it using the available schema. Bind user-provided names as parameters instead of embedding them in query text. This keeps entity matching separate from query structure.
Execution and Ranking
Graph execution returns candidate memories, not a finished answer. Rank results using criteria tied to the request, such as semantic relevance, event time, and source quality. If Maya made several Project Orion decisions, a latest-decision query should prioritize the newest matching event while retaining its source record for grounding.
Keep ranking signals visible to the application. A result can include its matched entity, relationship path, timestamp, and source identifier. The agent can then explain which event supports its response instead of blending records into an unsupported summary. When records conflict, preserve both and use their dates and provenance to distinguish them.
Real-Time Memory Queries
Real-time querying depends on fresh writes, targeted retrieval, and bounded result sets. If Maya records a new decision during a session, the next query should find the updated event and its project relationship. Use explicit temporal filters for requests such as “What changed today?” and return only the fields needed to answer.
Version the schema description supplied to the agent alongside the query logic. When a relationship changes from DECIDED to APPROVED, update the schema version and query templates together. This prevents an older prompt from generating invalid Cypher against a newer graph. Test representative requests after each change, including “Who approved Project Orion?” and “Which document supports Maya’s decision?”
Graph and vector database architecture for AI memory
A durable AI memory architecture gives graph and vector storage distinct roles. The vector index retrieves semantically similar records; the graph preserves entities, events, and relationships that support recall across sessions.
Start with a canonical identifier shared across both stores. A vector result, for example, can carry a document ID that resolves to its graph event and related entities. Keep the original text or chunk in the document store, embeddings and metadata in the vector index, and typed connections in the graph. This avoids treating duplicated copies as independent sources of truth.
Model episodic memory as timestamped event nodes linked to entity nodes. A graph can represent a user’s decision as an event, then connect it to a project and the source document. Store timestamps and source identifiers with the event so retrieval can distinguish an old decision from a later change. Keep relationship types explicit, such as DECIDED or MENTIONS.
Writes need a consistent path through the architecture. First, normalize the incoming memory and assign stable identifiers. Next, create or update graph entities and relationships with MERGE operations, which prevent duplicate nodes while enabling incremental updates. Then write or refresh the corresponding vector record using the same identifier. If a write fails, track the pending update so the two stores can be reconciled.
Read paths should match the question. A semantic search for a remembered explanation can begin in the vector index; a question about who made a decision can begin with an entity or event in the graph. The application can combine matching text with a bounded subgraph and return source references. For a query about a changed preference, use timestamps to order events rather than relying on vector similarity alone.
Enterprise infrastructure also needs clear boundaries for tenants, access, and retention. Include tenant scope in graph queries and vector filters, and apply the same authorization decision to both retrieval paths. When a memory is updated or removed, propagate the change across its graph record, vector entry, and source document. A portable format for identifiers, timestamps, and relationship types makes migration less dependent on a single database engine.
The design principle is simple: keep semantic matching and relationship reasoning separate, then join them through stable records. This gives each store a precise role while preserving a coherent memory trail for the agent.
NovaCortex: NovaCortex Self-Hosted Edition
NovaCortex Self-Hosted Edition provides a self-hosted memory layer for agents that need persistent, graph-native context on their own infrastructure. Use it when you want memory storage under your control, rather than an architecture built around disconnected retrieval components.
Portable Memory Format (PMF) supports portable memory without vendor lock-in, while the MCP-Native Memory Server connects memory access through MCP. Knowledge Buckets organize stored knowledge into distinct groupings. Together, these offerings align with the architecture described here: persistent context, structured relationships, and retrieval across sessions. NovaCortex reduces token usage by up to 98% compared with dumping entire knowledge bases.
To explore whether this memory approach fits your architecture, contact NovaCortex or visit novacortex.dev.
Build the Memory Layer Your Agents Need
The next step is to turn your architecture into a clear memory contract. Decide which facts must persist, how agents should trace them, and which infrastructure controls matter. Then test those choices against real queries, including updates, conflicting records, and access boundaries. A graph database schema for AI memory works best when it reflects the questions your agents need to answer, not just the shape of the available data.
For teams building that layer, NovaCortex Self-Hosted Edition provides a self-hosted memory option. Portable Memory Format (PMF) supports portability, while the MCP-Native Memory Server provides an MCP-native path for memory access. Choose the components that fit your existing architecture and data ownership requirements.
Start with one agent workflow and make its memory traceable, portable, and useful across sessions. That is a solid foundation for what comes next.
Frequently Asked Questions
Knowledge Graph Memory: How It Works?
Knowledge graph memory stores information as entities connected by typed relationships, making linked context queryable. For example, a travel-planning agent could connect a traveler, a trip, a booking, and a stated preference. A later query can retrieve the preference with its trip context. The key design choice is which facts merit durable nodes and which belong as attributes, so the graph stays meaningful rather than becoming a store for every sentence.
What is the Model Context Protocol and why does it matter for graph-powered agents?
The Model Context Protocol (MCP) is a standard way for AI applications to connect with tools and context providers. For graph-powered agents, an MCP server can expose memory operations without embedding database-specific access logic in every client. NovaCortex’s MCP server exposes 15 tools to Claude, Cursor, and MCP-compatible clients. This lets an agent request memory through a consistent interface while the memory layer handles its own storage and retrieval.
What is a graph database schema for AI memory?
A graph database schema for AI memory defines the node labels, relationship types, and properties used to represent persistent agent context. It determines how an application names concepts and expresses connections. For example, a support assistant might model a Case, Customer, and Resolution, then connect them with relationships that describe ownership and outcome. A stable schema helps different parts of an agent system interpret stored memories consistently as the application evolves.
What node and edge types should an AI memory graph include?
Include node types that match the memories your agent must use, such as Person, Project, Event, Document, and Preference. Use edge types that express specific connections, such as CREATED, PARTICIPATED_IN, SUPPORTS, or PREFERS. For a coding assistant, a Bug node could connect to a Repository, a commit, and a test result. Keep types distinct: a document mentioning a bug is evidence, not the bug itself.
How should entities, facts, events, and relationships be modeled in an AI memory graph?
Represent stable concepts as entity nodes, actions or changes as event nodes, and connections as typed relationships. Store a fact as a property when it describes one entity directly, such as a project’s status; use a relationship when it connects two entities. For example, “Riley assigned the task” becomes an assignment event linked to Riley and the task. This separation helps distinguish current state from the event that changed it.
How do graph databases support long-term memory for LLM agents?
Graph databases support long-term memory by keeping records available beyond a model’s current prompt and linking them for later retrieval. An LLM agent can store a user’s preferred coding language, then retrieve it in a later session when generating an example. The application decides what to persist, while the graph makes stored items accessible through entities and relationships. This separates durable memory from temporary conversation context.
How should an AI memory graph handle timestamps, provenance, confidence, and conflicting facts?
Store when a fact was recorded, where it came from, and how strongly the system supports it. If an employee’s role changes, preserve both records with their source and time rather than silently overwriting history. Retrieval can favor the newer record while retaining the older one for audit or historical questions. Keep confidence separate from provenance: confidence describes certainty, while provenance identifies the evidence behind the claim.
How can vector search be combined with a graph database for AI memory retrieval?
Use vector search to find text records resembling the query, then use their identifiers to locate related graph records. For example, a maintenance agent can find a similar equipment report and retrieve linked parts, inspections, and prior repairs. Keep identifiers consistent across stores, and update the vector record when its source text changes. This prevents an old embedding from pointing to graph context built around newer information.

FAQ
Knowledge Graph Memory: How It Works?
Knowledge graph memory stores information as entities connected by typed relationships, making linked context queryable. For example, a travel-planning agent could connect a traveler, a trip, a booking, and a stated preference. A later query can retrieve the preference with its trip context. The key design choice is which facts merit durable nodes and which belong as attributes, so the graph stays meaningful rather than becoming a store for every sentence.
What is the Model Context Protocol and why does it matter for graph-powered agents?
The Model Context Protocol (MCP) is a standard way for AI applications to connect with tools and context providers. For graph-powered agents, an MCP server can expose memory operations without embedding database-specific access logic in every client. NovaCortex’s MCP server exposes 15 tools to Claude, Cursor, and MCP-compatible clients. This lets an agent request memory through a consistent interface while the memory layer handles its own storage and retrieval.
What is a graph database schema for AI memory?
A graph database schema for AI memory defines the node labels, relationship types, and properties used to represent persistent agent context. It determines how an application names concepts and expresses connections. For example, a support assistant might model a Case, Customer, and Resolution, then connect them with relationships that describe ownership and outcome. A stable schema helps different parts of an agent system interpret stored memories consistently as the application evolves.
What node and edge types should an AI memory graph include?
Include node types that match the memories your agent must use, such as Person, Project, Event, Document, and Preference. Use edge types that express specific connections, such as CREATED, PARTICIPATED_IN, SUPPORTS, or PREFERS. For a coding assistant, a Bug node could connect to a Repository, a commit, and a test result. Keep types distinct: a document mentioning a bug is evidence, not the bug itself.
How should entities, facts, events, and relationships be modeled in an AI memory graph?
Represent stable concepts as entity nodes, actions or changes as event nodes, and connections as typed relationships. Store a fact as a property when it describes one entity directly, such as a project’s status; use a relationship when it connects two entities. For example, “Riley assigned the task” becomes an assignment event linked to Riley and the task. This separation helps distinguish current state from the event that changed it.
How do graph databases support long-term memory for LLM agents?
Graph databases support long-term memory by keeping records available beyond a model’s current prompt and linking them for later retrieval. An LLM agent can store a user’s preferred coding language, then retrieve it in a later session when generating an example. The application decides what to persist, while the graph makes stored items accessible through entities and relationships. This separates durable memory from temporary conversation context.
How should an AI memory graph handle timestamps, provenance, confidence, and conflicting facts?
Store when a fact was recorded, where it came from, and how strongly the system supports it. If an employee’s role changes, preserve both records with their source and time rather than silently overwriting history. Retrieval can favor the newer record while retaining the older one for audit or historical questions. Keep confidence separate from provenance: confidence describes certainty, while provenance identifies the evidence behind the claim.
How can vector search be combined with a graph database for AI memory retrieval?
Use vector search to find text records resembling the query, then use their identifiers to locate related graph records. For example, a maintenance agent can find a similar equipment report and retrieve linked parts, inspections, and prior repairs. Keep identifiers consistent across stores, and update the vector record when its source text changes. This prevents an old embedding from pointing to graph context built around newer information.