Home / File/ vectorstore.py — langchain Source File

vectorstore.py — langchain Source File

Architecture documentation for vectorstore.py, a python file in the langchain codebase. 12 imports, 0 dependents.

File python CoreAbstractions Serialization 12 imports 2 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676["vectorstore.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  2a596110_eecb_6975_0f38_02fb4494758e["langchain_core.document_loaders"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> 2a596110_eecb_6975_0f38_02fb4494758e
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3["langchain_core.embeddings"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  d55af636_303c_0eb6_faee_20d89bd952d5["langchain_core.vectorstores"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> d55af636_303c_0eb6_faee_20d89bd952d5
  5d24a664_4d9b_7491_ea6a_e13ddbcc8eeb["langchain_text_splitters"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> 5d24a664_4d9b_7491_ea6a_e13ddbcc8eeb
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  16ba09ba_bf3c_c352_cfb8_79269e19e908["langchain_classic.chains.qa_with_sources.retrieval"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> 16ba09ba_bf3c_c352_cfb8_79269e19e908
  ba604869_b61e_e85a_c63c_28db7c41dd6c["langchain_classic.chains.retrieval_qa.base"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> ba604869_b61e_e85a_c63c_28db7c41dd6c
  0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> 0c635125_6987_b8b3_7ff7_d60249aecde7
  e38551ac_1300_8e29_3a53_af6d09b55358["langchain_community.vectorstores.inmemory"]
  73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 --> e38551ac_1300_8e29_3a53_af6d09b55358
  style 73d9f5a5_8ee1_7e4e_6487_8a802a7a9676 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Vectorstore stubs for the indexing api."""

from typing import Any

from langchain_core.document_loaders import BaseLoader
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.language_models import BaseLanguageModel
from langchain_core.vectorstores import VectorStore
from langchain_text_splitters import RecursiveCharacterTextSplitter, TextSplitter
from pydantic import BaseModel, ConfigDict, Field

from langchain_classic.chains.qa_with_sources.retrieval import (
    RetrievalQAWithSourcesChain,
)
from langchain_classic.chains.retrieval_qa.base import RetrievalQA


def _get_default_text_splitter() -> TextSplitter:
    """Return the default text splitter used for chunking documents."""
    return RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)


class VectorStoreIndexWrapper(BaseModel):
    """Wrapper around a `VectorStore` for easy access."""

    vectorstore: VectorStore

    model_config = ConfigDict(
        arbitrary_types_allowed=True,
        extra="forbid",
    )

    def query(
        self,
        question: str,
        llm: BaseLanguageModel | None = None,
        retriever_kwargs: dict[str, Any] | None = None,
        **kwargs: Any,
    ) -> str:
        """Query the `VectorStore` using the provided LLM.

        Args:
            question: The question or prompt to query.
            llm: The language model to use. Must not be `None`.
            retriever_kwargs: Optional keyword arguments for the retriever.
            **kwargs: Additional keyword arguments forwarded to the chain.

        Returns:
            The result string from the RetrievalQA chain.
        """
        if llm is None:
            msg = (
                "This API has been changed to require an LLM. "
                "Please provide an llm to use for querying the vectorstore.\n"
                "For example,\n"
                "from langchain_openai import OpenAI\n"
                "model = OpenAI(temperature=0)"
            )
            raise NotImplementedError(msg)
// ... (212 more lines)

Subdomains

Dependencies

  • langchain_classic.chains.qa_with_sources.retrieval
  • langchain_classic.chains.retrieval_qa.base
  • langchain_community.vectorstores.inmemory
  • langchain_core.document_loaders
  • langchain_core.documents
  • langchain_core.embeddings
  • langchain_core.language_models
  • langchain_core.vectorstores
  • langchain_text_splitters
  • pydantic
  • typing
  • warnings

Frequently Asked Questions

What does vectorstore.py do?
vectorstore.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in vectorstore.py?
vectorstore.py defines 2 function(s): _get_default_text_splitter, _get_in_memory_vectorstore.
What does vectorstore.py depend on?
vectorstore.py imports 12 module(s): langchain_classic.chains.qa_with_sources.retrieval, langchain_classic.chains.retrieval_qa.base, langchain_community.vectorstores.inmemory, langchain_core.document_loaders, langchain_core.documents, langchain_core.embeddings, langchain_core.language_models, langchain_core.vectorstores, and 4 more.
Where is vectorstore.py in the architecture?
vectorstore.py is located at libs/langchain/langchain_classic/indexes/vectorstore.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/indexes).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free