hybrid
hybrid
¶
Hybrid memory backend — Reciprocal Rank Fusion of two retrievers.
Classes¶
HybridMemory
¶
HybridMemory(*, sparse: MemoryBackend, dense: MemoryBackend, k: int = 60, sparse_weight: float = 1.0, dense_weight: float = 1.0)
Bases: MemoryBackend
Fuses a sparse and a dense retriever via RRF.
Stores documents in both sub-backends and merges retrieval results using Reciprocal Rank Fusion.
Source code in src/openjarvis/tools/storage/hybrid.py
Functions¶
store
¶
Store in both sub-backends with the same doc id.
Source code in src/openjarvis/tools/storage/hybrid.py
retrieve
¶
retrieve(query: str, *, top_k: int = 5, **kwargs: Any) -> List[RetrievalResult]
Retrieve from both backends and fuse with RRF.
Source code in src/openjarvis/tools/storage/hybrid.py
delete
¶
Delete from both sub-backends.
Source code in src/openjarvis/tools/storage/hybrid.py
Functions¶
reciprocal_rank_fusion
¶
reciprocal_rank_fusion(ranked_lists: List[List[RetrievalResult]], *, k: int = 60, weights: Optional[List[float]] = None) -> List[RetrievalResult]
Fuse multiple ranked result lists using RRF.
RRF_score(d) = sum(weight_i / (k + rank_i(d)))
| PARAMETER | DESCRIPTION |
|---|---|
ranked_lists
|
Each inner list is a ranked sequence of results (best first).
TYPE:
|
k
|
RRF constant (default 60).
TYPE:
|
weights
|
Per-list weight (defaults to equal weighting).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Merged list sorted by fused score, descending.
|
|