Neo4j Agent Memory
Neo4j Labs · Graph-native memory for AI agents
Your agents forget everything. Fix that.
Store conversations, build knowledge graphs, and let your agents learn from their own reasoning — all backed by Neo4j.
|
Experimental · Community Supported |
pip install neo4j-agent-memory
Get Started | GitHub | PyPI
Three Memory Types, One Graph
Most agent memory systems give you a flat context window or a simple vector store. Neo4j Agent Memory gives your agent three distinct memory layers — all connected in a single knowledge graph.
| Memory Type | What It Stores | Key Features |
|---|---|---|
Short-Term |
Conversations & experiences |
Semantic message search, session scoping, metadata filters, LLM-powered summaries |
Long-Term |
Facts, entities & preferences |
POLE+O entity classification, entity deduplication, temporal fact validity, geospatial queries |
Reasoning |
Tool usage & reasoning traces |
Trace similarity search, tool call statistics, message-linked traces, streaming trace recording |
async with MemoryClient(settings) as memory:
# Short-term: store conversations
await memory.short_term.add_message(session_id, "user", "Find Italian restaurants near me")
# Long-term: build a knowledge graph
await memory.long_term.add_entity("La Trattoria", "ORGANIZATION", subtype="COMPANY")
# Reasoning: record how the agent solved problems
trace = await memory.reasoning.start_trace(session_id, task="Restaurant search")
await memory.reasoning.record_tool_call(step.id, "search_api", {"query": "Italian"}, results)
await memory.reasoning.complete_trace(trace.id, outcome="Recommended La Trattoria", success=True)
# Get unified context for LLM prompts
context = await memory.get_context("restaurant recommendation", session_id=session_id)
What Makes This Different
| Capability | Why It Matters |
|---|---|
Graph-Native, Not Bolted On |
Built on Neo4j from the ground up. Entities, messages, traces, and preferences are all nodes and relationships — not rows in a table or chunks in a vector store. Query across memory types with a single traversal. |
Vector + Graph + Spatial in One |
Semantic similarity search, graph traversal, and geospatial queries all in one database. No separate vector DB, no Redis, no Postgres. Find entities by meaning, by relationship, or by location. |
Multi-Stage Entity Extraction |
Combine spaCy, GLiNER2, GLiREL, and LLM extractors in a configurable pipeline. 8 domain schemas (podcast, news, medical, legal…). Streaming extraction for 100K+ token documents. |
Three Memory Layers, Connected |
Short-term conversations inform long-term entity extraction. Reasoning traces link back to triggering messages. The agent understands what happened, what it knows, and how it solved things. |
Wikipedia Enrichment & Geocoding |
Entities are automatically enriched with Wikipedia descriptions, images, and Wikidata IDs. Location entities get coordinates for geospatial queries. All in the background. |
Framework Agnostic |
Works with LangChain, PydanticAI, LlamaIndex, and CrewAI. Or use the client directly. Your agent framework, your choice — the memory layer stays the same. |
Demos
Lenny’s Podcast Memory Explorer (Flagship)
299 podcast episodes transformed into a searchable knowledge graph with a full-stack AI chat agent, interactive graph visualization, geospatial map view, and Wikipedia-enriched entity cards.
| Episodes loaded | Agent tools | Memory types |
|---|---|---|
299 |
19 |
3 |
-
Interactive graph visualization (Neo4j NVL)
-
Geospatial map with marker clusters & heatmaps
-
Wikipedia-enriched entity cards with images
-
SSE streaming with tool call visualization
-
Automatic preference learning from conversation
-
FastAPI + PydanticAI + Next.js + Chakra UI
Full-Stack Chat Agent
A news research assistant that uses all three memory types with an interactive memory graph visualization. Double-click nodes to expand neighbors and explore the knowledge graph.
-
Memory graph visualization with expansion
-
Conversation-scoped graph filtering
-
Dual Neo4j databases (memory + news)
Quick Start
pip install neo4j-agent-memory[openai]
import asyncio
from pydantic import SecretStr
from neo4j_agent_memory import MemoryClient, MemorySettings
async def main():
settings = MemorySettings(
neo4j={"uri": "bolt://localhost:7687", "password": SecretStr("password")}
)
async with MemoryClient(settings) as memory:
# Store a conversation
await memory.short_term.add_message("user-123", "user", "I love Italian food!")
# Build knowledge automatically
await memory.long_term.add_preference("food", "Loves Italian cuisine", confidence=0.9)
# Get combined context for your LLM
context = await memory.get_context("restaurant recommendation", session_id="user-123")
print(context)
asyncio.run(main())
Entity Extraction Pipeline
Combine extractors in a configurable pipeline. 5 merge strategies. 8 domain schemas. Streaming extraction for 100K+ token documents.
| Stage | Purpose | Best for |
|---|---|---|
spaCy |
Fast rule-based & statistical NER |
High throughput, no API cost |
GLiNER2 |
Zero-shot NER with domain schemas |
Accuracy without LLM cost |
GLiREL |
Relation extraction between entities |
Graph edge extraction |
LLM fallback |
High-accuracy extraction via API |
Complex or ambiguous text |
Framework Integrations
| Framework | Integration | Guide |
|---|---|---|
LangChain |
Memory & retriever |
|
PydanticAI |
Deps & trace recording |
|
LlamaIndex |
Memory nodes |
|
CrewAI |
Crew memory |
|
AWS Strands |
Agent tools |
|
Google ADK |
MemoryService |
Documentation
| Section | Purpose | Start here |
|---|---|---|
Learn by building complete examples |
||
Practical recipes for common tasks |
||
Technical specifications and API docs |
||
Concepts and architecture |
Quick Links
| Guide | Description |
|---|---|
Installation, setup, and your first memory-enabled agent |
|
Deep dive into short-term, long-term, and reasoning memory |
|
Domain schemas, multi-stage pipelines, and custom extractors |
|
Complete configuration options and environment variables |
|
Using with PydanticAI, LangChain, LlamaIndex, and CrewAI |