embed_documents() — langchain Function Reference
Architecture documentation for the embed_documents() function in cache.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2059f943_8fad_d2bc_2c40_ce532430d77f["embed_documents()"] b3be4e54_ae5f_c527_4e99_0843e3d30f72["CacheBackedEmbeddings"] 2059f943_8fad_d2bc_2c40_ce532430d77f -->|defined in| b3be4e54_ae5f_c527_4e99_0843e3d30f72 style 2059f943_8fad_d2bc_2c40_ce532430d77f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/embeddings/cache.py lines 165–199
def embed_documents(self, texts: list[str]) -> list[list[float]]:
"""Embed a list of texts.
The method first checks the cache for the embeddings.
If the embeddings are not found, the method uses the underlying embedder
to embed the documents and stores the results in the cache.
Args:
texts: A list of texts to embed.
Returns:
A list of embeddings for the given texts.
"""
vectors: list[list[float] | None] = self.document_embedding_store.mget(
texts,
)
all_missing_indices: list[int] = [
i for i, vector in enumerate(vectors) if vector is None
]
for missing_indices in batch_iterate(self.batch_size, all_missing_indices):
missing_texts = [texts[i] for i in missing_indices]
missing_vectors = self.underlying_embeddings.embed_documents(missing_texts)
self.document_embedding_store.mset(
list(zip(missing_texts, missing_vectors, strict=False)),
)
for index, updated_vector in zip(
missing_indices, missing_vectors, strict=False
):
vectors[index] = updated_vector
return cast(
"list[list[float]]",
vectors,
) # Nones should have been resolved by now
Domain
Subdomains
Source
Frequently Asked Questions
What does embed_documents() do?
embed_documents() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/embeddings/cache.py.
Where is embed_documents() defined?
embed_documents() is defined in libs/langchain/langchain_classic/embeddings/cache.py at line 165.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free