TOOL WIKI · MEMORY & STATE
Graphiti
Builds and queries time-aware context graphs with provenance.
Jump to a section 10 sections
EXAMPLE USE CASE
Recall a preference with episode provenance
A returning user’s preference or an unfinished run needs an explicit owner, storage lifetime and recall rule.
- Input
- An episode, reference time, source description and group ID.
- Expected output
- Extracted facts matching the response-format question.
- Success check: The stored preference can be recalled for the intended user. Inspect the record and its source rather than only the generated answer.
- Try a failure: Search another group and verify that scoped facts are not returned.
Example scope: Actual temporal-graph ingestion/search using configured graph and model services.
Separate working conversation state from candidate long-term facts.
candidateTo 02 · Write policyRetain only permitted information and preserve where it came from.
retainTo 03 · GraphitiRepresenting changing entities, relationships, and historical facts. It is a graph-building framework; choose and operate the backing store.
recordsTo 05 · Context builderUse verified tenant and subject identifiers when retrieving memory.
Choose useful records within the current context budget.
contextBack to 01 · InteractionApply corrections and deletion to records, derived indexes, and caches.
maintainBack to 03 · Graphiti
Representing changing entities, relationships, and historical facts. It is a graph-building framework; choose and operate the backing store.
When to consider it
- Representing changing entities, relationships, and historical facts.
A design decision to make
- It is a graph-building framework; choose and operate the backing store.
Prerequisites and setup
- A compatible Neo4j service, a restricted scratch database and provider credentials for extraction/embedding.
- This example uses Graphiti’s default OpenAI clients; configure alternative clients explicitly when changing provider.
python3 -m venv .venv
source .venv/bin/activate
pip install graphiti-core
export OPENAI_API_KEY="YOUR_KEY"
export NEO4J_URI="bolt://localhost:7687"
export NEO4J_USER="neo4j"
export NEO4J_PASSWORD="YOUR_LOCAL_PASSWORD"Try a small integration
memory.py
import asyncio
import os
from datetime import datetime, timezone
from graphiti_core import Graphiti
from graphiti_core.nodes import EpisodeType
async def main():
graph = Graphiti(os.environ["NEO4J_URI"],os.environ["NEO4J_USER"],os.environ["NEO4J_PASSWORD"])
try:
await graph.build_indices_and_constraints()
await graph.add_episode(name="format-preference", episode_body="Demo User prefers concise bullet answers.",
source=EpisodeType.text, source_description="Explicit user preference in demo conversation",
reference_time=datetime.now(timezone.utc), group_id="asg-demo-user")
results = await graph.search("What answer format does Demo User prefer?", group_ids=["asg-demo-user"])
print([r.fact for r in results])
finally:
await graph.close()
asyncio.run(main())Run and check the result
python memory.py- The stored preference can be recalled for the intended user. Inspect the record and its source rather than only the generated answer.
- A different user must not inherit this preference.
Common failures
- Extraction acceptance does not establish immediate query visibility; inspect job/index state when results are empty.
- Do not silently copy memory across users after a failed lookup.
Production decisions
- Define allowed memory types, evidence/provenance, correction, expiry and user deletion before accepting automatic writes.
- Derive user and tenant scope from authenticated application state. Test cross-user recall, expired facts and deletion from every derived index.
- A group_id partitions retrieval; application authorization must decide which group IDs the caller may access. Validate temporal conflicts and graph-summary deletion.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.