diff --git a/llama_index/vector_stores/qdrant.py b/llama_index/vector_stores/qdrant.py index b46cb86857908..4dbb50fa9949a 100644 --- a/llama_index/vector_stores/qdrant.py +++ b/llama_index/vector_stores/qdrant.py @@ -443,6 +443,7 @@ def query( return self._hybrid_fusion_fn( self.parse_to_query_result(sparse_response[0]), self.parse_to_query_result(sparse_response[1]), + # NOTE: only for hybrid search (0 for sparse search, 1 for dense search) alpha=query.alpha or 0.5, top_k=query.similarity_top_k, ) diff --git a/llama_index/vector_stores/qdrant_utils.py b/llama_index/vector_stores/qdrant_utils.py index 3dbc8b63e76a7..20aa58ef659a5 100644 --- a/llama_index/vector_stores/qdrant_utils.py +++ b/llama_index/vector_stores/qdrant_utils.py @@ -66,6 +66,7 @@ def compute_vectors(texts: List[str]) -> Tuple[List[List[int]], List[List[float] def relative_score_fusion( dense_result: VectorStoreQueryResult, sparse_result: VectorStoreQueryResult, + # NOTE: only for hybrid search (0 for sparse search, 1 for dense search) alpha: float = 0.5, top_k: int = 2, ) -> VectorStoreQueryResult: @@ -140,7 +141,7 @@ def relative_score_fusion( for node_id in all_nodes_dict: sparse_sim = sparse_per_node.get(node_id, 0) dense_sim = dense_per_node.get(node_id, 0) - fused_sim = alpha * (sparse_sim + dense_sim) + fused_sim = (1 - alpha) * sparse_sim + alpha * dense_sim fused_similarities.append((fused_sim, all_nodes_dict[node_id])) fused_similarities.sort(key=lambda x: x[0], reverse=True)