mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-22 09:15:31 -04:00
09f301cd38
Also updated docs, and noticed an issue with the add_texts method on VectorStores that I had missed before -- the metadatas arg should be required to match the classmethod which initializes the VectorStores (the add_example methods break otherwise in the ExampleSelectors)
32 lines
933 B
Python
32 lines
933 B
Python
"""Interface for vector stores."""
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any, Iterable, List, Optional
|
|
|
|
from langchain.docstore.document import Document
|
|
from langchain.embeddings.base import Embeddings
|
|
|
|
|
|
class VectorStore(ABC):
|
|
"""Interface for vector stores."""
|
|
|
|
@abstractmethod
|
|
def add_texts(
|
|
self, texts: Iterable[str], metadatas: Optional[List[dict]] = None
|
|
) -> None:
|
|
"""Run more texts through the embeddings and add to the vectorstore."""
|
|
|
|
@abstractmethod
|
|
def similarity_search(self, query: str, k: int = 4) -> List[Document]:
|
|
"""Return docs most similar to query."""
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def from_texts(
|
|
cls,
|
|
texts: List[str],
|
|
embedding: Embeddings,
|
|
metadatas: Optional[List[dict]] = None,
|
|
**kwargs: Any
|
|
) -> "VectorStore":
|
|
"""Return VectorStore initialized from texts and embeddings."""
|