Home / Function/ from_documents() — langchain Function Reference

from_documents() — langchain Function Reference

Architecture documentation for the from_documents() function in vectorstores.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  47dbea0f_8a83_dbee_34f5_9406b1ac209b["from_documents()"]
  d25f9e94_3ec0_b9ca_7d2f_eb7ef487ccab["Chroma"]
  47dbea0f_8a83_dbee_34f5_9406b1ac209b -->|defined in| d25f9e94_3ec0_b9ca_7d2f_eb7ef487ccab
  8333d70f_d25a_107c_0310_d6f0ca8ca56e["from_texts()"]
  47dbea0f_8a83_dbee_34f5_9406b1ac209b -->|calls| 8333d70f_d25a_107c_0310_d6f0ca8ca56e
  style 47dbea0f_8a83_dbee_34f5_9406b1ac209b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/chroma/langchain_chroma/vectorstores.py lines 1375–1450

    def from_documents(
        cls: type[Chroma],
        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: chromadb.config.Settings | None = None,
        client: chromadb.ClientAPI | None = None,  # Add this line
        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.

        Args:
            collection_name: Name of the collection to create.
            persist_directory: Directory to persist the collection.
            host: Hostname of a deployed Chroma server.
            port: Connection port for a deployed Chroma server. Default is 8000.
            ssl: Whether to establish an SSL connection with a deployed Chroma server.
            headers: HTTP headers to send to a deployed Chroma server.
            chroma_cloud_api_key: Chroma Cloud API key.
            tenant: Tenant ID. Required for Chroma Cloud connections.
                    Default is 'default_tenant' for local Chroma servers.
            database: Database name. Required for Chroma Cloud connections.
                    Default is 'default_database'.
            ids: List of document IDs.
            documents: List of documents to add to the `VectorStore`.
            embedding: Embedding function.
            client_settings: Chroma client settings.
            client: Chroma client. Documentation:
                    https://docs.trychroma.com/reference/python/client
            collection_metadata: Collection configurations.
            collection_configuration: Index configuration for the collection.

            kwargs: Additional keyword arguments to initialize a Chroma client.

        Returns:
            Chroma: Chroma vectorstore.
        """
        texts = [doc.page_content for doc in documents]
        metadatas = [doc.metadata for doc in documents]
        if ids is None:
            ids = [doc.id if doc.id else str(uuid.uuid4()) for doc in documents]
        return cls.from_texts(
            texts=texts,
            embedding=embedding,
            metadatas=metadatas,
            ids=ids,
            collection_name=collection_name,
            persist_directory=persist_directory,
            host=host,
            port=port,
            ssl=ssl,
            headers=headers,
            chroma_cloud_api_key=chroma_cloud_api_key,
            tenant=tenant,
            database=database,
            client_settings=client_settings,
            client=client,
            collection_metadata=collection_metadata,
            collection_configuration=collection_configuration,
            **kwargs,
        )

Subdomains

Calls

Frequently Asked Questions

What does from_documents() do?
from_documents() is a function in the langchain codebase, defined in libs/partners/chroma/langchain_chroma/vectorstores.py.
Where is from_documents() defined?
from_documents() is defined in libs/partners/chroma/langchain_chroma/vectorstores.py at line 1375.
What does from_documents() call?
from_documents() calls 1 function(s): from_texts.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free