What is .add_texts()?
.add_texts() is the lower-level method for adding content to a vector store when you have raw strings rather than Document objects. It embeds each text string using the store's configured embedding function and inserts the resulting vectors with optional associated metadata. The metadatas parameter accepts a list of dicts — one per text — to associate structured metadata with each stored vector. It returns a list of string IDs, one per input text.
add_texts() is the method that from_texts() calls internally when creating a new vector store. Most vector store implementations inherit a default add_texts() from the VectorStore base class that handles batching and embedding; others (Pinecone, Weaviate, Chroma) override it with provider-specific bulk insert APIs. In practice, add_documents() is more commonly used because Document objects carry metadata implicitly. Use add_texts() when ingesting text from a source that does not produce Document objects — raw API responses, scraped strings, database text columns.
The optional ids parameter lets you specify custom document IDs instead of auto-generated UUIDs. This is important for idempotent pipelines: if you re-ingest the same content with the same IDs, Pinecone and Qdrant will upsert rather than duplicate. For Chroma, which uses IDs as primary keys, passing the same ID twice raises an error unless you delete the old document first.
Use Cases
- • Add raw text
- • Incremental indexing
- • Text-only additions
- • Dynamic updates
- • Growing store
- • Batch text
Key Features
- ✓ Add text strings
- ✓ No doc objects
- ✓ Simple API
- ✓ Returns IDs
- ✓ Batch support
- ✓ Direct storage
When NOT to Use
When you have Document objects—use add_documents().
Notes
Prefer add_documents() when you have metadata
If you have metadata to associate, create Document(page_content=text, metadata={...}) objects and use add_documents(). The code is cleaner and avoids the positional metadatas list requirement in add_texts().
metadatas must be scalar values
The metadatas list must be the same length as texts. If any metadata dict contains non-scalar values (lists, nested dicts), Chroma and some other stores will reject the insert. Flatten metadata to str, int, float, or bool before calling add_texts().
Batching limits vary by store
For large lists, most stores batch embedding calls based on chunk_size. Chroma has an internal batch limit of 41,666 documents per call; Pinecone's upsert batch limit is 1,000 vectors. Check your store's documentation when adding tens of thousands of texts at once.
Async variant available
Use aadd_texts() for non-blocking addition. Signature is identical but the method is a coroutine: ids = await store.aadd_texts(texts). Available on all stores that implement async operations.
Method Signature
ids = vector_store.add_texts(texts)
Parameters
| Parameter | Type | Required | Purpose |
|---|---|---|---|
| texts | List[str] | Yes | Text strings to add |
Return Value
Type:
List[str]
Description:
IDs of added texts
Example Output:
['id1', 'id2', ...]
Code Examples
Basic add_texts
new_texts = ['New content 1', 'New content 2']
ids = vector_store.add_texts(new_texts)
print(f'Added {len(ids)} texts')
Add with metadata and deterministic IDs
import hashlib
texts = [
'LangChain simplifies building LLM apps.',
'Vector stores enable semantic similarity search.',
]
metadatas = [
{'source': 'intro', 'section': 'overview', 'ts': '2026-01-01'},
{'source': 'guide', 'section': 'retrieval', 'ts': '2026-01-02'},
]
ids = [hashlib.md5(t.encode()).hexdigest() for t in texts]
vector_store.add_texts(texts, metadatas=metadatas, ids=ids)
print(f'Added with custom IDs: {ids}')
Async add with aadd_texts
import asyncio
async def async_add(store, texts):
ids = await store.aadd_texts(texts)
print(f'Async added {len(ids)} texts')
return ids
texts = [f'chunk {i}' for i in range(100)]
asyncio.run(async_add(vector_store, texts))
Common Mistakes
❌ Add metadata with add_texts()
✅ Use add_documents() for metadata support
Related LangChain References
Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with .add_texts() and the wider framework.
.add_texts() FAQ
What does .add_texts() do in LangChain?
Add text strings to existing vector store. .add_texts() is the lower-level method for adding content to a vector store when you have raw strings rather than Document objects. It embeds each text string using the store's configured embedding function and inserts the resulting vectors with optional associated metadata. The metadatas parameter accepts a list of dicts — one per text — to associate structured metadata with each stored vector. It returns a list of string IDs, one per input text. add_texts() is the method t…
Which LangChain classes support .add_texts()?
.add_texts() is available on Vector stores. Pin your installed LangChain version and verify the method exists in that release before deploying.
When should I use .add_texts()?
Use .add_texts() when your LangChain chains, agents, or pipelines need the behavior described in this guide.
What does .add_texts() return?
.add_texts() returns a List[str]. IDs of added texts
Does .add_texts() have an async equivalent?
Yes — use aadd_texts() for async contexts such as FastAPI handlers or asyncio-based pipelines. It is the non-blocking counterpart to .add_texts().
Where can I explore more LangChain API reference pages?
Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.