Home / Class/ CustomAddTextsVectorstore Class — langchain Architecture

CustomAddTextsVectorstore Class — langchain Architecture

Architecture documentation for the CustomAddTextsVectorstore class in test_vectorstore.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  de67e33f_ac85_46b4_d151_2a405847ca87["CustomAddTextsVectorstore"]
  6c336ac6_f55c_1ad7_6db3_73dbd71fb625["VectorStore"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|extends| 6c336ac6_f55c_1ad7_6db3_73dbd71fb625
  547b9326_0fd1_ea2c_f15c_82026f35f74c["test_vectorstore.py"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|defined in| 547b9326_0fd1_ea2c_f15c_82026f35f74c
  4900823c_4629_4150_6a55_efb943ced1fb["__init__()"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|method| 4900823c_4629_4150_6a55_efb943ced1fb
  ace26790_92a3_03c0_1017_6c319ca5f45a["add_texts()"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|method| ace26790_92a3_03c0_1017_6c319ca5f45a
  cb881d61_c433_1fa7_9b56_681f781555e5["get_by_ids()"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|method| cb881d61_c433_1fa7_9b56_681f781555e5
  bc50d4b5_30d2_311f_4e38_2ece7c35a0f6["from_texts()"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|method| bc50d4b5_30d2_311f_4e38_2ece7c35a0f6
  81819e77_11a4_105e_9e7a_77d30620350b["similarity_search()"]
  de67e33f_ac85_46b4_d151_2a405847ca87 -->|method| 81819e77_11a4_105e_9e7a_77d30620350b

Relationship Graph

Source Code

libs/core/tests/unit_tests/vectorstores/test_vectorstore.py lines 23–71

class CustomAddTextsVectorstore(VectorStore):
    """A VectorStore that only implements add texts."""

    def __init__(self) -> None:
        self.store: dict[str, Document] = {}

    @override
    def add_texts(
        self,
        texts: Iterable[str],
        metadatas: list[dict] | None = None,
        ids: list[str] | None = None,
        **kwargs: Any,
    ) -> list[str]:
        if not isinstance(texts, list):
            texts = list(texts)
        ids_iter = iter(ids or [])

        ids_ = []

        metadatas_ = metadatas or [{} for _ in texts]

        for text, metadata in zip(texts, metadatas_ or [], strict=False):
            next_id = next(ids_iter, None)
            id_ = next_id or str(uuid.uuid4())
            self.store[id_] = Document(page_content=text, metadata=metadata, id=id_)
            ids_.append(id_)
        return ids_

    def get_by_ids(self, ids: Sequence[str], /) -> list[Document]:
        return [self.store[id_] for id_ in ids if id_ in self.store]

    @classmethod
    @override
    def from_texts(
        cls,
        texts: list[str],
        embedding: Embeddings,
        metadatas: list[dict] | None = None,
        **kwargs: Any,
    ) -> CustomAddTextsVectorstore:
        vectorstore = CustomAddTextsVectorstore()
        vectorstore.add_texts(texts, metadatas=metadatas, **kwargs)
        return vectorstore

    def similarity_search(
        self, query: str, k: int = 4, **kwargs: Any
    ) -> list[Document]:
        raise NotImplementedError

Extends

Frequently Asked Questions

What is the CustomAddTextsVectorstore class?
CustomAddTextsVectorstore is a class in the langchain codebase, defined in libs/core/tests/unit_tests/vectorstores/test_vectorstore.py.
Where is CustomAddTextsVectorstore defined?
CustomAddTextsVectorstore is defined in libs/core/tests/unit_tests/vectorstores/test_vectorstore.py at line 23.
What does CustomAddTextsVectorstore extend?
CustomAddTextsVectorstore extends VectorStore.

Analyze Your Own Codebase

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

Try Supermodel Free