fastrag.lexical_store.base#

The LexicalStore contract: BM25 search over stored document text.

Deliberately independent of VectorStore. Lexical and dense retrieval are separate capabilities, so neither forces the other on a backend:

  • A vector database with server-side BM25 inherits both (class MilvusVectorStore(VectorStore, LexicalStore)) and one open store answers both branches of a HybridRetriever.

  • A vector database without it implements only VectorStore; BM25 then comes from a different backend implementing only LexicalStore — dense vectors in Milvus, say, and lexical ranking in PostgreSQL.

BM25Retriever depends on this contract only, never on a backend client.

Classes

LexicalStore()

Storage able to rank its documents' text against a query with BM25.

class fastrag.lexical_store.base.LexicalStore[source]#

Bases: ABC

Storage able to rank its documents’ text against a query with BM25.

Opened and closed by the caller, like a vector store — a retriever holds an already-open one and never manages its lifecycle.

Return at most k BM25 matches for query, best first.

Stamps the same reserved metadata keys as search(): score (the backend’s own BM25 score, never comparable across backends) and rank (0-based position in the returned list).

Parameters:
  • query (str) – Natural-language query text, analyzed server-side.

  • k (int) – Maximum number of documents to return.

  • filter (str | None) – Backend-native filter expression, applied server-side. None searches unfiltered.

Return type:

list[Document]