TOOL WIKI · MEMORY & STATE
Neo4j
Stores entities and relationships for graph-oriented queries and retrieval.
Jump to a section 10 sections
EXAMPLE USE CASE
Keep a scoped preference on a graph user node
A returning user’s preference or an unfinished run needs an explicit owner, storage lifetime and recall rule.
- Input
- Tenant/user identifiers and format=bullets.
- Expected output
- The matching node’s format from a parameterized graph query.
- 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: A query without tenant scope must be rejected before it reaches a shared graph.
Example scope: Actual graph-node write/read; this small example does not demonstrate graph traversal or automatic memory extraction.
Separate working conversation state from candidate long-term facts.
candidateTo 02 · Write policyRetain only permitted information and preserve where it came from.
retainTo 03 · Neo4jMemory questions that depend on relationships between entities. Graph extraction and temporal meaning need application-level design.
recordsTo 05 · Context builderUse verified tenant and subject identifiers when retrieving memory.
queryBack to 03 · Neo4jChoose useful records within the current context budget.
contextBack to 01 · InteractionApply corrections and deletion to records, derived indexes, and caches.
maintainBack to 03 · Neo4j
Memory questions that depend on relationships between entities. Graph extraction and temporal meaning need application-level design.
When to consider it
- Memory questions that depend on relationships between entities.
A design decision to make
- Graph extraction and temporal meaning need application-level design.
Prerequisites and setup
- An existing Neo4j test database and credentials with the minimum required permissions.
python3 -m venv .venv
source .venv/bin/activate
pip install neo4j
export NEO4J_URI="neo4j://localhost:7687"
export NEO4J_USER="YOUR_USER"
export NEO4J_PASSWORD="YOUR_PASSWORD"Try a small integration
memory.py
import os
from neo4j import GraphDatabase
with GraphDatabase.driver(os.environ["NEO4J_URI"], auth=(os.environ["NEO4J_USER"],os.environ["NEO4J_PASSWORD"])) as driver:
driver.verify_connectivity()
driver.execute_query("MERGE (u:AsgUser {tenant:$tenant,id:$user}) SET u.format=$format",
tenant="a", user="u1", format="bullets", database_="neo4j")
records, _, _ = driver.execute_query("MATCH (u:AsgUser {tenant:$tenant,id:$user}) RETURN u.format AS format",
tenant="a", user="u1", database_="neo4j")
print(records[0]["format"])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.
- Create composite uniqueness constraints for tenant and record ID, and keep Cypher parameterized. Graph relationships also need tenant scope.
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.