Skip to content
Projects

About

๐Ÿ” Deep RAG: Advanced Retrieval-Augmented Generation system that goes beyond vector search. Enables AI to perform multi-hop reasoning, negation queries, numerical comparisons & global aggregation on your knowledge base. Supports OpenAI, Anthropic, Google Gemini. Python FastAPI + React UI

Web & App Development

How these counts are measured

What you can do

  • Negation Queries ("except", "besides") - โŒ - โœ…
  • Numerical Comparison ("greater than", "less than") - โŒ - โœ…
  • Finding Extremes ("maximum", "minimum") - โŒ - โœ…
  • Cross-document Comparison - โŒ - โœ…

Measured star growth

in 24h
0
in 7 days
0
in 15 days
+2
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

๐Ÿ” Deep RAG: Teaching AI to Truly "Understand" Your Knowledge Base

License Python 3.8+ Node.js 16+

[ English | ไธญๆ–‡ ]

Features โ€ข Quick Start โ€ข How It Works โ€ข Architecture โ€ข Configuration


Negation Exclusion.png

๐Ÿ“ธ Click to see more example images

Finding Extremes.png Comparative Synthesis.png Multi-hop Reasoning.png Global Understanding.png


๐ŸŒŸ Why Deep RAG?

The Problem with Traditional RAG

Traditional RAG systems:

  • โŒ Split documents into fragments, losing structure
  • โŒ Can only "find similar" content, not "find opposite"
  • โŒ Struggle with numerical comparisons and negation logic
  • โŒ Cannot perform multi-hop reasoning across documents
  • โŒ Lack global understanding for aggregation queries

The Deep RAG Solution

Traditional RAG: Fragment documents โ†’ Retrieve chunks โ†’ Feed to model
Deep RAG:        Preserve structure โ†’ Give model a "map" โ†’ Let model navigate

Deep RAG provides:

  • โœ… File Summary as Knowledge Map: LLM sees the entire structure
  • โœ… Active Navigation: Model retrieves what it needs, when it needs it
  • โœ… Multi-round Retrieval: Supports complex multi-hop reasoning
  • โœ… Complete Context: Retrieves full files/directories, not fragments

Want to learn more about Deep RAG? Welcome to read the intuitive and easy-to-understand article: ๐Ÿ” Deep RAG: Teaching AI to Truly "Understand" Your Knowledge Base


๐ŸŽฏ Features

Core Capabilities

Capability Traditional RAG Deep RAG
Negation Queries ("except", "besides") โŒ โœ…
Numerical Comparison ("greater than", "less than") โŒ โœ…
Finding Extremes ("maximum", "minimum") โŒ โœ…
Cross-document Comparison โŒ โœ…
Temporal Reasoning ("last year", "previous") โŒ โœ…
Multi-turn Memory โŒ โœ…
Multi-hop Reasoning โŒ โœ…
Global Aggregation โŒ โœ…

Technical Features

  • ๐Ÿ”Œ Universal LLM Support: OpenAI, Anthropic, Google Gemini, or any OpenAI-compatible API
  • ๐Ÿ› ๏ธ Dual Tool Calling Modes: Function Calling + ReAct
  • ๐ŸŽจ Modern Web UI: Built with React + TypeScript + Vite
  • โšก Streaming Responses: Real-time response streaming
  • ๐Ÿ”ง Easy Configuration: Web-based .env editor
  • ๐Ÿ“Š Tool Call Visualization: See what the AI is doing

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • An LLM API Key (OpenAI, Google Gemini, Anthropic, or compatible)

Installation

  1. Clone the repository
git clone https://github.com/boluo2077/deep-rag.git
cd deep-rag
  1. Configure environment variables
cp .env.example .env
# Edit .env with your API keys
  1. Start the application
./start.sh

Quick start (skip dependency checks):

./start.sh --fast

The script will:

  • โœ… Create Python virtual environment
  • โœ… Install backend dependencies
  • โœ… Install frontend dependencies
  • โœ… Start backend server (http://localhost:8000)
  • โœ… Start frontend dev server (http://localhost:5173)
  • โœ… Open browser automatically

Manual Start (Alternative)

Backend:

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn backend.main:app --host 0.0.0.0 --port 8000

Frontend:

cd frontend
npm install
npm run dev

Stop/Restart

./stop.sh
./restart.sh
./restart.sh --full

๐Ÿ’ก How It Works

1. Knowledge Base Structure

Instead of splitting documents into chunks, Deep RAG preserves your file structure:

Knowledge-Base/
โ”œโ”€ Product-Line-A-Smartwatch-Series/
โ”‚  โ”œโ”€ SW-2100-Flagship.md
โ”‚  โ”œโ”€ SW-1800-Business.md
โ”‚  โ””โ”€ SW-1500-Sport.md
โ”œโ”€ 2023-Market-Layout/
โ”‚  โ”œโ”€ East-China-Region.md
โ”‚  โ””โ”€ South-China-Region.md
โ””โ”€ Supplier-Partnership-Records/
   โ””โ”€ Display-Supplier-CrystalVision.md

2. File Summary Generation

Generate a structured summary of your knowledge base:

cd Knowledge-Base-File-Summary
python generate.py

This creates a "knowledge map" that looks like:

Product-Line-A-Smartwatch-Series/
โ”œโ”€ SW-2100-Flagship.md: 2.1" AMOLED, 72h battery, IP68, $2999
โ”œโ”€ SW-1800-Business.md: 1.8" LCD, 48h battery, IP67, $1899
โ””โ”€ SW-1500-Sport.md: 1.5" TFT, 36h battery, IP68, $999

3. System Prompt Integration

The file summary is injected into the system prompt, giving the LLM:

  • ๐Ÿ“ Overview of all available knowledge
  • ๐Ÿ—บ๏ธ File paths for targeted retrieval
  • ๐ŸŽฏ Ability to plan multi-step queries

4. Active Retrieval

When answering questions, the LLM can:

retrieve_files([
    "Product-Line-A-Smartwatch-Series/SW-2100-Flagship.md",  # Specific file
    "2023-Market-Layout/",                                     # Entire directory
    "/"                                                        # All files
])

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                       Frontend (React)                       โ”‚
โ”‚  โ€ข Chat Interface  โ€ข Config Panel  โ€ข System Prompt Viewer   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚ HTTP/SSE
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Backend (FastAPI)                         โ”‚
โ”‚  โ€ข LLM Provider Abstraction  โ€ข Tool Calling Handler         โ”‚
โ”‚  โ€ข Knowledge Base Manager    โ€ข ReAct Mode Support           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                   โ”‚                   โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”          โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”
   โ”‚Knowledgeโ”‚         โ”‚  LLM  โ”‚          โ”‚ Tools โ”‚
   โ”‚  Base   โ”‚         โ”‚  API  โ”‚          โ”‚(Func/ โ”‚
   โ”‚  Files  โ”‚         โ”‚       โ”‚          โ”‚ReAct) โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Project Structure

deep-rag/
โ”œโ”€โ”€ backend/                   # FastAPI backend
โ”‚   โ”œโ”€โ”€ main.py               # API endpoints
โ”‚   โ”œโ”€โ”€ config.py             # Configuration management
โ”‚   โ”œโ”€โ”€ llm_provider.py       # LLM provider abstraction
โ”‚   โ”œโ”€โ”€ knowledge_base.py     # Knowledge base operations
โ”‚   โ”œโ”€โ”€ prompts.py            # System prompts & tools
โ”‚   โ”œโ”€โ”€ react_handler.py      # ReAct mode handler
โ”‚   โ””โ”€โ”€ models.py             # Pydantic models
โ”œโ”€โ”€ frontend/                  # React frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx           # Main app component
โ”‚   โ”‚   โ”œโ”€โ”€ components/       # React components
โ”‚   โ”‚   โ””โ”€โ”€ api.ts            # API client
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ Knowledge-Base/            # Your documents
โ”œโ”€โ”€ Knowledge-Base-Chunks/     # Chunked documents (optional)
โ”œโ”€โ”€ Knowledge-Base-File-Summary/
โ”‚   โ”œโ”€โ”€ generate.py           # Summary generator
โ”‚   โ””โ”€โ”€ summary.txt           # Generated summary
โ”œโ”€โ”€ .env.example              # Environment config template
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”œโ”€โ”€ start.sh                  # Start script
โ”œโ”€โ”€ stop.sh                   # Stop script
โ””โ”€โ”€ restart.sh                # Restart script

โš™๏ธ Configuration

Environment Variables

Edit .env to configure:

# LLM Provider (openai, google, anthropic, custom)
API_PROVIDER=google

# Tool Calling Mode (function, react)
TOOL_CALLING_MODE=function

# Model Parameters
TEMPERATURE=0
MAX_TOKENS=8192

# Knowledge Base Paths
KNOWLEDGE_BASE_PATH=./Knowledge-Base
KNOWLEDGE_BASE_FILE_SUMMARY=./Knowledge-Base-File-Summary/summary.txt

# Google Gemini
GOOGLE_API_KEY=your_google_key
GOOGLE_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai
GOOGLE_MODEL=gemini-2.5-flash-lite

# OpenAI
OPENAI_API_KEY=your_openai_key
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4.1-mini

# Anthropic Claude
ANTHROPIC_API_KEY=your_anthropic_key
ANTHROPIC_BASE_URL=https://api.anthropic.com/v1
ANTHROPIC_MODEL=claude-3-5-sonnet-20241022

# Custom Provider (any OpenAI-compatible API)
CUSTOM_API_KEY=your_api_key
CUSTOM_BASE_URL=https://your-api.com/v1/chat/completions
CUSTOM_MODEL=your-model

Adding New LLM Providers

No code changes needed! Just add to .env:

PROVIDER_NAME_API_KEY=your_key
PROVIDER_NAME_BASE_URL=https://api.provider.com/v1
PROVIDER_NAME_MODEL=model-name

API_PROVIDER=provider_name

Tool Calling Modes

Function Calling Mode (Recommended)

  • For models with native function calling support
  • Examples: GPT-4+, Gemini 1.5+, Claude 3.5+
  • More reliable and structured

ReAct Mode

  • For models without function calling
  • Uses prompt-based reasoning and action
  • Compatible with any text-completion model

If this project helps you, please click the โญ Star in the top right corner!

Your Star is our motivation to keep improving ๐Ÿ’ช


Back to Top

Explore related projects

Loadingโ€ฆ