VectorStore Class — langchain Architecture
Architecture documentation for the VectorStore class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9d2a2799_754f_4de7_e4e6_081d8ea620e0["VectorStore"] c3ed6b51_a344_0c0c_cf56_b617f175e3d8["base.py"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|defined in| c3ed6b51_a344_0c0c_cf56_b617f175e3d8 ed195720_19bc_4367_34a6_d24e2765eb12["add_texts()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| ed195720_19bc_4367_34a6_d24e2765eb12 65e68099_937b_7a77_0d7f_a4456746ea1d["embeddings()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 65e68099_937b_7a77_0d7f_a4456746ea1d 204e7362_b4a0_7694_b60d_97f9075df45d["delete()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 204e7362_b4a0_7694_b60d_97f9075df45d 2028dab1_b5b7_5e87_e8ed_dc7b74672cd4["get_by_ids()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 2028dab1_b5b7_5e87_e8ed_dc7b74672cd4 620e937a_304c_dc46_6a42_54357de1bc70["aget_by_ids()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 620e937a_304c_dc46_6a42_54357de1bc70 fea1b7b3_3c01_3080_a826_e7d9da1299fc["adelete()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| fea1b7b3_3c01_3080_a826_e7d9da1299fc 6c119853_2639_1f05_f0bf_3f3e68fdc2a5["aadd_texts()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 6c119853_2639_1f05_f0bf_3f3e68fdc2a5 d45d14a7_f50d_9fd8_b67c_a5d5feac6a61["add_documents()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| d45d14a7_f50d_9fd8_b67c_a5d5feac6a61 96e6b952_6686_89a9_1f1d_20cda66190cd["aadd_documents()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 96e6b952_6686_89a9_1f1d_20cda66190cd 01b0af81_f849_22ee_7639_f48e66e6caf1["search()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| 01b0af81_f849_22ee_7639_f48e66e6caf1 cd051a98_086d_11ab_a724_ffc3ac9b6185["asearch()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| cd051a98_086d_11ab_a724_ffc3ac9b6185 e225c83a_d502_9fa2_58ee_af556a2bf945["similarity_search()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| e225c83a_d502_9fa2_58ee_af556a2bf945 f32e6b1f_dcf7_6fd3_4296_34dbfa336f14["_euclidean_relevance_score_fn()"] 9d2a2799_754f_4de7_e4e6_081d8ea620e0 -->|method| f32e6b1f_dcf7_6fd3_4296_34dbfa336f14
Relationship Graph
Source Code
libs/core/langchain_core/vectorstores/base.py lines 43–961
class VectorStore(ABC):
"""Interface for vector store."""
def add_texts(
self,
texts: Iterable[str],
metadatas: list[dict] | None = None,
*,
ids: list[str] | None = None,
**kwargs: Any,
) -> list[str]:
"""Run more texts through the embeddings and add to the `VectorStore`.
Args:
texts: Iterable of strings to add to the `VectorStore`.
metadatas: Optional list of metadatas associated with the texts.
ids: Optional list of IDs associated with the texts.
**kwargs: `VectorStore` specific parameters.
One of the kwargs should be `ids` which is a list of ids
associated with the texts.
Returns:
List of IDs from adding the texts into the `VectorStore`.
Raises:
ValueError: If the number of metadatas does not match the number of texts.
ValueError: If the number of IDs does not match the number of texts.
"""
if type(self).add_documents != VectorStore.add_documents:
# This condition is triggered if the subclass has provided
# an implementation of the upsert method.
# The existing add_texts
texts_: Sequence[str] = (
texts if isinstance(texts, (list, tuple)) else list(texts)
)
if metadatas and len(metadatas) != len(texts_):
msg = (
"The number of metadatas must match the number of texts."
f"Got {len(metadatas)} metadatas and {len(texts_)} texts."
)
raise ValueError(msg)
metadatas_ = iter(metadatas) if metadatas else cycle([{}])
ids_: Iterator[str | None] = iter(ids) if ids else cycle([None])
docs = [
Document(id=id_, page_content=text, metadata=metadata_)
for text, metadata_, id_ in zip(texts, metadatas_, ids_, strict=False)
]
if ids is not None:
# For backward compatibility
kwargs["ids"] = ids
return self.add_documents(docs, **kwargs)
msg = f"`add_texts` has not been implemented for {self.__class__.__name__} "
raise NotImplementedError(msg)
@property
def embeddings(self) -> Embeddings | None:
"""Access the query embedding object if available."""
logger.debug(
"The embeddings property has not been implemented for %s",
self.__class__.__name__,
)
return None
def delete(self, ids: list[str] | None = None, **kwargs: Any) -> bool | None:
"""Delete by vector ID or other criteria.
Args:
ids: List of IDs to delete. If `None`, delete all.
**kwargs: Other keyword arguments that subclasses might use.
Returns:
`True` if deletion is successful, `False` otherwise, `None` if not
implemented.
"""
msg = "delete method must be implemented by subclass."
raise NotImplementedError(msg)
def get_by_ids(self, ids: Sequence[str], /) -> list[Document]:
"""Get documents by their IDs.
Source
Frequently Asked Questions
What is the VectorStore class?
VectorStore is a class in the langchain codebase, defined in libs/core/langchain_core/vectorstores/base.py.
Where is VectorStore defined?
VectorStore is defined in libs/core/langchain_core/vectorstores/base.py at line 43.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free