liveBook · Manning

BM25

As explained in Domain-Specific Small Language Models

A lexical information-retrieval ranking algorithm that scores documents using term frequency, inverse document frequency, and document length.

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:

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

How Domain-Specific Small Language Models covers it

How deep it goes
Defines BM25 at a ranking-formula level and stops short of derivation or implementation details.
Examples
Uses local document search, a Smart Home technologies query, and a hybrid local LanceDB search example.
What it assumes
Assumes retrieval concepts and document chunking, while introducing BM25 as a named keyword-ranking method.
What you can do after
Apply it in retrieval tools to rank local documents by keyword relevance.
How it connects
Links to agentic RAG, semantic search, hybrid search, CodeAgent, and EnsembleRetriever.

Also explained in

Compare how 5 books explain BM25 →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.