Home / Function/ add_documents() — langchain Function Reference

add_documents() — langchain Function Reference

Architecture documentation for the add_documents() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a["add_documents()"]
  6c336ac6_f55c_1ad7_6db3_73dbd71fb625["VectorStore"]
  ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a -->|defined in| 6c336ac6_f55c_1ad7_6db3_73dbd71fb625
  8987550d_87eb_63b4_a3e6_a9f355797f08["add_texts()"]
  8987550d_87eb_63b4_a3e6_a9f355797f08 -->|calls| ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a
  01360435_9886_2db5_7556_2148d97a9fdd["add_documents()"]
  01360435_9886_2db5_7556_2148d97a9fdd -->|calls| ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a
  8987550d_87eb_63b4_a3e6_a9f355797f08["add_texts()"]
  ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a -->|calls| 8987550d_87eb_63b4_a3e6_a9f355797f08
  01360435_9886_2db5_7556_2148d97a9fdd["add_documents()"]
  ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a -->|calls| 01360435_9886_2db5_7556_2148d97a9fdd
  style ebcdae9e_b9ad_ed9c_d4b2_8d59854c890a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/vectorstores/base.py lines 234–263

    def add_documents(self, documents: list[Document], **kwargs: Any) -> list[str]:
        """Add or update documents in the `VectorStore`.

        Args:
            documents: Documents to add to the `VectorStore`.
            **kwargs: Additional keyword arguments.

                If kwargs contains IDs and documents contain ids, the IDs in the kwargs
                will receive precedence.

        Returns:
            List of IDs of the added texts.
        """
        if type(self).add_texts != VectorStore.add_texts:
            if "ids" not in kwargs:
                ids = [doc.id for doc in documents]

                # If there's at least one valid ID, we'll assume that IDs
                # should be used.
                if any(ids):
                    kwargs["ids"] = ids

            texts = [doc.page_content for doc in documents]
            metadatas = [doc.metadata for doc in documents]
            return self.add_texts(texts, metadatas, **kwargs)
        msg = (
            f"`add_documents` and `add_texts` has not been implemented "
            f"for {self.__class__.__name__} "
        )
        raise NotImplementedError(msg)

Subdomains

Frequently Asked Questions

What does add_documents() do?
add_documents() is a function in the langchain codebase, defined in libs/core/langchain_core/vectorstores/base.py.
Where is add_documents() defined?
add_documents() is defined in libs/core/langchain_core/vectorstores/base.py at line 234.
What does add_documents() call?
add_documents() calls 2 function(s): add_documents, add_texts.
What calls add_documents()?
add_documents() is called by 2 function(s): add_documents, add_texts.

Analyze Your Own Codebase

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

Try Supermodel Free