Files
langchain-python/langchain/vectorstores/base.py
T
Harrison Chase 2163d064f3 add return of ids (#254)
not actually sure the desired return in add_example to example selector
is actually general/good - whats the use case?
2022-12-05 12:50:48 -08:00

42 lines
1.2 KiB
Python

"""Interface for vector stores."""
from __future__ import annotations
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
) -> 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.
Returns:
List of ids from adding the texts into 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."""