langchain-chroma
¶
LangChain integration for Chroma vector database.
Classes¶
Chroma ¶
Chroma( collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME, embedding_function: Embeddings | None = None, persist_directory: str | None = None, host: str | None = None, port: int | None = None, headers: dict[str, str] | None = None, chroma_cloud_api_key: str | None = None, tenant: str | None = None, database: str | None = None, client_settings: Settings | None = None, collection_metadata: dict | None = None, collection_configuration: ( CreateCollectionConfiguration | None ) = None, client: ClientAPI | None = None, relevance_score_fn: ( Callable[[float], float] | None ) = None, create_collection_if_not_exists: bool | None = True, *, ssl: bool = False )
Bases: VectorStore
Chroma vector store integration.
Key init args — indexing params: collection_name: str Name of the collection. embedding_function: Embeddings Embedding function to use.
Key init args — client params: client: Client | None Chroma client to use. client_settings: chromadb.config.Settings | None Chroma client settings. persist_directory: str | None Directory to persist the collection. host: str | None Hostname of a deployed Chroma server. port: int | None Connection port for a deployed Chroma server. Default is 8000. ssl: bool | None Whether to establish an SSL connection with a deployed Chroma server. Default is False. headers: dict[str, str] | None HTTP headers to send to a deployed Chroma server. chroma_cloud_api_key: str | None Chroma Cloud API key. tenant: str | None Tenant ID. Required for Chroma Cloud connections. Default is 'default_tenant' for local Chroma servers. database: str | None Database name. Required for Chroma Cloud connections. Default is 'default_database'.
Instantiate
Add Documents
from langchain_core.documents import Document document_1 = Document(page_content="foo", metadata={"baz": "bar"}) document_2 = Document(page_content="thud", metadata={"bar": "baz"}) document_3 = Document(page_content="i will be deleted :(") documents = [document_1, document_2, document_3] ids = ["1", "2", "3"] vector_store.add_documents(documents=documents, ids=ids)
Update Documents
Search
Search with filter
Search with score
Async
# add documents # await vector_store.aadd_documents(documents=documents, ids=ids) # delete documents # await vector_store.adelete(ids=["3"]) # search # results = vector_store.asimilarity_search(query="thud",k=1) # search with score results = await vector_store.asimilarity_search_with_score(query="qux", k=1) for doc, score in results: print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
Use as Retriever
Initialize with a Chroma client.
PARAMETER | DESCRIPTION |
---|---|
| Name of the collection to create. TYPE: |
| Embedding class object. Used to embed texts. TYPE: |
| Directory to persist the collection. TYPE: |
| Hostname of a deployed Chroma server. TYPE: |
| Connection port for a deployed Chroma server. Default is 8000. TYPE: |
| Whether to establish an SSL connection with a deployed Chroma server. Default is False. TYPE: |
| HTTP headers to send to a deployed Chroma server. |
| Chroma Cloud API key. TYPE: |
| Tenant ID. Required for Chroma Cloud connections. Default is 'default_tenant' for local Chroma servers. TYPE: |
| Database name. Required for Chroma Cloud connections. Default is 'default_database'. TYPE: |
| Chroma client settings TYPE: |
| Collection configurations. TYPE: |
| Index configuration for the collection. TYPE: |
| Chroma client. Documentation: https://docs.trychroma.com/reference/python/client TYPE: |
| Function to calculate relevance score from distance. Used only in |
| Whether to create collection if it doesn't exist. Defaults to TYPE: |
METHOD | DESCRIPTION |
---|---|
aget_by_ids | Async get documents by their IDs. |
adelete | Async delete by vector ID or other criteria. |
aadd_texts | Async run more texts through the embeddings and add to the vectorstore. |
add_documents | Add or update documents in the vectorstore. |
aadd_documents | Async run more documents through the embeddings and add to the vectorstore. |
search | Return docs most similar to query using a specified search type. |
asearch | Async return docs most similar to query using a specified search type. |
asimilarity_search_with_score | Async run similarity search with distance. |
similarity_search_with_relevance_scores | Return docs and relevance scores in the range [0, 1]. |
asimilarity_search_with_relevance_scores | Async return docs and relevance scores in the range [0, 1]. |
asimilarity_search | Async return docs most similar to query. |
asimilarity_search_by_vector | Async return docs most similar to embedding vector. |
amax_marginal_relevance_search | Async return docs selected using the maximal marginal relevance. |
amax_marginal_relevance_search_by_vector | Async return docs selected using the maximal marginal relevance. |
afrom_documents | Async return VectorStore initialized from documents and embeddings. |
afrom_texts | Async return VectorStore initialized from texts and embeddings. |
as_retriever | Return VectorStoreRetriever initialized from this VectorStore. |
encode_image | Get base64 string from image URI. |
fork | Fork this vector store. |
add_images | Run more images through the embeddings and add to the vectorstore. |
add_texts | Run more texts through the embeddings and add to the vectorstore. |
similarity_search | Run similarity search with Chroma. |
similarity_search_by_vector | Return docs most similar to embedding vector. |
similarity_search_by_vector_with_relevance_scores | Return docs most similar to embedding vector and similarity score. |
similarity_search_with_score | Run similarity search with Chroma with distance. |
similarity_search_with_vectors | Run similarity search with Chroma with vectors. |
similarity_search_by_image | Search for similar images based on the given image URI. |
similarity_search_by_image_with_relevance_score | Search for similar images based on the given image URI. |
max_marginal_relevance_search_by_vector | Return docs selected using the maximal marginal relevance. |
max_marginal_relevance_search | Return docs selected using the maximal marginal relevance. |
delete_collection | Delete the collection. |
reset_collection | Resets the collection. |
get | Gets the collection. |
get_by_ids | Get documents by their IDs. |
update_document | Update a document in the collection. |
update_documents | Update a document in the collection. |
from_texts | Create a Chroma vectorstore from a raw documents. |
from_documents | Create a Chroma vectorstore from a list of documents. |
delete | Delete by vector IDs. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
Attributes¶
Functions¶
aget_by_ids async
¶
Async get documents by their IDs.
The returned documents are expected to have the ID field set to the ID of the document in the vector store.
Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.
Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.
This method should NOT raise exceptions if no documents are found for some IDs.
PARAMETER | DESCRIPTION |
---|---|
| List of ids to retrieve. |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents. |
Added in version 0.2.11
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
adelete async
¶
Async delete by vector ID or other criteria.
PARAMETER | DESCRIPTION |
---|---|
| List of ids to delete. If |
| Other keyword arguments that subclasses might use. TYPE: |
RETURNS | DESCRIPTION |
---|---|
bool | None | True if deletion is successful, False otherwise, None if not implemented. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
aadd_texts async
¶
aadd_texts( texts: Iterable[str], metadatas: list[dict] | None = None, *, ids: list[str] | None = None, **kwargs: Any ) -> list[str]
Async run more texts through the embeddings and add to the vectorstore.
PARAMETER | DESCRIPTION |
---|---|
| Iterable of strings to add to the vectorstore. |
| Optional list of metadatas associated with the texts. Default is None. |
| Optional list |
| vectorstore specific parameters. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[str] | List of ids from adding the texts into the vectorstore. |
RAISES | DESCRIPTION |
---|---|
ValueError | If the number of metadatas does not match the number of texts. |
ValueError | If the number of ids does not match the number of texts. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
add_documents ¶
Add or update documents in the vectorstore.
PARAMETER | DESCRIPTION |
---|---|
| Documents to add to the vectorstore. TYPE: |
| Additional keyword arguments. if kwargs contains ids and documents contain ids, the ids in the kwargs will receive precedence. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[str] | List of IDs of the added texts. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
aadd_documents async
¶
Async run more documents through the embeddings and add to the vectorstore.
PARAMETER | DESCRIPTION |
---|---|
| Documents to add to the vectorstore. TYPE: |
| Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[str] | List of IDs of the added texts. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
search ¶
Return docs most similar to query using a specified search type.
PARAMETER | DESCRIPTION |
---|---|
| Input text TYPE: |
| Type of search to perform. Can be "similarity", "mmr", or "similarity_score_threshold". TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents most similar to the query. |
RAISES | DESCRIPTION |
---|---|
ValueError | If search_type is not one of "similarity", "mmr", or "similarity_score_threshold". |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
asearch async
¶
Async return docs most similar to query using a specified search type.
PARAMETER | DESCRIPTION |
---|---|
| Input text. TYPE: |
| Type of search to perform. Can be "similarity", "mmr", or "similarity_score_threshold". TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents most similar to the query. |
RAISES | DESCRIPTION |
---|---|
ValueError | If search_type is not one of "similarity", "mmr", or "similarity_score_threshold". |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
asimilarity_search_with_score async
¶
Async run similarity search with distance.
PARAMETER | DESCRIPTION |
---|---|
| Arguments to pass to the search method. TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, float]] | List of Tuples of (doc, similarity_score). |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
similarity_search_with_relevance_scores ¶
similarity_search_with_relevance_scores( query: str, k: int = 4, **kwargs: Any ) -> list[tuple[Document, float]]
Return docs and relevance scores in the range [0, 1].
0 is dissimilar, 1 is most similar.
PARAMETER | DESCRIPTION |
---|---|
| Input text. TYPE: |
| Number of Documents to return. Defaults to 4. TYPE: |
| kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, float]] | List of Tuples of (doc, similarity_score). |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
asimilarity_search_with_relevance_scores async
¶
asimilarity_search_with_relevance_scores( query: str, k: int = 4, **kwargs: Any ) -> list[tuple[Document, float]]
Async return docs and relevance scores in the range [0, 1].
0 is dissimilar, 1 is most similar.
PARAMETER | DESCRIPTION |
---|---|
| Input text. TYPE: |
| Number of Documents to return. Defaults to 4. TYPE: |
| kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, float]] | List of Tuples of (doc, similarity_score) |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
asimilarity_search async
¶
Async return docs most similar to query.
PARAMETER | DESCRIPTION |
---|---|
| Input text. TYPE: |
| Number of Documents to return. Defaults to 4. TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents most similar to the query. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
asimilarity_search_by_vector async
¶
Async return docs most similar to embedding vector.
PARAMETER | DESCRIPTION |
---|---|
| Embedding to look up documents similar to. |
| Number of Documents to return. Defaults to 4. TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents most similar to the query vector. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
amax_marginal_relevance_search async
¶
amax_marginal_relevance_search( query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any ) -> list[Document]
Async return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
PARAMETER | DESCRIPTION |
---|---|
| Text to look up documents similar to. TYPE: |
| Number of Documents to return. Defaults to 4. TYPE: |
| Number of Documents to fetch to pass to MMR algorithm. Default is 20. TYPE: |
| Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents selected by maximal marginal relevance. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
amax_marginal_relevance_search_by_vector async
¶
amax_marginal_relevance_search_by_vector( embedding: list[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any ) -> list[Document]
Async return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
PARAMETER | DESCRIPTION |
---|---|
| Embedding to look up documents similar to. |
| Number of Documents to return. Defaults to 4. TYPE: |
| Number of Documents to fetch to pass to MMR algorithm. Default is 20. TYPE: |
| Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. TYPE: |
| Arguments to pass to the search method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents selected by maximal marginal relevance. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
afrom_documents async
classmethod
¶
Async return VectorStore initialized from documents and embeddings.
PARAMETER | DESCRIPTION |
---|---|
| List of Documents to add to the vectorstore. TYPE: |
| Embedding function to use. TYPE: |
| Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | VectorStore initialized from documents and embeddings. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
afrom_texts async
classmethod
¶
afrom_texts( texts: list[str], embedding: Embeddings, metadatas: list[dict] | None = None, *, ids: list[str] | None = None, **kwargs: Any ) -> Self
Async return VectorStore initialized from texts and embeddings.
PARAMETER | DESCRIPTION |
---|---|
| Texts to add to the vectorstore. |
| Embedding function to use. TYPE: |
| Optional list of metadatas associated with the texts. Default is None. |
| Optional list of IDs associated with the texts. |
| Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Self | VectorStore initialized from texts and embeddings. |
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
as_retriever ¶
Return VectorStoreRetriever initialized from this VectorStore.
PARAMETER | DESCRIPTION |
---|---|
| Keyword arguments to pass to the search function. Can include: search_type: Defines the type of search that the Retriever should perform. Can be "similarity" (default), "mmr", or "similarity_score_threshold". search_kwargs: Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata TYPE: |
RETURNS | DESCRIPTION |
---|---|
VectorStoreRetriever | Retriever class for VectorStore. |
Examples:
# Retrieve more documents with higher diversity # Useful if your dataset has many similar documents docsearch.as_retriever( search_type="mmr", search_kwargs={"k": 6, "lambda_mult": 0.25} ) # Fetch more documents for the MMR algorithm to consider # But only return the top 5 docsearch.as_retriever(search_type="mmr", search_kwargs={"k": 5, "fetch_k": 50}) # Only retrieve documents that have a relevance score # Above a certain threshold docsearch.as_retriever( search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.8}, ) # Only get the single most similar document from the dataset docsearch.as_retriever(search_kwargs={"k": 1}) # Use a filter to only retrieve documents from a specific paper docsearch.as_retriever( search_kwargs={"filter": {"paper_title": "GPT-4 Technical Report"}} )
Source code in .venv/lib/python3.13/site-packages/langchain_core/vectorstores/base.py
__ensure_collection ¶
Ensure that the collection exists or create it.
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
__query_collection ¶
__query_collection( query_texts: list[str] | None = None, query_embeddings: list[list[float]] | None = None, n_results: int = 4, where: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[Document] | QueryResult
Query the chroma collection.
PARAMETER | DESCRIPTION |
---|---|
| List of query texts. |
| List of query embeddings. |
| Number of results to return. Defaults to 4. TYPE: |
| dict used to filter results by metadata. E.g. {"color" : "red"}. |
| dict used to filter by the document contents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | QueryResult | List of |
list[Document] | QueryResult | query_embeddings or query_texts. |
See more: https://docs.trychroma.com/reference/py-collection#query
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
encode_image staticmethod
¶
Get base64 string from image URI.
fork ¶
Fork this vector store.
PARAMETER | DESCRIPTION |
---|---|
| New name for the forked store. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Chroma | A new Chroma store forked from this vector store. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
add_images ¶
add_images( uris: list[str], metadatas: list[dict] | None = None, ids: list[str] | None = None, ) -> list[str]
Run more images through the embeddings and add to the vectorstore.
PARAMETER | DESCRIPTION |
---|---|
| File path to the image. |
| Optional list of metadatas. When querying, you can filter on this metadata. |
| Optional list of IDs. (Items without IDs will be assigned UUIDs) |
RETURNS | DESCRIPTION |
---|---|
list[str] | List of IDs of the added images. |
RAISES | DESCRIPTION |
---|---|
ValueError | When metadata is incorrect. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
add_texts ¶
add_texts( texts: Iterable[str], metadatas: list[dict] | None = None, ids: list[str] | None = None, **kwargs: Any ) -> list[str]
Run more texts through the embeddings and add to the vectorstore.
PARAMETER | DESCRIPTION |
---|---|
| Texts to add to the vectorstore. |
| Optional list of metadatas. When querying, you can filter on this metadata. |
| Optional list of IDs. (Items without IDs will be assigned UUIDs) |
| Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[str] | List of IDs of the added texts. |
RAISES | DESCRIPTION |
---|---|
ValueError | When metadata is incorrect. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
|
similarity_search ¶
similarity_search( query: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, **kwargs: Any ) -> list[Document]
Run similarity search with Chroma.
PARAMETER | DESCRIPTION |
---|---|
| Query text to search for. TYPE: |
| Number of results to return. Defaults to 4. TYPE: |
| Filter by metadata. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of documents most similar to the query text. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
similarity_search_by_vector ¶
similarity_search_by_vector( embedding: list[float], k: int = DEFAULT_K, filter: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[Document]
Return docs most similar to embedding vector.
PARAMETER | DESCRIPTION |
---|---|
| Embedding to look up documents similar to. |
| Number of Documents to return. Defaults to 4. TYPE: |
| Filter by metadata. |
| dict used to filter by the document contents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents most similar to the query vector. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
similarity_search_by_vector_with_relevance_scores ¶
similarity_search_by_vector_with_relevance_scores( embedding: list[float], k: int = DEFAULT_K, filter: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[tuple[Document, float]]
Return docs most similar to embedding vector and similarity score.
PARAMETER | DESCRIPTION |
---|---|
| Embedding to look up documents similar to. TYPE: |
| Number of Documents to return. Defaults to 4. TYPE: |
| Filter by metadata. |
| dict used to filter by the documents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, float]] | List of documents most similar to the query text and relevance score |
list[tuple[Document, float]] | in float for each. Lower score represents more similarity. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
similarity_search_with_score ¶
similarity_search_with_score( query: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[tuple[Document, float]]
Run similarity search with Chroma with distance.
PARAMETER | DESCRIPTION |
---|---|
| Query text to search for. TYPE: |
| Number of results to return. Defaults to 4. TYPE: |
| Filter by metadata. |
| dict used to filter by document contents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, float]] | List of documents most similar to the query text and |
list[tuple[Document, float]] | distance in float for each. Lower score represents more similarity. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
similarity_search_with_vectors ¶
similarity_search_with_vectors( query: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[tuple[Document, ndarray]]
Run similarity search with Chroma with vectors.
PARAMETER | DESCRIPTION |
---|---|
| Query text to search for. TYPE: |
| Number of results to return. Defaults to 4. TYPE: |
| Filter by metadata. |
| dict used to filter by the document contents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, ndarray]] | List of documents most similar to the query text and |
list[tuple[Document, ndarray]] | embedding vectors for each. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
similarity_search_by_image ¶
similarity_search_by_image( uri: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, **kwargs: Any ) -> list[Document]
Search for similar images based on the given image URI.
PARAMETER | DESCRIPTION |
---|---|
| URI of the image to search for. TYPE: |
| Number of results to return. TYPE: |
| Filter by metadata. |
| Additional arguments to pass to function. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Images most similar to the provided image. Each element in list is a |
list[Document] | LangChain Document Object. The page content is b64 encoded image, metadata |
list[Document] | is default or as defined by user. |
RAISES | DESCRIPTION |
---|---|
ValueError | If the embedding function does not support image embeddings. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
similarity_search_by_image_with_relevance_score ¶
similarity_search_by_image_with_relevance_score( uri: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, **kwargs: Any ) -> list[tuple[Document, float]]
Search for similar images based on the given image URI.
PARAMETER | DESCRIPTION |
---|---|
| URI of the image to search for. TYPE: |
| Number of results to return. TYPE: |
| Filter by metadata. |
| Additional arguments to pass to function. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[tuple[Document, float]] | List of tuples containing documents similar to the query image and their |
list[tuple[Document, float]] | similarity scores. 0th element in each tuple is a LangChain Document Object. |
list[tuple[Document, float]] | The page content is b64 encoded img, metadata is default or defined by user. |
RAISES | DESCRIPTION |
---|---|
ValueError | If the embedding function does not support image embeddings. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
max_marginal_relevance_search_by_vector ¶
max_marginal_relevance_search_by_vector( embedding: list[float], k: int = DEFAULT_K, fetch_k: int = 20, lambda_mult: float = 0.5, filter: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[Document]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
PARAMETER | DESCRIPTION |
---|---|
| Embedding to look up documents similar to. |
| Number of Documents to return. Defaults to 4. TYPE: |
| Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. TYPE: |
| Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. TYPE: |
| Filter by metadata. |
| dict used to filter by the document contents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents selected by maximal marginal relevance. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
max_marginal_relevance_search ¶
max_marginal_relevance_search( query: str, k: int = DEFAULT_K, fetch_k: int = 20, lambda_mult: float = 0.5, filter: dict[str, str] | None = None, where_document: dict[str, str] | None = None, **kwargs: Any ) -> list[Document]
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
PARAMETER | DESCRIPTION |
---|---|
| Text to look up documents similar to. TYPE: |
| Number of Documents to return. Defaults to 4. TYPE: |
| Number of Documents to fetch to pass to MMR algorithm. TYPE: |
| Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. TYPE: |
| Filter by metadata. |
| dict used to filter by the document contents. E.g. {"$contains": "hello"}. |
| Additional keyword arguments to pass to Chroma collection query. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents selected by maximal marginal relevance. |
RAISES | DESCRIPTION |
---|---|
ValueError | If the embedding function is not provided. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
delete_collection ¶
reset_collection ¶
Resets the collection.
Resets the collection by deleting the collection and recreating an empty one.
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
get ¶
get( ids: str | list[str] | None = None, where: Where | None = None, limit: int | None = None, offset: int | None = None, where_document: WhereDocument | None = None, include: list[str] | None = None, ) -> dict[str, Any]
Gets the collection.
PARAMETER | DESCRIPTION |
---|---|
| The ids of the embeddings to get. Optional. |
| A Where type dict used to filter results by. E.g. TYPE: |
| The number of documents to return. Optional. TYPE: |
| The offset to start returning results from. Useful for paging results with limit. Optional. TYPE: |
| A WhereDocument type dict used to filter by the documents. E.g. TYPE: |
| A list of what to include in the results. Can contain |
RETURNS | DESCRIPTION |
---|---|
dict[str, Any] | A dict with the keys |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
get_by_ids ¶
Get documents by their IDs.
The returned documents are expected to have the ID field set to the ID of the document in the vector store.
Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.
Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.
This method should NOT raise exceptions if no documents are found for some IDs.
PARAMETER | DESCRIPTION |
---|---|
| List of ids to retrieve. |
RETURNS | DESCRIPTION |
---|---|
list[Document] | List of Documents. |
Added in 0.2.1
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
update_document ¶
update_document( document_id: str, document: Document ) -> None
update_documents ¶
Update a document in the collection.
PARAMETER | DESCRIPTION |
---|---|
| List of ids of the document to update. |
| List of documents to update. TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If the embedding function is not provided. |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
from_texts classmethod
¶
from_texts( texts: list[str], embedding: Embeddings | None = None, metadatas: list[dict] | None = None, ids: list[str] | None = None, collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME, persist_directory: str | None = None, host: str | None = None, port: int | None = None, headers: dict[str, str] | None = None, chroma_cloud_api_key: str | None = None, tenant: str | None = None, database: str | None = None, client_settings: Settings | None = None, client: ClientAPI | None = None, collection_metadata: dict | None = None, collection_configuration: ( CreateCollectionConfiguration | None ) = None, *, ssl: bool = False, **kwargs: Any ) -> Chroma
Create a Chroma vectorstore from a raw documents.
If a persist_directory is specified, the collection will be persisted there. Otherwise, the data will be ephemeral in-memory.
PARAMETER | DESCRIPTION |
---|---|
| List of texts to add to the collection. |
| Name of the collection to create. TYPE: |
| Directory to persist the collection. TYPE: |
| Hostname of a deployed Chroma server. TYPE: |
| Connection port for a deployed Chroma server. Default is 8000. TYPE: |
| Whether to establish an SSL connection with a deployed Chroma server. Default is False. TYPE: |
| HTTP headers to send to a deployed Chroma server. |
| Chroma Cloud API key. TYPE: |
| Tenant ID. Required for Chroma Cloud connections. Default is 'default_tenant' for local Chroma servers. TYPE: |
| Database name. Required for Chroma Cloud connections. Default is 'default_database'. TYPE: |
| Embedding function. TYPE: |
| List of metadatas. |
| List of document IDs. |
| Chroma client settings. TYPE: |
| Chroma client. Documentation: https://docs.trychroma.com/reference/python/client TYPE: |
| Collection configurations. TYPE: |
| Index configuration for the collection. TYPE: |
| Additional keyword arguments to initialize a Chroma client. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Chroma | Chroma vectorstore. TYPE: |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
|
from_documents classmethod
¶
from_documents( documents: list[Document], embedding: Embeddings | None = None, ids: list[str] | None = None, collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME, persist_directory: str | None = None, host: str | None = None, port: int | None = None, headers: dict[str, str] | None = None, chroma_cloud_api_key: str | None = None, tenant: str | None = None, database: str | None = None, client_settings: Settings | None = None, client: ClientAPI | None = None, collection_metadata: dict | None = None, collection_configuration: ( CreateCollectionConfiguration | None ) = None, *, ssl: bool = False, **kwargs: Any ) -> Chroma
Create a Chroma vectorstore from a list of documents.
If a persist_directory is specified, the collection will be persisted there. Otherwise, the data will be ephemeral in-memory.
PARAMETER | DESCRIPTION |
---|---|
| Name of the collection to create. TYPE: |
| Directory to persist the collection. TYPE: |
| Hostname of a deployed Chroma server. TYPE: |
| Connection port for a deployed Chroma server. Default is 8000. TYPE: |
| Whether to establish an SSL connection with a deployed Chroma server. Default is False. TYPE: |
| HTTP headers to send to a deployed Chroma server. |
| Chroma Cloud API key. TYPE: |
| Tenant ID. Required for Chroma Cloud connections. Default is 'default_tenant' for local Chroma servers. TYPE: |
| Database name. Required for Chroma Cloud connections. Default is 'default_database'. TYPE: |
| List of document IDs.
|
| List of documents to add to the vectorstore. TYPE: |
| Embedding function. TYPE: |
| Chroma client settings. TYPE: |
| Chroma client. Documentation: https://docs.trychroma.com/reference/python/client TYPE: |
| Collection configurations. TYPE: |
| Index configuration for the collection. TYPE: |
| Additional keyword arguments to initialize a Chroma client. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Chroma | Chroma vectorstore. TYPE: |
Source code in .venv/lib/python3.13/site-packages/langchain_chroma/vectorstores.py
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 |
|