fastrag.lexical_store#

fastrag.lexical_store — the read contract for BM25 relevance search.

Re-exports LexicalStore. It is a capability, not a storage family: a vector store that can also rank text (MilvusVectorStore, OpenSearchVectorStore) implements it alongside VectorStore, while a vector store that cannot (ChromaVectorStore) simply does not, and lexical retrieval is served from a separate database instead.

class fastrag.lexical_store.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]

Modules

base

The LexicalStore contract: BM25 search over stored document text.