Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain VectorStore Add Documents

From Leeroopedia
Knowledge Sources
Domains Vector_Search, Data_Indexing
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for adding documents to a vector store with automatic embedding provided by langchain-core and backend integrations.

Description

The VectorStore.add_documents() method is the high-level API for indexing. It extracts text and metadata from Document objects, delegates to add_texts(), which calls embed_documents() on the configured embedding model and stores the results. The Chroma.add_texts() implementation upserts into the underlying Chroma collection.

Usage

Call add_documents() with a list of Document objects after text splitting.

Code Reference

Source Location

  • Repository: langchain
  • File: libs/core/langchain_core/vectorstores/base.py (add_documents), libs/partners/chroma/langchain_chroma/vectorstores.py (Chroma.add_texts)
  • Lines: base.py L234-263 (add_documents); vectorstores.py L597-682 (Chroma.add_texts)

Signature

# VectorStore base
def add_documents(self, documents: list[Document], **kwargs: Any) -> list[str]:

# Chroma implementation
def add_texts(
    self,
    texts: Iterable[str],
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    **kwargs: Any,
) -> list[str]:

Import

from langchain_chroma import Chroma
from langchain_core.documents import Document

I/O Contract

Inputs

Name Type Required Description
documents list[Document] Yes Documents to embed and store
ids list[str] or None No Custom document IDs (auto-generated UUIDs if not provided)

Outputs

Name Type Description
return list[str] IDs of the added documents

Usage Examples

Adding Documents

from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document

vectorstore = Chroma(embedding_function=OpenAIEmbeddings())

docs = [
    Document(page_content="LangChain is a framework for LLM apps", metadata={"source": "docs"}),
    Document(page_content="Vector stores enable semantic search", metadata={"source": "docs"}),
]

ids = vectorstore.add_documents(docs)
print(ids)  # ['uuid-1', 'uuid-2']

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment