MCPcopy
hub / github.com/daveebbelaar/ai-cookbook / hybrid_candidates

Function hybrid_candidates

knowledge/hybrid-retrieval/utils/fusion.py:21–29  ·  view source on GitHub ↗
(
    query: str,
    bm25: BM25Retriever,
    dense: DenseRetriever,
    candidate_k: int = 50,
)

Source from the content-addressed store, hash-verified

19
20
21def hybrid_candidates(
22 query: str,
23 bm25: BM25Retriever,
24 dense: DenseRetriever,
25 candidate_k: int = 50,
26) -> list[tuple[str, float]]:
27 bm25_ids = [doc_id for doc_id, _ in bm25.search(query, k=candidate_k)]
28 dense_ids = [doc_id for doc_id, _ in dense.search(query, k=candidate_k)]
29 return reciprocal_rank_fusion([bm25_ids, dense_ids])[:candidate_k]

Callers 4

hybrid_topkFunction · 0.90
search_rerankedFunction · 0.90
5-rerank.pyFile · 0.90
search_rerankedFunction · 0.90

Calls 2

reciprocal_rank_fusionFunction · 0.70
searchMethod · 0.45

Tested by

no test coverage detected