Skip to content

hybrid

diapason.tools.storage.hybrid

Hybrid memory backend — Reciprocal Rank Fusion of two retrievers.

HybridMemory

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.

clear()

Clear both sub-backends.

delete(doc_id)

Delete from both sub-backends.

retrieve(query, *, top_k=5, **kwargs)

Retrieve from both backends and fuse with RRF.

store(content, *, source='', metadata=None)

Store in both sub-backends with the same doc id.

reciprocal_rank_fusion(ranked_lists, *, k=60, weights=None)

Fuse multiple ranked result lists using RRF.

RRF_score(d) = sum(weight_i / (k + rank_i(d)))

Parameters

ranked_lists: Each inner list is a ranked sequence of results (best first). k: RRF constant (default 60). weights: Per-list weight (defaults to equal weighting).

Returns

Merged list sorted by fused score, descending.