fastrag.retrieval.reranking_retriever#
RerankingRetriever: narrowing any retrieval strategy with a reranker.
Classes
|
Over-fetch with a retriever, then narrow on relevance. |
- class fastrag.retrieval.reranking_retriever.RerankingRetriever(*, reranker, retriever=None, vector_store=None, embedder=None, candidate_k=None)[source]#
Bases:
RetrieverOver-fetch with a retriever, then narrow on relevance.
Composition, not configuration: a plain
VectorRetrieverover-fetcheskcandidates on cosine similarity, andrerankerthen narrows them totop_kon relevance — a cross-encoder reading query and document together, which similarity search alone cannot do. The returnedscore/rankare the reranker’s own, not the vector search’s — seererank().async with MilvusVectorStore(url=MILVUS_URI) as vector_store: retriever = RerankingRetriever( vector_store=vector_store, embedder=Model2VecEmbedder(model=EMBEDDING_MODEL), reranker=CohereReranker( model="rerank-v3.5", base_url=RERANK_BASE_URL, api_key=api_key ), ) documents = await retriever.retrieve("What is AgrospAI?", k=200, top_k=5)
- Parameters:
vector_store (VectorStore | None) – The collection to over-fetch from. Opened by the caller; this retriever neither opens nor closes it.
embedder (Embedder | None) – Embeds the query text — see
VectorRetriever.retriever (Retriever | None) – Any SDK retriever, including a hybrid retriever. Mutually exclusive with the legacy vector_store/embedder pair.
candidate_k (int | None) – Optional over-fetch count used even when the caller requests only the final k results.
reranker (Reranker) – Scores the over-fetched documents against the query.