This commit is contained in:
Eugene Yurtsev
2024-07-12 17:03:24 -04:00
parent b3cf1ae842
commit a596b1b515
4 changed files with 17 additions and 15 deletions

View File

@@ -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:

View File

@@ -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.

View File

@@ -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(

View File

@@ -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(