MCPcopy
hub / github.com/langchain-ai/langchain / Chroma

Class Chroma

libs/partners/chroma/langchain_chroma/vectorstores.py:132–941  ·  view source on GitHub ↗

`ChromaDB` vector store. To use, you should have the ``chromadb`` python package installed. Example: .. code-block:: python from langchain_chroma import Chroma from langchain_openai import OpenAIEmbeddings embeddings = OpenAIEmbeddi

Source from the content-addressed store, hash-verified

130
131
132class Chroma(VectorStore):
133 """`ChromaDB` vector store.
134
135 To use, you should have the ``chromadb`` python package installed.
136
137 Example:
138 .. code-block:: python
139
140 from langchain_chroma import Chroma
141 from langchain_openai import OpenAIEmbeddings
142
143 embeddings = OpenAIEmbeddings()
144 vectorstore = Chroma("langchain_store", embeddings)
145 """
146
147 _LANGCHAIN_DEFAULT_COLLECTION_NAME = "langchain"
148
149 def __init__(
150 self,
151 collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
152 embedding_function: Optional[Embeddings] = None,
153 persist_directory: Optional[str] = None,
154 client_settings: Optional[chromadb.config.Settings] = None,
155 collection_metadata: Optional[Dict] = None,
156 client: Optional[chromadb.ClientAPI] = None,
157 relevance_score_fn: Optional[Callable[[float], float]] = None,
158 create_collection_if_not_exists: Optional[bool] = True,
159 ) -> None:
160 """Initialize with a Chroma client.
161
162 Args:
163 collection_name: Name of the collection to create.
164 embedding_function: Embedding class object. Used to embed texts.
165 persist_directory: Directory to persist the collection.
166 client_settings: Chroma client settings
167 collection_metadata: Collection configurations.
168 client: Chroma client. Documentation:
169 https://docs.trychroma.com/reference/js-client#class:-chromaclient
170 relevance_score_fn: Function to calculate relevance score from distance.
171 Used only in `similarity_search_with_relevance_scores`
172 create_collection_if_not_exists: Whether to create collection
173 if it doesn't exist. Defaults to True.
174 """
175 if client is not None:
176 self._client_settings = client_settings
177 self._client = client
178 self._persist_directory = persist_directory
179 else:
180 if client_settings:
181 # If client_settings is provided with persist_directory specified,
182 # then it is "in-memory and persisting to disk" mode.
183 client_settings.persist_directory = (
184 persist_directory or client_settings.persist_directory
185 )
186
187 _client_settings = client_settings
188 elif persist_directory:
189 _client_settings = chromadb.config.Settings(is_persistent=True)

Callers 15

ingest.pyFile · 0.90
chain.pyFile · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90
get_vectorstoreFunction · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
ingest.pyFile · 0.90

Calls

no outgoing calls