TOOL WIKI · MEMORY & STATE

Neo4j

Stores entities and relationships for graph-oriented queries and retrieval.

Download example files Code + setup + checks in a ZIP
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.

Official reference · Neo4j

WHAT IT ISGraph database
WHERE IT FITSMemory & state
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
candidateretainqueryrecordscontextmaintainInteractionSubject + evidenceWrite policySelect and verifyNeo4jGraph databaseRecall requestAuthenticated scopeContext builderRelevant selected factsLifecycle controlsCorrect, expire, delete
  1. Separate working conversation state from candidate long-term facts.

  2. Retain only permitted information and preserve where it came from.

  3. Memory questions that depend on relationships between entities. Graph extraction and temporal meaning need application-level design.

  4. Use verified tenant and subject identifiers when retrieving memory.

  5. Choose useful records within the current context budget.

  6. Apply corrections and deletion to records, derived indexes, and caches.

Neo4j

Memory questions that depend on relationships between entities. Graph extraction and temporal meaning need application-level design.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

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.
Shell
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

Python · 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

Shell
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

A layered architecture for agent memoryA context pipeline for a long-running agent

Explore the same layer

Mem0LettaZepGraphiti

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.