mirror of
https://github.com/open-webui/open-webui
synced 2025-05-02 12:03:51 +00:00
refac: chroma
This commit is contained in:
parent
656a887db6
commit
c79b975ad0
@ -11,6 +11,8 @@ from langchain.retrievers import ContextualCompressionRetriever, EnsembleRetriev
|
|||||||
from langchain_community.retrievers import BM25Retriever
|
from langchain_community.retrievers import BM25Retriever
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
|
|
||||||
|
from open_webui.config import VECTOR_DB
|
||||||
from open_webui.retrieval.vector.connector import VECTOR_DB_CLIENT
|
from open_webui.retrieval.vector.connector import VECTOR_DB_CLIENT
|
||||||
from open_webui.utils.misc import get_last_user_message
|
from open_webui.utils.misc import get_last_user_message
|
||||||
|
|
||||||
@ -199,6 +201,11 @@ def query_collection(
|
|||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
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
|
||||||
|
return merge_and_sort_query_results(results, k=k, reverse=False)
|
||||||
|
else:
|
||||||
return merge_and_sort_query_results(results, k=k, reverse=True)
|
return merge_and_sort_query_results(results, k=k, reverse=True)
|
||||||
|
|
||||||
|
|
||||||
@ -235,6 +242,11 @@ def query_collection_with_hybrid_search(
|
|||||||
"Hybrid search failed for all collections. Using Non hybrid search as fallback."
|
"Hybrid search failed for all collections. Using Non hybrid search as fallback."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
return merge_and_sort_query_results(results, k=k, reverse=False)
|
||||||
|
else:
|
||||||
return merge_and_sort_query_results(results, k=k, reverse=True)
|
return merge_and_sort_query_results(results, k=k, reverse=True)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user