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

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.

Short-Term Memory

Conversations & experiences

Full conversation history with sequential message chains, session management, metadata-based search, and conversation summaries.

  • Semantic message search
  • Session scoping & listing
  • Metadata filters
  • LLM-powered summaries

Long-Term Memory

Facts, entities & preferences

A knowledge graph of entities (people, places, orgs), preferences, facts, and relationships — built automatically from conversations.

  • POLE+O entity classification
  • Entity deduplication
  • Temporal fact validity
  • Geospatial queries

Reasoning Memory

Tool usage & reasoning traces

Records how the agent solved problems — every thought, tool call, and outcome — so it can learn from past reasoning patterns.

  • 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

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

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)

Domain Schema Examples

8 specialized extraction schemas for different domains. See how GLiNER2 domain schemas improve entity extraction accuracy with type descriptions and confidence tuning.

Podcast News Scientific Business Medical Legal Entertainment POLE+O

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", importance=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

spaCy Fast & free
GLiNER2 Zero-shot NER
GLiREL Relation extraction
LLM High accuracy
Knowledge Graph Merged results

Combine extractors in a configurable pipeline. 5 merge strategies. 8 domain schemas. Streaming extraction for 100K+ token documents.

Architecture

                         ┌─────────────────────────────────────────────┐
                         │              MemoryClient                   │
                         ├───────────────┬──────────────┬──────────────┤
                         │  Short-Term   │  Long-Term   │  Reasoning   │
                         │  Memory       │  Memory      │  Memory      │
                         ├───────────────┴──────────────┴──────────────┤
                         │          Extraction Pipeline                 │
                         │  ┌───────┬─────────┬────────┬─────┐        │
                         │  │ spaCy │ GLiNER2 │ GLiREL │ LLM │        │
                         │  └───────┴─────────┴────────┴─────┘        │
                         ├─────────────────────────────────────────────┤
                         │        Neo4j Graph Database                  │
                         │   Nodes · Relationships · Vectors · Spatial │
                         └─────────────────────────────────────────────┘

Requirements

  • Python 3.10+

  • Neo4j 5.20+ (with APOC plugin recommended)

  • OpenAI API key (for embeddings and LLM extraction)