Cookies

With your permission, we use Google Analytics cookies to measure visits and improve the site. Necessary cookies are always on. You can change your choice or withdraw consent anytime in the footer, under Cookie settings. Cookie Policy

Skip to content

RAG and Knowledge ·Intermediate

Knowledge Graph RAG with Verifiable Citations

About this app

A Streamlit application demonstrating how Knowledge Graph-based Retrieval-Augmented Generation (RAG) provides multi-hop reasoning with fully verifiable source attribution.

  • Complete open-source code
  • Step-by-step tutorial
  • Runs on your computer

Technical sheet

Category
RAG and Knowledge
Difficulty
Intermediate
Models
Llama, Mistral
Frameworks
Ollama (local)
Runs locally?
Yes (Ollama)
Required keys
None

License Apache-2.0 · content curated and maintained by Doutor AI.

Full tutorial

A Streamlit application demonstrating how Knowledge Graph-based Retrieval-Augmented Generation (RAG) provides multi-hop reasoning with fully verifiable source attribution.

🎯 What Makes This Different?

Traditional vector-based RAG finds similar text chunks, but struggles with:

  • Questions requiring information from multiple documents
  • Complex reasoning chains
  • Providing verifiable sources for each claim

Knowledge Graph RAG solves these by:

  1. Building a structured graph of entities and relationships from documents
  2. Traversing connections to find related information (multi-hop reasoning)
  3. Tracking provenance so every claim links back to its source

✨ Features

FeatureDescription
🔗 Multi-hop ReasoningTraverse entity relationships to answer complex questions
📚 Verifiable CitationsEvery claim includes source document and text
🧠 Reasoning TraceSee exactly how the answer was derived
🏠 Fully LocalUses Ollama for LLM, Neo4j for graph storage

🚀 Quick Start

Prerequisites

  1. Ollama - Local LLM inference
# Install from https://ollama.ai
ollama pull llama3.2
  1. Neo4j - Knowledge graph database
# Using Docker
docker run -d \
  --name neo4j \
  -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/password \
  neo4j:latest

Installation

# Clone and navigate
cd knowledge_graph_rag_citations

# Install dependencies
pip install -r requirements.txt

# Run the app
streamlit run knowledge_graph_rag.py

📖 How It Works

Step 1: Document → Knowledge Graph

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│   Document      │ ──► │  LLM Extraction  │ ──► │ Knowledge Graph │
│   (Text/PDF)    │     │  (Entities+Rels) │     │    (Neo4j)      │
└─────────────────┘     └──────────────────┘     └─────────────────┘

The LLM extracts:

  • Entities: People, organizations, concepts, technologies
  • Relationships: How entities connect (e.g., "works_for", "created", "uses")
  • Provenance: Source document and chunk for each extraction

Step 2: Query → Multi-hop Traversal

┌─────────┐     ┌─────────────┐     ┌─────────────┐     ┌───────────┐
│  Query  │ ──► │  Find Start │ ──► │  Traverse   │ ──► │  Context  │
│         │     │   Entities  │     │  Relations  │     │  + Sources│
└─────────┘     └─────────────┘     └─────────────┘     └───────────┘

Step 3: Answer → Verified Citations

┌─────────────┐     ┌─────────────┐     ┌──────────────────┐
│   Context   │ ──► │  Generate   │ ──► │  Answer with     │
│ + Sources   │     │   Answer    │     │  [1][2] Citations│
└─────────────┘     └─────────────┘     └──────────────────┘
                                                │
                                                ▼
                                        ┌──────────────────┐
                                        │ Citation Details │
                                        │ • Source Doc     │
                                        │ • Source Text    │
                                        │ • Reasoning Path │
                                        └──────────────────┘

🖥️ Usage Example

1. Add a Document

Paste or select a sample document. The system extracts entities and relationships:

Document: "GraphRAG was developed by Microsoft Research. 
           Darren Edge led the project..."

Extracted:
  ├── Entity: GraphRAG (TECHNOLOGY)
  ├── Entity: Microsoft Research (ORGANIZATION)  
  ├── Entity: Darren Edge (PERSON)
  └── Relationship: Darren Edge --[WORKS_FOR]--> Microsoft Research

2. Ask a Question

Question: "Who developed GraphRAG and what organization are they from?"

3. Get Verified Answer

Answer: GraphRAG was developed by researchers at Microsoft Research [1], 
        with Darren Edge leading the project [2].

Citations:
  [1] Source: AI Research Paper
      Text: "GraphRAG is a technique developed by Microsoft Research..."
      
  [2] Source: AI Research Paper  
      Text: "...introduced by researchers including Darren Edge..."

🔧 Configuration

SettingDefaultDescription
Neo4j URIbolt://localhost:7687Neo4j connection string
Neo4j Userneo4jDatabase username
Neo4j Password-Database password
LLM Modelllama3.2Ollama model for extraction/generation

🏗️ Architecture

knowledge_graph_rag_citations/
├── knowledge_graph_rag.py   # Main Streamlit application
├── requirements.txt         # Python dependencies
└── README.md               # This file

Key Components

  • KnowledgeGraphManager: Neo4j interface for graph operations
  • extract_entities_with_llm(): LLM-based entity/relationship extraction
  • generate_answer_with_citations(): Multi-hop RAG with provenance tracking

🎓 Learn More

This example is inspired by VeritasGraph, an enterprise-grade framework for:

  • On-premise knowledge graph RAG
  • Visual reasoning traces (Veritas-Scope)
  • LoRA-tuned LLM integration

📝 License

MIT License

From the same category

RAG and KnowledgeIntermediate

Agentic RAG Embedding Gemma

This Streamlit app demonstrates an agentic Retrieval-Augmented Generation (RAG) Agent using Google's EmbeddingGemma for embeddings and Llama 3.2 as th…

  • Llama
  • local
RAG and KnowledgeIntermediate

Agentic RAG with GPT-5

An agentic RAG application built with the Agno framework, featuring GPT-5 and LanceDB for efficient knowledge retrieval and question answering.

  • OpenAI

Need a tailor-made solution?

Not sure where to start with AI in your business? Get a free assessment and a tailored plan - no commitment.

Save hours every week with AI, no hassle

Doutor AI gives you 1,859 ready-to-copy AI prompts, by industry and in plain English - plus a complete technical library for those who want to go further.

See plans