Add BM25 retrieval to DB-GPT with Elasticsearch

Overview
RAG
June 20, 2026Updated June 28, 2026RAGDB-GPT BM25 RAG

Use Elasticsearch as DB-GPT full-text RAG storage so exact terms, identifiers, and keyword-heavy questions are retrieved alongside semantic workflows.

DB-GPTBM25ElasticsearchHybrid search

What you will build

This guide configures DB-GPT to use Elasticsearch as a full-text retrieval backend. In practice, that means your RAG system can search by exact keywords and BM25 ranking instead of relying only on vector similarity.

BM25 is not old-fashioned. It is the precision layer for questions that include exact product names, error messages, API fields, ticket IDs, log fragments, file paths, and domain-specific vocabulary.

Workflow

DB-GPT BM25 setup

  1. 1

    Install full-text storage

    Add the Elasticsearch storage extra to DB-GPT.

    Why: The retriever needs the full-text backend installed.

  2. 2

    Run Elasticsearch

    Start a reachable Elasticsearch service.

    Why: BM25 scoring happens in the search engine.

  3. 3

    Configure DB-GPT

    Point full-text RAG storage at the Elasticsearch host and port.

    Why: The app must route retrieval to the correct backend.

  4. 4

    Index documents

    Parse documents into searchable chunks.

    Why: BM25 quality depends on chunk boundaries and analyzers.

  5. 5

    Ask exact questions

    Test names, IDs, quoted phrases, and errors.

    Why: These are the cases BM25 should win.

  6. 6

    Blend with vectors

    Use BM25 beside semantic search when users ask mixed questions.

    Why: Hybrid retrieval gives precision plus recall.

Setup
4

Before you start

  • Python 3.10+ with uv
  • A local or managed Elasticsearch service
  • DB-GPT source checkout
  • Documents with identifiers, names, logs, or exact terms

Step 1 - Install the Elasticsearch storage extra

From a DB-GPT checkout:

uv sync --all-packages --frozen \
  --extra "base" \
  --extra "proxy_openai" \
  --extra "rag" \
  --extra "storage_elasticsearch" \
  --extra "dbgpts"

Keep model configuration separate from storage configuration. You should be able to change one without surprising the other.

Step 2 - Prepare Elasticsearch

For local development, run Elasticsearch however your team normally does. Capture:

SettingExample
host127.0.0.1
port9200
index policyone index per knowledge base or environment
authrequired outside local development

For production, configure authentication, TLS, backups, and retention before indexing private content.

Step 3 - Configure DB-GPT full-text storage

Create or update configs/dbgpt-bm25-rag.toml:

[rag.storage]

[rag.storage.full_text]
type = "ElasticSearch"
uri = "127.0.0.1"
port = "9200"

If your Elasticsearch cluster requires credentials, keep them out of committed config and inject them through your deployment environment.

Step 4 - Start DB-GPT with the BM25 config

uv run python packages/dbgpt-app/src/dbgpt_app/dbgpt_server.py \
  --config configs/dbgpt-bm25-rag.toml

Index a small document set first. A good starter corpus includes:

  • an API reference page;
  • a troubleshooting guide with exact error strings;
  • a changelog;
  • a README with commands and file paths.

Step 5 - Evaluate keyword retrieval

Create questions that vectors often mishandle:

Question typeExample
exact error"What causes ERR_CONTEXT_LENGTH_EXCEEDED?"
field lookup"Where is KNOWLEDGE_GRAPH_CHUNK_SEARCH_TOP_SIZE described?"
file path"What does configs/dbgpt-bm25-rag.toml configure?"
named feature"How do I enable BM25 RAG?"

For each question, inspect the retrieved chunks before judging the final answer. Retrieval quality is the foundation; generation is only the last mile.

Step 6 - Add hybrid retrieval rules

Use BM25 and vector search together when the question has both exact and conceptual parts.

Example routing:

If the query contains exact IDs, errors, code symbols, or quoted strings:
  run BM25 first
If the query asks for concepts, summaries, or broad similarity:
  run vector search first
If both are true:
  run both, deduplicate chunks, and rank by evidence coverage

The best RAG systems make retrieval strategy explicit. They do not pretend every question is a vector question.

Step 7 - Production checklist

Before shipping:

  • tune analyzers for your language and domain;
  • preserve source document IDs in every chunk;
  • log matched terms and scores;
  • add out-of-scope behavior;
  • cap retrieved context;
  • evaluate exact-match questions after every chunking change.

BM25 gives you a precision layer. Governance and answer discipline still belong to the application.

Tutorial
Guide

Answer Engine Summary

Use Elasticsearch as DB-GPT full-text RAG storage so exact terms, identifiers, and keyword-heavy questions are retrieved alongside semantic workflows. Use this tutorial to turn DB-GPT BM25 Elasticsearch RAG into a buildable workflow with prerequisites, source citations, implementation examples, review boundaries, and proof artifacts.

For AI search, the extractable answer is direct: DB-GPT BM25 Elasticsearch RAG should be implemented as a bounded workflow with clear setup, source-grounded behavior, human review for risky actions, and a verification artifact before it is reused or scaled. The supporting keywords are DB-GPT, BM25, Elasticsearch, Hybrid search, RAG.

Source-Backed Guidance

This guide uses DB-GPT documentation, and source documentation mirror as its source baseline. Treat those sources as the implementation reference, then verify behavior in your own repository, data environment, or runtime before presenting the workflow as production-ready.

SEO elementRecommendation
Primary queryDB-GPT BM25 Elasticsearch RAG
Search intentimplementation guide
AudienceRAG engineers adding exact-match retrieval to DB-GPT with Elasticsearch.
Citation angleExplain the build path, cite the source behavior, and show the verification artifact
Related internal pathsUse adjacent tutorials with matching tags.

Implementation Examples and Checks

ExampleHow to use itProof to capture
First setup passStart with Python 3.10+ with uv.Command output, config diff, or local route evidence showing the environment is ready.
Controlled implementationUse a local or managed Elasticsearch service for one narrow, reviewable case.A small artifact, report, test, retrieval result, or code diff that a reviewer can inspect.
Source-grounded reviewCompare the result against DB-GPT documentation.A reference link plus notes on what changed from the source example.
Expansion decisionUse DB-GPT source checkout as the owner, approval input, or readiness check for the next scope.A written pass/fail decision with owner, limitation, and next action.

FAQ

FAQ

FAQ for DB-GPT BM25 Elasticsearch RAG

What does this tutorial help me build?

It helps you build or evaluate DB-GPT BM25 Elasticsearch RAG as a bounded workflow with setup steps, implementation examples, source citations, and verification evidence instead of a loose prompt or concept note.

Which keywords should this page target?

Target DB-GPT BM25 Elasticsearch RAG as the primary phrase, then support it with DB-GPT, BM25, Elasticsearch, Hybrid search, RAG. Use those phrases in natural headings, examples, metadata, and related links rather than repeating them mechanically.

How should I validate the implementation?

Run the smallest command, route check, retrieval test, or code review that proves the workflow works in your environment. Capture the output and keep it next to the source references.

What should stay human-reviewed?

Keep data access, customer-facing output, regulated decisions, production code changes, financial actions, and destructive operations behind human review until logs, approvals, and recovery paths are proven.

How often should I refresh this tutorial?

Refresh it when the linked source docs, SDK behavior, model interfaces, or deployment target changes. AI-agent and RAG tutorials should be rechecked at least quarterly because platform behavior moves quickly.

References
2

References

The DB-GPT BM25 docs provide the Elasticsearch storage extra, full-text config, and startup command. This article expands that into a practical guide for exact-match RAG and hybrid retrieval.

Stefan Creadore · @Eldergenix - generated and hand-seeded tutorials for governed agent systems