Revert the ordering change with chromadb, not necessary with reranker results

This commit is contained in:
Marko Henning 2025-03-19 17:04:45 +01:00
parent 5ab789e83e
commit 5f48af5b91

View File

@ -146,12 +146,7 @@ def query_doc_with_hybrid_search(
# retrieve only min(k, k_reranker) items, sort and cut by distance if k < k_reranker
if k < k_reranker:
if VECTOR_DB == "chroma":
# Chroma uses unconventional cosine similarity, so we don't need to reverse the results
# https://docs.trychroma.com/docs/collections/configure#configuring-chroma-collections
sorted_items = sorted(zip(distances, metadatas, documents), key=lambda x: x[0], reverse=False)
else:
sorted_items = sorted(zip(distances, metadatas, documents), key=lambda x: x[0], reverse=True)
sorted_items = sorted(zip(distances, metadatas, documents), key=lambda x: x[0], reverse=True)
sorted_items = sorted_items[:k]
distances, documents, metadatas = map(list, zip(*sorted_items))
result = {