This commit is contained in:
Eugene Yurtsev
2024-07-12 17:06:37 -04:00
parent a596b1b515
commit 8be42bb0d4
2 changed files with 50 additions and 13 deletions

View File

@@ -54,7 +54,7 @@ if TYPE_CHECKING:
AsyncCallbackManagerForRetrieverRun,
CallbackManagerForRetrieverRun,
)
from langchain_core.indexing.base import DeleteResponse, UpsertResponse
from langchain_core.indexing.base import DeleteResponse, Sort, T, UpsertResponse
from langchain_core.documents.base import Document
from langchain_core.indexing import BaseIndex
@@ -516,6 +516,54 @@ class VectorStore(BaseIndex[Document]):
"search_type to be 'similarity', 'similarity_score_threshold' or 'mmr'."
)
def delete_by_filter(
self,
filter: Union[Dict[str, Any], List[Dict[str, Any]]],
/,
**kwargs: Any,
) -> DeleteResponse:
"""Delete documents by filter.
Args:
filter: Filter to apply to documents.
**kwargs: Other keyword arguments that subclasses might use.
Returns:
DeleteResponse: A response object that contains the list of IDs that were
successfully deleted from the vectorstore and the list of IDs that failed
to be deleted.
.. versionadded:: 0.2.15
"""
raise NotImplementedError(
f"{self.__class__.__name__} does not yet support delete_by_filter."
)
def get_by_filter(
self,
*,
filter: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
limit: Optional[int] = None,
sort: Optional[Sort] = None,
**kwargs: Any,
) -> Iterable[T]:
"""Get documents by filter.
Args:
filter: Filter to apply to documents.
limit: Maximum number of documents to return.
sort: Sort order for the returned documents.
**kwargs: Other keyword arguments that subclasses might use.
Returns:
Iterable of documents that match the filter.
.. versionadded:: 0.2.15
"""
raise NotImplementedError(
f"{self.__class__.__name__} does not yet support get_by_filter."
)
@abstractmethod
def similarity_search(
self, query: str, k: int = 4, **kwargs: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Iterable, List, Optional, Sequence, cast
from typing import Any, Iterable, List, Optional, cast
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings, FakeEmbeddings
@@ -6,7 +6,6 @@ from langchain_core.example_selectors import (
MaxMarginalRelevanceExampleSelector,
SemanticSimilarityExampleSelector,
)
from langchain_core.indexing.base import DeleteResponse
from langchain_core.vectorstores import VectorStore
@@ -32,16 +31,6 @@ class DummyVectorStore(VectorStore):
self.metadatas.extend(metadatas)
return ["dummy_id"]
def get_by_ids(self, ids: Sequence[str], /) -> List[Document]:
raise NotImplementedError()
def delete_by_ids(
self,
ids: Sequence[str],
/,
) -> DeleteResponse:
raise NotImplementedError()
def similarity_search(
self, query: str, k: int = 4, **kwargs: Any
) -> List[Document]: