Indexers¶
HybridIndexProtocol
¶
Bases: Protocol
Combined dense + sparse index with RRF or weighted fusion.
HybridIndex¶
HybridIndex
¶
Combined dense + sparse index with RRF fusion.
Parameters¶
dense:
A DenseIndex instance (e.g. LanceDBIndex).
sparse:
A SparseIndex instance (e.g. BM25Index).
rrf_k:
RRF smoothing constant (default 60, from the original RRF paper).
over_fetch:
Multiplier on k when querying sub-indexes. Larger pools give RRF
more candidates to promote chunks appearing in both lists.
Source code in src/verifiable_rag/indexers/hybrid.py
search
¶
search(query: str, query_embedding: list[float], k: int) -> list[RetrievedChunk]
Return up to k chunks fused from dense and sparse results via RRF.
Source code in src/verifiable_rag/indexers/hybrid.py
LanceDBIndex¶
LanceDBIndex
¶
Dense ANN index backed by LanceDB.
Parameters¶
uri:
Directory for the LanceDB database. Created on first write.
table_name:
Name of the table inside the database. Use different names to keep
multiple collections in the same URI.
metric:
Distance metric: "cosine" (default, requires normalised vectors)
or "l2".
Source code in src/verifiable_rag/indexers/lance.py
add
¶
add(chunks: list[Chunk], embeddings: list[list[float]]) -> None
Persist chunks with their embeddings. Appends if table exists.
Source code in src/verifiable_rag/indexers/lance.py
search
¶
search(query_embedding: list[float], k: int) -> list[RetrievedChunk]
Return up to k chunks nearest to query_embedding.
Source code in src/verifiable_rag/indexers/lance.py
build_index
¶
Build an HNSW ANN index. Call after bulk-loading for fast queries.
Source code in src/verifiable_rag/indexers/lance.py
clear
¶
BM25Index¶
BM25Index
¶
Sparse BM25 retrieval index backed by bm25s.
Parameters¶
tokenize:
Callable (texts: list[str]) -> list[list[str]] that converts raw
texts into token lists. Defaults to bm25s.tokenize.
method:
BM25 variant — "bm25" (Okapi, default), "bm25l", "bm25+".
Source code in src/verifiable_rag/indexers/sparse/bm25.py
add
¶
add(chunks: list[Chunk]) -> None
Append chunks to the corpus; rebuild is deferred to next search().
Lazy rebuild: the internal BM25 matrix is only recomputed on the next
search() (or save()). This keeps a bulk ingest of N PDFs O(N)
rather than O(N²) — previously every add() re-tokenised the entire
corpus.
Source code in src/verifiable_rag/indexers/sparse/bm25.py
search
¶
search(query: str, k: int) -> list[RetrievedChunk]
Return up to k chunks ranked by BM25 score for query.
Source code in src/verifiable_rag/indexers/sparse/bm25.py
clear
¶
save
¶
Persist the index and corpus to path directory.
Source code in src/verifiable_rag/indexers/sparse/bm25.py
load
classmethod
¶
load(path: str | Path) -> BM25Index
Restore a previously saved BM25Index from path directory.