From a596b1b51558cb8c6abcb78e1140ba726affd8fc Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Fri, 12 Jul 2024 17:03:24 -0400 Subject: [PATCH] linting --- libs/core/langchain_core/indexing/base.py | 8 +++----- libs/core/langchain_core/vectorstores/base.py | 18 +++++++++++------- .../langchain_core/vectorstores/in_memory.py | 4 ++-- .../vectorstores/test_vectorstore.py | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libs/core/langchain_core/indexing/base.py b/libs/core/langchain_core/indexing/base.py index bb82184b8e6..87e2cbca44f 100644 --- a/libs/core/langchain_core/indexing/base.py +++ b/libs/core/langchain_core/indexing/base.py @@ -163,6 +163,7 @@ class BaseIndex(Generic[T]): for item_batch in batch_iterate(batch_size, items): yield self.upsert(item_batch, **kwargs) + @abc.abstractmethod @beta(message="Added in 0.2.15. The API is subject to change.") def upsert(self, items: Sequence[T], /, **kwargs: Any) -> UpsertResponse: """Upsert items into the index. @@ -270,11 +271,8 @@ class BaseIndex(Generic[T]): @abc.abstractmethod def delete( - self, - ids: Sequence[str], - /, - **kwargs: Any, - ) -> Union[DeleteResponse, bool]: + self, ids: Optional[List[str]] = None, **kwargs: Any + ) -> Union[DeleteResponse, bool, None]: """Delete by IDs or other criteria. Args: diff --git a/libs/core/langchain_core/vectorstores/base.py b/libs/core/langchain_core/vectorstores/base.py index 2258af6503f..cad6ffeedc3 100644 --- a/libs/core/langchain_core/vectorstores/base.py +++ b/libs/core/langchain_core/vectorstores/base.py @@ -54,7 +54,7 @@ if TYPE_CHECKING: AsyncCallbackManagerForRetrieverRun, CallbackManagerForRetrieverRun, ) - from langchain_core.indexing.base import UpsertResponse + from langchain_core.indexing.base import DeleteResponse, UpsertResponse from langchain_core.documents.base import Document from langchain_core.indexing import BaseIndex @@ -235,8 +235,10 @@ class VectorStore(BaseIndex[Document]): ) return None - def delete(self, ids: Optional[List[str]] = None, **kwargs: Any) -> Optional[bool]: - """Delete by vector ID or other criteria. + def delete( + self, ids: Optional[List[str]] = None, **kwargs: Any + ) -> Union[DeleteResponse, None, bool]: + """Delete by ID or other criteria. Args: ids: List of ids to delete. @@ -249,7 +251,7 @@ class VectorStore(BaseIndex[Document]): raise NotImplementedError("delete method must be implemented by subclass.") - def get_by_ids(self, ids: Sequence[str], /) -> List[Document]: + def get_by_ids(self, ids: Sequence[str], /, **kwargs: Any) -> List[Document]: """Get documents by their IDs. The returned documents are expected to have the ID field set to the ID of the @@ -267,6 +269,7 @@ class VectorStore(BaseIndex[Document]): Args: ids: List of ids to retrieve. + kwargs: Other keyword arguments these are up to the implementation. Returns: List of Documents. @@ -278,7 +281,7 @@ class VectorStore(BaseIndex[Document]): ) # Implementations should override this method to provide an async native version. - async def aget_by_ids(self, ids: Sequence[str], /) -> List[Document]: + async def aget_by_ids(self, ids: Sequence[str], /, **kwargs: Any) -> List[Document]: """Get documents by their IDs. The returned documents are expected to have the ID field set to the ID of the @@ -296,6 +299,7 @@ class VectorStore(BaseIndex[Document]): Args: ids: List of ids to retrieve. + kwargs: Other keyword arguments these are up to the implementation. Returns: List of Documents. @@ -306,8 +310,8 @@ class VectorStore(BaseIndex[Document]): async def adelete( self, ids: Optional[List[str]] = None, **kwargs: Any - ) -> Optional[bool]: - """Delete by vector ID or other criteria. + ) -> Union[DeleteResponse, None, bool]: + """Delete by ID or other criteria. Args: ids: List of ids to delete. diff --git a/libs/core/langchain_core/vectorstores/in_memory.py b/libs/core/langchain_core/vectorstores/in_memory.py index deb93a5ce91..ee655e8db80 100644 --- a/libs/core/langchain_core/vectorstores/in_memory.py +++ b/libs/core/langchain_core/vectorstores/in_memory.py @@ -73,7 +73,7 @@ class InMemoryVectorStore(VectorStore): "failed": [], } - def get_by_ids(self, ids: Sequence[str], /) -> List[Document]: + def get_by_ids(self, ids: Sequence[str], /, **kwargs: Any) -> List[Document]: """Get documents by their ids.""" documents = [] @@ -89,7 +89,7 @@ class InMemoryVectorStore(VectorStore): ) return documents - async def aget_by_ids(self, ids: Sequence[str], /) -> List[Document]: + async def aget_by_ids(self, ids: Sequence[str], /, **kwargs: Any) -> List[Document]: return self.get_by_ids(ids) async def aadd_texts( diff --git a/libs/core/tests/unit_tests/vectorstores/test_vectorstore.py b/libs/core/tests/unit_tests/vectorstores/test_vectorstore.py index 6c1c6e101b2..6d16609f2ee 100644 --- a/libs/core/tests/unit_tests/vectorstores/test_vectorstore.py +++ b/libs/core/tests/unit_tests/vectorstores/test_vectorstore.py @@ -65,7 +65,7 @@ class CustomSyncVectorStore(VectorStore): "failed": [], } - def get_by_ids(self, ids: Sequence[str], /) -> List[Document]: + def get_by_ids(self, ids: Sequence[str], /, **kwargs: Any) -> List[Document]: return [self.store[id] for id in ids if id in self.store] def delete_by_ids(