MS-RAG
Multi-Source Enhanced Retrieval-Augmented Generation Framework (MS-RAG)
This page is the framework reference. For the why behind indexing and the agentic retrieval loop, read the design docs first:
- Knowledge Base Indexing Principles โ how a document becomes searchable: structural / knowledge-graph (incl. code graph) / vector / keyword indexes.
- Agentic RAG Conversation Principles โ how a question becomes a cited answer via an agent-driven retrieval loop.
Introduction
Large Language Models (LLMs) are powerful, but they can only answer based on the data they were trained on. When users need up-to-date or domain-specific information โ such as internal documents, proprietary databases, or the latest reports โ LLMs alone fall short.
Retrieval-Augmented Generation (RAG) bridges this gap by retrieving relevant information from external knowledge sources and feeding it as context to the LLM before generating a response. This ensures answers are grounded in real data rather than memorized patterns.
DB-GPT implements a Multi-Source RAG (MS-RAG) framework that goes beyond basic document Q&A. It supports multiple knowledge sources (documents, URLs, databases, knowledge graphs, git repos), multiple indexing strategies, and integrates deeply with the DB-GPT agent and workflow ecosystem. Conversation over a knowledge base is performed by an agentic RAG loop โ the agent can rewrite the query, retrieve multiple times, fuse and rerank results, and produce a cited answer โ rather than a single retrieve-then-generate pass.
Architecture
Two phases: indexing and conversationโ
INDEXING (runs at document-sync time) CONVERSATION (runs at chat time)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Knowledge Source โ Chunking โ Indexes User question
โ โ
one chunking, โผ
multiple indexes: Agentic RAG loop
โข Vector โข Keyword (query rewrite โ retrieve
โข Knowledge-graph (triplets, multiple times โ fuse +
โข document-paragraph, Markdown rerank โ assemble prompt)
โข heading, code AST) โ
โผ
LLM generates a cited answer
Indexing and conversation are decoupled: indexing happens once when documents are synced; chat only retrieves and never re-indexes.
Indexing pipelineโ
Building an index is an ETL pipeline โ one extract + one chunk feeds every enabled index; only the per-index transform and load differ.
Extract Transform Load
โโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ
Knowledge.load() โ ChunkManager.split() โ persist into the index store
parse source โ + per-index transform: ยท EmbeddingAssembler โ vector DB
raw text ยท embed (vector) ยท BM25Assembler โ Elasticsearch
ยท tokenize (keyword / BM25) ยท graph store + RepoGraphBuilder
ยท triplets / heading / โ graph store / code graph
code AST (knowledge graph) ยท SummaryAssembler โ vector DB
ยท summary (summary) ยท DBSchemaAssembler โ vector DB
attach metadata (header path,
chunk_id, โฆ) for retrieval/citation
- Extract โ
KnowledgeFactoryroutes each data source (file / URL / text / git repo) to the rightKnowledgeimplementation, which parses it into raw text (Knowledge.load()). - Transform โ
ChunkManager.split()chunks the text (by size / page / paragraph / separator / markdown headers) and each index applies its own transform โ embedding, BM25 tokenization, LLM triplet / heading / code-AST extraction, summary, or schema embedding โ attaching metadata (Header1โฆHeader6,chunk_id, โฆ) that later underpins retrieval and citation. - Load โ the per-index driver persists the transformed representation into the index store:
EmbeddingAssembler/BM25Assembler/SummaryAssembler/DBSchemaAssemblerfor the vector / keyword / summary / schema indexes, and the graph store (aload_document) +RepoGraphBuilderfor the knowledge-graph and code-graph indexes. (The structural index is not loaded โ it is rebuilt at retrieve time from theHeaderNmetadata written in this stage.) - Retrieval & Generation โ this is the agentic RAG conversation (see next section).
Indexing ETL pipelineโ
BaseAssembler defines the common Extract โ Transform โ Load shape; each index type plugs in its own transform + load. One extract + one chunking feeds every enabled index โ only the transform + load differ per index.
Knowledge.load() โ ChunkManager.split() โ Assembler.persist() โ Assembler.as_retriever()
# Extract # Transform # Load # retrieve-time (chat)
| Index | Transform | Load driver (implementation) | Index store |
|---|---|---|---|
| Vector | chunk โ embedding | EmbeddingAssembler.persist() | Vector DB (Chroma, Milvus, โฆ) |
| Keyword | chunk โ BM25 tokens | BM25Assembler.persist() | Elasticsearch |
| Knowledge graph | chunk โ LLM triplets + document/heading/code-AST graph | graph store aload_document + RepoGraphBuilder | TuGraph / Neo4j / Memgraph |
| Summary | chunk โ LLM summary โ embedding | SummaryAssembler.persist() | Vector DB |
| DB schema | schema โ embedding | DBSchemaAssembler.persist() | Vector DB |
| Code graph | code โ tree-sitter AST | RepoGraphBuilder โ CodeGraphStore | code-graph tables |
| Structural | (none โ built at retrieve time) | retrieve-time DocTreeIndex from HeaderN metadata | โ |
The assemblers are the Load-stage drivers for the vector / keyword / summary / schema indexes. The knowledge-graph and code-graph indexes are built by the graph store and
RepoGraphBuilderrespectively. All of them consume the same chunks produced in the Extract + Transform stage โ which is why chunking quality is the shared foundation under every index.
Indexes
DB-GPT selects which indexes to build per knowledge space via index_methods (a string list). Three index methods are persisted; structural index and code graph are two extra shapes layered on top. All indexes operate on the same chunks, so chunking quality dominates retrieval quality.
| Index | index_methods value | Built at sync time? | What it gives you |
|---|---|---|---|
| Vector | VectorStore | yes | semantic similarity ranking via embeddings + cosine |
| Keyword | FullText | yes | exact term / BM25 hits |
| Knowledge-graph | KnowledgeGraph | yes | graph traversal over entities, document structure, headings, and code |
| Structural | (retrieve-time tree) | no โ rebuilt at query time from HeaderN chunk metadata | markdown-header tree / parent-child section navigation |
| Code graph | (layered on KnowledgeGraph; also for GIT_REPO spaces) | yes | AST of code files as function / class nodes with defines edges |
The knowledge-graph index is not one graph but a family: an LLM-extracted triplet graph, a documentโparagraph structure graph, a Markdown heading-hierarchy graph, and (for code/git repos) a code AST graph. They share one build path. Details and the code-graph tree-sitter parsing are in Knowledge Base Indexing Principles.
Conversation: agentic RAG
When a user asks a question over a knowledge base, DB-GPT does not do a single retrieve-then-generate. Instead an agent drives the loop:
question
โ
โผ
query rewrite / multi-query โโโ LLM expands the question for better recall
โ
โผ
retrieve (vector + keyword + graph, possibly repeated) โโโ may iterate: retrieve โ judge โ retrieve again
โ
โผ
fusion + rerank
โ
โผ
assemble context, generate answer with citations
This agentic loop โ multi-step retrieval, query rewriting, result fusion and reranking, and citation โ is what lets DB-GPT answer complex or multi-part questions that a one-shot RAG cannot. The full flow is documented in Agentic RAG Conversation Principles.
Retrieval strategiesโ
You can configure the retrieve mode in the knowledge base settings:

| Strategy | Description | Backend Required |
|---|---|---|
| Semantic | Vector similarity search using embeddings | Vector Store |
| Keyword | BM25-based keyword matching | Elasticsearch |
| Hybrid | Combines vector + keyword search with Reciprocal Rank Fusion (RRF) | Vector Store + Elasticsearch |
| Tree | Tree-structured retrieval over the markdown heading hierarchy | Vector Store |
Query enhancementโ
Beyond raw retrieval, the agentic loop provides advanced query processing:
- Query Rewrite โ Uses an LLM to expand and rephrase the original query into multiple search queries for better recall, and to decide whether another retrieval round is needed.
- Reranking โ After retrieval, a reranker re-scores and re-orders the results for higher precision before they enter the prompt.
Supported Rerankersโ
| Reranker | Type | Description |
|---|---|---|
| CrossEncoderRanker | Local | Uses sentence-transformers CrossEncoder models |
| QwenRerankEmbeddings | Local | Qwen3-Reranker via transformers |
| OpenAPIRerankEmbeddings | API | Compatible with OpenAI-style rerank APIs |
| RRFRanker | Algorithm | Reciprocal Rank Fusion for merging multi-source results |
| DefaultRanker | Algorithm | Simple score-based sorting |
Knowledge Sources
DB-GPT supports loading knowledge from multiple source types. In the Web UI, you can select a datasource type when uploading:

Datasource Typesโ
| Type | Description | Example |
|---|---|---|
| Document | Upload files in various formats | PDF, Word, Excel, CSV, Markdown, PowerPoint, TXT, HTML, JSON, ZIP |
| URL | Fetch and index web page content | Any accessible HTTP/HTTPS URL |
| Text | Directly input raw text | Paste text content in the UI |
| Yuque | Import from Yuque documentation platform | Yuque document links |
| Git Repo | Clone a code repository and index it as a code graph | A GitHub/GitLab repo URL |
Supported Document Formatsโ
| Format | Extension | Knowledge Class |
|---|---|---|
.pdf | PDFKnowledge | |
| CSV | .csv | CSVKnowledge |
| Markdown | .md | MarkdownKnowledge |
| Word (docx) | .docx | DocxKnowledge |
| Word (legacy) | .doc | Word97DocKnowledge |
| Excel | .xlsx | ExcelKnowledge |
| PowerPoint | .pptx | PPTXKnowledge |
| Plain Text | .txt | TXTKnowledge |
| HTML | .html | HTMLKnowledge |
| JSON | .json | JSONKnowledge |
| Code | .py .java .js .ts .go .rs .c .cpp โฆ | CodeFileKnowledge (parsed with tree-sitter into the code graph) |
Storage Types
When creating a knowledge base, you choose which index store(s) to use โ one or more can be enabled together and are complementary:

| Storage Type | index_methods | Description | Best For |
|---|---|---|---|
| Vector Store | VectorStore | Stores document embeddings for semantic similarity search | General-purpose document Q&A |
| Knowledge Graph | KnowledgeGraph | Builds the graph family (LLM triplets + document/heading/code structure) for relational retrieval | Domain knowledge with entity relationships, code, structured docs |
| Full Text | FullText | Full-text/BM25 index for keyword-based retrieval | Exact term matching and keyword search |
Vector Store Backendsโ
| Backend | Description | Install Extra |
|---|---|---|
| ChromaDB | Default embedded vector database, zero setup | storage_chromadb |
| Milvus | Distributed vector database for production scale | storage_milvus |
| PGVector | PostgreSQL extension for vector operations | storage_pgvector |
| Valkey | High-performance in-memory vector store with HNSW/FLAT indexing | storage_valkey |
| Weaviate | Cloud-native vector search engine | storage_weaviate |
| Elasticsearch | Full-text + vector hybrid search | storage_elasticsearch |
| OceanBase | Cloud-native distributed database | storage_oceanbase |
Knowledge Graph Backendsโ
| Backend | Description |
|---|---|
| TuGraph | High-performance graph database by Ant Group |
| Neo4j | Popular open-source graph database |
| Memgraph | In-memory graph database for low-latency queries |
Full-Text Backendsโ
| Backend | Description |
|---|---|
| Elasticsearch | Industry-standard full-text search engine |
| OpenSearch | AWS-managed search and analytics suite |
Knowledge Graph RAG
When the KnowledgeGraph index method is enabled, DB-GPT builds a family of graphs, not a single one. They share one build path and all support edge-traversal retrieval:
- LLM triplet graph โ An LLM extracts
(subject, predicate, object)triplets from each chunk; triplets are upserted asentity -edge- entityinto the graph store (TuGraph, Neo4j, or Memgraph). Each edge remembers the chunk it came from, so answers stay citable. - Documentโparagraph graph โ a structural skeleton of
document โ chunk โ chunk(include/nextedges) so retrieval can hop from an entity to the chunk and document that contain it. (With the community-summary variant, communities are also detected and summarised by an LLM.) - Markdown heading graph โ for
.mdfiles, afile โ H1 โ H2 โ H3(contains) hierarchy. This is the graph analogue of the structural index. - Code graph โ for code files and
GIT_REPOspaces, the source is parsed with tree-sitter (Python / Java / JavaScript / TypeScript / Go / Rust / C / C++) andfunction/class/method/interface/structโฆ nodes are emitted withfile โ defines โ nodeedges. This enables precise code-level questions such as "where isapply_anthropic_cache_controldefined?".
The retriever also supports CALLS / INHERITS / IMPLEMENTS edges, but the current code-graph builder only emits contains and defines. Call-chain and inheritance traversals only return data when those edges were produced by another builder. See Knowledge Base Indexing Principles for the full detail and this caveat.
Graph retrieval sub-strategiesโ
At query time, the GraphRetriever combines several sub-strategies:
- Keyword-based โ Match graph nodes by extracted keywords
- Vector-based โ Semantic similarity search on graph node embeddings
- Text-based โ Convert natural language to graph query language (Text2GQL) via LLM
- Document-based โ Retrieve through document-graph associations
Chunking Strategies
Document chunking is a critical step in RAG quality โ it is the shared foundation under every index. DB-GPT supports multiple chunking strategies:

| Strategy | Splitter | Description |
|---|---|---|
| Chunk by Size | RecursiveCharacterTextSplitter | Split by character count with configurable size and overlap (default: 512 / 50) |
| Chunk by Page | PageTextSplitter | Split at page boundaries (useful for PDFs) |
| Chunk by Paragraph | ParagraphTextSplitter | Split at paragraph boundaries |
| Chunk by Separator | SeparatorTextSplitter | Split at custom separator strings |
| Chunk by Markdown Header | MarkdownHeaderTextSplitter | Split at markdown heading levels; preserves the heading path used by the structural index and the heading graph |
Chunking Parametersโ

| Parameter | Description | Default |
|---|---|---|
| chunk_size | Maximum characters per chunk | 512 |
| chunk_overlap | Overlapping characters between adjacent chunks | 50 |
| topk | Number of chunks to retrieve per query | 5 |
| recall_score | Minimum relevance score threshold | 0 |
| recall_type | Recall strategy (TopK) | TopK |
| model | Embedding model to use | Depends on configuration |
Embedding Models
DB-GPT supports a wide range of embedding models for converting text into vector representations:
Local Modelsโ
| Model | Class | Description |
|---|---|---|
| HuggingFace | HuggingFaceEmbeddings | General-purpose HuggingFace models |
| BGE Series | HuggingFaceBgeEmbeddings | BAAI BGE models with instruction support (Chinese/English) |
| Instructor | HuggingFaceInstructEmbeddings | Instruction-following embedding models |
Remote API Modelsโ
| Provider | Class | Description |
|---|---|---|
| OpenAI-compatible | OpenAPIEmbeddings | Any OpenAI-compatible embedding API |
| Jina | JinaEmbeddings | Jina AI embedding service |
| Ollama | OllamaEmbeddings | Local Ollama embedding server |
| Tongyi (Aliyun) | TongyiEmbeddings | Alibaba Cloud DashScope |
| Qianfan (Baidu) | QianfanEmbeddings | Baidu Wenxin platform |
| SiliconFlow | SiliconFlowEmbeddings | SiliconFlow embedding service |
Usage
Creating a Knowledge Base (Web UI)โ
Step 1 โ Open Knowledge Managementโ
Navigate to the Knowledge section in the sidebar.

Step 2 โ Create and Configureโ
- Click Create to start a new knowledge base.
- Select the index methods to enable (Vector Store, Knowledge Graph, Full Text โ combinable).
- Choose the Embedding Model and configure chunk parameters.

Step 3 โ Upload Dataโ
Select a datasource type and upload your content. Supported types include Document (PDF, Word, Excel, CSV, etc.), URL, Text, Yuque, and Git Repo.
Step 4 โ Configure Chunkingโ
Choose a chunking strategy and set parameters:

Step 5 โ Configure Retrieval Strategy (Optional)โ
You can configure the retrieval strategy for your knowledge base. DB-GPT supports multiple retrieve modes โ Semantic, Keyword, Hybrid, and Tree โ to suit different query scenarios. Select the mode that best fits your use case in the knowledge base settings.

Step 6 โ Chat with Your Knowledgeโ
Go to Chat, click the knowledge base icon in the chat input toolbar, select your knowledge base from the dropdown, and start asking questions. The conversation runs the agentic RAG loop described above.

Programmatic Usage (Python API)โ
from dbgpt.rag import Chunk
from dbgpt_ext.rag.assembler import EmbeddingAssembler
from dbgpt_ext.rag.knowledge import KnowledgeFactory
# Extract: parse the source into raw text
knowledge = KnowledgeFactory.create(file_path="your_document.pdf")
# Transform + Load: chunk, embed, and persist into the vector index
assembler = await EmbeddingAssembler.aload_from_knowledge(
knowledge=knowledge,
index_store=your_vector_store,
embedding_model=your_embedding_model,
)
assembler.persist()
# Retrieve (chat time): the vector index answers similarity queries
retriever = assembler.as_retriever(top_k=5)
chunks = await retriever.aretrieve("What is the main topic?")
Next Steps
| Topic | Link |
|---|---|
| Indexing principles (structural / KG / code graph / vector / keyword) | Knowledge Base Indexing Principles |
| Agentic RAG conversation principles | Agentic RAG Conversation Principles |
| Knowledge Base Web UI Guide | Knowledge Base |
| RAG Concepts | RAG |
| Graph RAG Setup | Graph RAG |
| AWEL RAG Operators | AWEL |
| Source Code | GitHub |