Moving Beyond RAG with Context Graphs

Standard RAG (Retrieval-Augmented Generation) systems often struggle to provide explainable, high-quality decisions because they rely solely on static knowledge bases. A context graph evolves this by adding a layer of reasoning and history. It connects entities (customers, transactions, policies) with "decision traces"—the documented reasoning and outcomes of past actions. This allows an agent to not just retrieve facts, but to analyze why a previous decision was made and whether that precedent applies to the current case.

Structural vs. Semantic Retrieval

While traditional vector search relies on semantic similarity (finding text that "sounds" like the query), context graphs enable structural similarity searches. By embedding the graph structure itself (using Graph Data Science tools), agents can identify past decisions that are structurally similar to the current scenario. This allows the system to surface relevant "precedents"—causal chains of events that led to specific outcomes—which are often impossible to extract from flat document stores.

Rapid Prototyping with create-context-graph

To lower the barrier to entry, Neo4j provides a scaffolding tool, uvx create-context-graph, which generates a full-stack application (frontend, backend, demo data, and MCP server) with a single command.

Key features include:

  • Domain Support: Ships with 22 built-in domain ontologies (e.g., healthcare, finance) or can generate a custom schema based on a user-provided domain description.
  • Memory Management: The neo4j-agent-memory package handles the complex pipeline of entity extraction, deduplication, and merging. It uses a multi-stage approach: spaCy for initial processing, GLiNER for entity recognition, and an LLM fallback for refinement.
  • Framework Integration: Designed to plug into modern agentic frameworks including Pydantic AI, LangGraph, CrewAI, and the Google ADK.

The Three-Layer Memory Architecture

Effective agent memory requires a unified approach across three distinct layers:

  1. Short-term: Conversation history and immediate session context.
  2. Long-term: Entities extracted and resolved over time, stored as nodes in the graph.
  3. Reasoning: The decision traces and causal chains that link entities, providing the "why" behind agent recommendations.