VectorstoreIndexCreator Class — langchain Architecture
Architecture documentation for the VectorstoreIndexCreator class in vectorstore.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 858579e5_58f8_178b_c582_c9b4c09e72f6["VectorstoreIndexCreator"] 73d9f5a5_8ee1_7e4e_6487_8a802a7a9676["vectorstore.py"] 858579e5_58f8_178b_c582_c9b4c09e72f6 -->|defined in| 73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 ebd0b8a2_8771_f114_d5dd_011e22fe0c3b["from_loaders()"] 858579e5_58f8_178b_c582_c9b4c09e72f6 -->|method| ebd0b8a2_8771_f114_d5dd_011e22fe0c3b b4b26be7_d158_ad24_30f8_66497b468401["afrom_loaders()"] 858579e5_58f8_178b_c582_c9b4c09e72f6 -->|method| b4b26be7_d158_ad24_30f8_66497b468401 0dccabf5_af9e_78c8_bfa5_76137cd47c85["from_documents()"] 858579e5_58f8_178b_c582_c9b4c09e72f6 -->|method| 0dccabf5_af9e_78c8_bfa5_76137cd47c85 4a3a4410_3fac_99d0_d53f_7420f53b2dd6["afrom_documents()"] 858579e5_58f8_178b_c582_c9b4c09e72f6 -->|method| 4a3a4410_3fac_99d0_d53f_7420f53b2dd6
Relationship Graph
Source Code
libs/langchain/langchain_classic/indexes/vectorstore.py lines 193–271
class VectorstoreIndexCreator(BaseModel):
"""Logic for creating indexes."""
vectorstore_cls: type[VectorStore] = Field(
default_factory=_get_in_memory_vectorstore,
)
embedding: Embeddings
text_splitter: TextSplitter = Field(default_factory=_get_default_text_splitter)
vectorstore_kwargs: dict = Field(default_factory=dict)
model_config = ConfigDict(
arbitrary_types_allowed=True,
extra="forbid",
)
def from_loaders(self, loaders: list[BaseLoader]) -> VectorStoreIndexWrapper:
"""Create a `VectorStore` index from a list of loaders.
Args:
loaders: A list of `BaseLoader` instances to load documents.
Returns:
A `VectorStoreIndexWrapper` containing the constructed vectorstore.
"""
docs = []
for loader in loaders:
docs.extend(loader.load())
return self.from_documents(docs)
async def afrom_loaders(self, loaders: list[BaseLoader]) -> VectorStoreIndexWrapper:
"""Asynchronously create a `VectorStore` index from a list of loaders.
Args:
loaders: A list of `BaseLoader` instances to load documents.
Returns:
A `VectorStoreIndexWrapper` containing the constructed vectorstore.
"""
docs = []
for loader in loaders:
docs.extend([doc async for doc in loader.alazy_load()])
return await self.afrom_documents(docs)
def from_documents(self, documents: list[Document]) -> VectorStoreIndexWrapper:
"""Create a `VectorStore` index from a list of documents.
Args:
documents: A list of `Document` objects.
Returns:
A `VectorStoreIndexWrapper` containing the constructed vectorstore.
"""
sub_docs = self.text_splitter.split_documents(documents)
vectorstore = self.vectorstore_cls.from_documents(
sub_docs,
self.embedding,
**self.vectorstore_kwargs,
)
return VectorStoreIndexWrapper(vectorstore=vectorstore)
async def afrom_documents(
self,
documents: list[Document],
) -> VectorStoreIndexWrapper:
"""Asynchronously create a `VectorStore` index from a list of documents.
Args:
documents: A list of `Document` objects.
Returns:
A `VectorStoreIndexWrapper` containing the constructed vectorstore.
"""
sub_docs = self.text_splitter.split_documents(documents)
vectorstore = await self.vectorstore_cls.afrom_documents(
sub_docs,
self.embedding,
**self.vectorstore_kwargs,
)
return VectorStoreIndexWrapper(vectorstore=vectorstore)
Source
Frequently Asked Questions
What is the VectorstoreIndexCreator class?
VectorstoreIndexCreator is a class in the langchain codebase, defined in libs/langchain/langchain_classic/indexes/vectorstore.py.
Where is VectorstoreIndexCreator defined?
VectorstoreIndexCreator is defined in libs/langchain/langchain_classic/indexes/vectorstore.py at line 193.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free