Generative AI

Knowledge graphs and retrieval-augmented generation

Give your language models a memory they can reason over. A knowledge graph stores facts and the relationships between them, so a RAG pipeline can retrieve grounded, traceable context instead of guessing. This is GraphRAG, and Neo4j is where you build it.

The foundation

What is a knowledge graph?

A knowledge graph is more than a pile of facts. It is two things working together: the data — real entities and the relationships between them — and the organizing principles that give the data a shape.

The simplest principle is the label on each node: Alice is a Person, Acme a Company — one flat level of classification. On top of that a graph holds richer structure, like a category hierarchy where companies operate in an industry that rolls up into a category. Hover the diagram to see each organizing principle in turn.

Explore the Neo4j Fundamentals course
  1. 1The data — real entities and the facts between them: Alice works at Acme.
  2. 2Labels — each node is classified by a label such as Person, Company, or Industry. A single, flat level of type, and the simplest organizing principle.
  3. 3A category hierarchy — companies operate in an industry, and industries roll up into a category: a multi-level taxonomy stored in the graph, so you can query at any level.

Retrieval · pattern two

Or query directly with text-to-Cypher

When a question is precise and structured — how many orders contain a product, which customers a supplier serves, the shortest path between two accounts — semantic search is the wrong tool. Text-to-Cypher takes the other route: an LLM turns the natural-language question directly into a Cypher query.

The query reads the exact nodes, relationships, and properties from the graph and returns them as a precise result. No embeddings, no approximation — just the structured answer, retrieved directly.

Learn text-to-Cypher retrieval
An LLM writes a Cypher query that returns exactly the nodes and relationships asked for.

Beyond retrieval

Give your agents a memory

The same graph that grounds retrieval can give an AI agent a memory. A context graph holds all three memory layers in one connected graph — and because they are connected, an agent can traverse from a final answer back to the message that prompted it and the entity it retrieved.

Hover the diagram to see each layer: the conversation, the entities the agent has learned, and the reasoning trace — end-to-end provenance a flat log or vector store cannot express.

Build agent memory with context graphs
  1. 1Short-term memory — the live conversation, stored as a chain of messages in one session.
  2. 2Long-term memory — a persistent graph of the entities the agent has learned about, surviving across sessions.
  3. 3Reasoning memory — an audit trail of every tool call and decision, so you can trace how an answer was reached.

The workflow

Prepare your data for GraphRAG

Four stages turn raw documents into a knowledge graph an agent can reason over, then let you evaluate how it decides. Each links to a hands-on course.

  1. 01

    Chunk your documents

    Split text documents into chunks and embed them, so semantic search can find the right passages.

  2. 02

    Build the knowledge graph

    Extract entities and relationships from the text and turn them into a connected knowledge graph.

  3. 03

    Build agentic GraphRAG

    Build agents that retrieve with the patterns above — semantic search and text-to-Cypher — to answer over your graph.

  4. 04

    Evaluate the decisions

    Use context graphs to evaluate your agents and understand why each decision was made.

FAQ

Common questions about GraphRAG

  • GraphRAG (Graph Retrieval-Augmented Generation) is the union of generative AI and knowledge graphs. A knowledge graph supplies contextual facts and the relationships between them to ground a large language model, which helps prevent hallucinations and produces more accurate, explainable answers.

  • Two ways. Semantic search uses a vector index to find relevant content by meaning, and you then traverse relationships to gather connected context. For precise, structured questions, text-to-Cypher has an LLM generate a Cypher query that reads the exact data straight from the graph.

  • Semantic search alone retrieves isolated passages by similarity and often misses how entities relate to one another. GraphRAG uses the connected structure of a knowledge graph to supply that context, so the model can answer complex queries that depend on relationships, not just keywords.

  • Yes. A context graph stores an agent’s short-term memory (the conversation), long-term memory (a graph of entities it has learned), and reasoning memory (a trace of its tool calls and decisions) in one connected graph, so the agent can recall context and explain how it reached an answer.

  • Black-box answers are hard to trust. Because every fact retrieved through GraphRAG has a place in the graph, you can trace the reasoning back to its source and show clear evidence for each response, which builds trust in your AI systems.

  • No. If you are new to graphs, start with Neo4j Fundamentals and Cypher Fundamentals, then take the Generative AI courses. The GraphRAG courses assume some Python and a little Cypher, but the fundamentals course begins from the core concepts.

Explore the Generative AI learning path

Every GraphRAG course in one place, in the order that builds each skill on the last. Start grounding your LLMs in a Neo4j knowledge graph today.

Browse GenAI courses