Skip to content

Commit d6b8be6

Browse files
liugddxhinthornw
authored andcommitted
community[patch]: Fix the bug that Chroma does not specify embedding_function (#19277)
- **Issue:** close #18291 - @baskaryan, @eyurtsev PTAL
1 parent 9cdc2dc commit d6b8be6

File tree

1 file changed

+6
-2
lines changed
  • libs/community/langchain_community/vectorstores

1 file changed

+6
-2
lines changed

libs/community/langchain_community/vectorstores/chroma.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import chromadb.config
2929
from chromadb.api.types import ID, OneOrMany, Where, WhereDocument
3030

31+
3132
logger = logging.getLogger()
3233
DEFAULT_K = 4 # Number of Documents to return.
3334

@@ -80,6 +81,7 @@ def __init__(
8081
try:
8182
import chromadb
8283
import chromadb.config
84+
from chromadb.utils import embedding_functions
8385
except ImportError:
8486
raise ImportError(
8587
"Could not import chromadb python package. "
@@ -122,10 +124,12 @@ def __init__(
122124
_client_settings.persist_directory or persist_directory
123125
)
124126

125-
self._embedding_function = embedding_function
127+
self._embedding_function = (
128+
embedding_function or embedding_functions.DefaultEmbeddingFunction()
129+
)
126130
self._collection = self._client.get_or_create_collection(
127131
name=collection_name,
128-
embedding_function=None,
132+
embedding_function=self._embedding_function,
129133
metadata=collection_metadata,
130134
)
131135
self.override_relevance_score_fn = relevance_score_fn

0 commit comments

Comments
 (0)