What is .from_texts()?
.from_texts() is a class method on all LangChain vector store classes that creates and populates a store directly from a list of plain text strings. It is the simplest entry point for vector store creation — no Document objects required. Pass a list of strings, an embedding model, and you get back a fully initialized, immediately queryable store.
Under the hood, .from_texts() constructs Document objects from the strings (and the optional metadatas list) and delegates to the same embedding and storage path as .from_documents(). The two methods produce identical results when given equivalent inputs. The difference is purely ergonomic: .from_texts() saves the step of wrapping each string in Document() when you already have raw strings and either no metadata or simple inline metadata.
The method accepts an optional metadatas=List[dict] parameter and an optional ids=List[str] parameter. The metadatas list, if provided, must be the same length as texts — each dict is attached to the corresponding Document. Both .from_texts() and .from_documents() share the same persistence semantics per backend: Chroma is in-memory unless persist_directory is passed, FAISS must be saved with .save_local(), and cloud stores persist automatically.
Use Cases
- • Quickly prototype a RAG retriever from string literals
- • Index strings from a database query without a Document loader
- • Build test fixtures for retrieval pipelines without file I/O
- • Create a vector store with inline metadata via the metadatas= parameter
- • Set up a FAISS index for local similarity experiments
- • Assign stable IDs to text chunks for later targeted deletion or update
Key Features
- ✓ No Document wrapping required — raw strings accepted directly
- ✓ Optional metadatas= and ids= for structured storage
- ✓ Same embedding and storage path as from_documents() internally
- ✓ Works with all LangChain vector store backends
- ✓ Immediately queryable after creation
- ✓ Persistence behavior matches from_documents() per backend
When NOT to Use
When you already have Document objects from a loader or text splitter — use from_documents() to preserve their metadata without manually extracting page_content.
Notes
Metadata is supported — use it rather than discarding it
from_texts() accepts an optional metadatas=[{...}, ...] list with one dict per text string. Each dict is attached to the corresponding Document internally. If your strings have any source information, pass it here rather than creating a separate from_documents() call — the result is identical.
IDs enable upsert and targeted deletion
Pass ids=["stable-id-1", ...] to assign reproducible IDs instead of auto-generated UUIDs. Stable IDs let you call vector_store.delete(["stable-id-1"]) to remove specific entries and re-index changed content without rebuilding the entire store.
Persistence semantics are the same as from_documents()
Chroma.from_texts() is in-memory unless you pass persist_directory. FAISS.from_texts() is always in-memory and requires .save_local() / .load_local(). Cloud stores (Pinecone, Weaviate, Qdrant) persist automatically. The method you use to create the store does not change how persistence works.
Switch to from_documents() when metadata grows complex
from_texts() is ergonomically convenient for small prototypes. Once you start loading real files (PDFs, web pages, CSVs) with loaders that return Document objects, switch to from_documents() — it avoids manually extracting page_content and re-constructing metadata dicts.
Method Signature
vector_store = VectorStore.from_texts(texts, embedding, metadatas=None, ids=None, **kwargs)
Parameters
| Parameter | Type | Required | Purpose |
|---|---|---|---|
| texts | List[str] | Yes | List of raw text strings to embed and store |
| embedding | Embeddings | Yes | Embedding model used to encode the text strings |
| metadatas | List[dict] | No | Per-text metadata dicts — same length as texts |
| ids | List[str] | No | Stable string IDs for each entry (auto-generated if omitted) |
Return Value
Type:
VectorStore
Description:
Initialized vector store with all texts embedded and indexed
Example Output:
Chroma(collection_name="langchain", ...)
Code Examples
Create and query a vector store from plain strings
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(model='text-embedding-3-small')
texts = [
'LangChain is a framework for building LLM applications.',
'LCEL lets you compose Runnables into chains declaratively.',
'Agents use LLMs to decide which tools to call at runtime.',
]
vector_store = Chroma.from_texts(texts, embeddings)
results = vector_store.similarity_search('what are agents?', k=2)
print(results[0].page_content)
Add metadata and stable IDs with persistence
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(model='text-embedding-3-small')
texts = [
'LangChain simplifies building LLM apps.',
'LangGraph adds stateful multi-agent workflows.',
]
metadatas = [
{'source': 'langchain_docs', 'section': 'intro'},
{'source': 'langgraph_docs', 'section': 'overview'},
]
ids = ['lc-intro-1', 'lg-overview-1']
vs = Chroma.from_texts(
texts, embeddings, metadatas=metadatas, ids=ids,
persist_directory='.chroma_db'
)
# Filter search by source
results = vs.similarity_search('multi-agent', k=1, filter={'source': 'langgraph_docs'})
print(results[0].page_content)
FAISS index from texts with save/load
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(model='text-embedding-3-small')
# Quick FAISS index for testing
texts = [f'Test document {i}' for i in range(10)]
vs = FAISS.from_texts(texts, embeddings)
# Save and reload across runs
vs.save_local('./faiss_test')
vs2 = FAISS.load_local('./faiss_test', embeddings, allow_dangerous_deserialization=True)
print(vs2.similarity_search('document 5', k=1)[0].page_content)
Common Mistakes
❌ Chroma.from_texts(texts, embeddings) # loses all metadata when you actually have it
✅ from_texts() accepts an optional metadatas=[{...}, ...] list — use it instead of discarding source info
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 .from_texts() and the wider framework.
.from_texts() FAQ
What does .from_texts() do in LangChain?
Create and populate a vector store from raw text strings without needing Document objects. .from_texts() is a class method on all LangChain vector store classes that creates and populates a store directly from a list of plain text strings. It is the simplest entry point for vector store creation — no Document objects required. Pass a list of strings, an embedding model, and you get back a fully initialized, immediately queryable store. Under the hood, .from_texts() constructs Document objects from the strings (and the optional metadatas list) and delegates to the …
Which LangChain classes support .from_texts()?
.from_texts() is available on Vector stores (class method). Pin your installed LangChain version and verify the method exists in that release before deploying.
When should I use .from_texts()?
Use .from_texts() when your LangChain chains, agents, or pipelines need the behavior described in this guide.
What does .from_texts() return?
.from_texts() returns a VectorStore. Initialized vector store with all texts embedded and indexed
Does .from_texts() have an async equivalent?
.from_texts() does not have a documented async variant. Avoid .from_texts() When you already have Document objects from a loader or text splitter — use from_documents() to preserve their metadata without manually extracting page_content.
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.