Skip to main content
Version: dev

RAG (Retrieval-Augmented Generation)

RAG enhances LLM responses by retrieving relevant context from your own data before generating an answer. DB-GPT provides a comprehensive RAG framework with multiple indexing and retrieval strategies, and runs knowledge-base chat as an agentic RAG loop.

Two phases: indexing and conversationโ€‹

INDEXING  (document-sync time)        CONVERSATION  (chat time)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
upload โ†’ chunk โ†’ indexes question
โ”‚ โ”‚
vector / keyword / agentic RAG loop:
knowledge-graph rewrite โ†’ retrieve
(+ structural tree, (maybe repeat) โ†’
+ code graph for code) fuse + rerank โ†’
cited answer

These two phases are decoupled โ€” indexing runs once at sync time; chat only retrieves and never re-indexes.

How the conversation works (agentic RAG)โ€‹

DB-GPT does not do a single retrieve-then-generate. An agent drives the loop:

The agent can rewrite the query, retrieve multiple times, fuse and rerank results, and produce a cited answer โ€” letting it handle complex or multi-part questions that one-shot RAG cannot. Full detail: Agentic RAG Conversation Principles.

Indexesโ€‹

All indexes operate on the same chunks, so chunking quality is the foundation.

IndexWhat it gives youBuilt
Vectorsemantic similarity via embeddings + cosineat sync time
Keyword (BM25)exact term matchingat sync time
Knowledge Graphgraph traversal over entities, document structure, headings, and codeat sync time
Structuralmarkdown-header tree / parent-child navigationat query time (from chunk heading metadata)
Code graphcode AST as function / class nodes (for code files / git repos)at sync time
tip

The Knowledge Graph index is a family of graphs: LLM-extracted triplets, a documentโ€“paragraph structure graph, a Markdown heading-hierarchy graph, and a code AST graph (parsed with tree-sitter). See Knowledge Base Indexing Principles.

Supported file formatsโ€‹

Upload and process a wide variety of document formats:

  • Documents: PDF, Word (.docx), Markdown, TXT
  • Spreadsheets: Excel (.xlsx), CSV
  • Web: HTML, URLs
  • Code: Python, Java, JavaScript, TypeScript, Go, Rust, C/C++ โ€” parsed into the code graph

Quick start with RAGโ€‹

  1. Open the DB-GPT Web UI
  2. Navigate to Knowledge Base in the sidebar
  3. Create a new knowledge base (choose index methods: Vector / Knowledge Graph / Full Text โ€” combinable)
  4. Upload your documents
  5. Wait for processing to complete
  6. Start chatting with your knowledge base (runs the agentic RAG loop)

For programmatic access, see the RAG Cookbook.

What's nextโ€‹