BM25 ranks documents for keyword-based retrieval using term frequency, inverse document frequency, and document length. It appears as a local retrieval option inside agentic RAG workflows. section 14.2 section 14.4
Used here alongside adjacent retrieval and agent patterns:
- Pairs with vector search in hybrid retrieval. section 14.4
- Feeds CodeAgent tool choice in agentic RAG. section 14.2
- Contrasts with semantic search over embeddings. section 14.2
Search tool over local documents
A BM25 search tool wraps a local document list, invokes BM25Retriever.from_documents(docs, k=3), and returns the retrieved document text for a query. section 14.2
Hybrid local search
A hybrid tool combines BM25 keyword retrieval with LanceDB vector search, then lets CodeAgent choose the local search strategy for a query. section 14.2 section 14.4
Figure 14.3 The logical schema of a basic agentic RAG system
Shows the basic agentic RAG schema where retrieval happens before generation and can fall back to web search if local results are weak. section 14.2




