Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docarray/index/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ def num_docs(self) -> int:
"""Return the number of indexed documents"""
...

@property
def _is_index_empty(self) -> bool:
"""
Check if index is empty by comparing the number of documents to zero.
:return: True if the index is empty, False otherwise.
"""
return self.num_docs() == 0

@abstractmethod
def _del_items(self, doc_ids: Sequence[str]):
"""Delete Documents from the index.
Expand Down Expand Up @@ -1212,7 +1220,7 @@ def subindex_contains(self, item: BaseDoc) -> bool:
:param item: the given BaseDoc
:return: if the given BaseDoc item is contained in the index/subindices
"""
if self.num_docs() == 0:
if self._is_index_empty:
return False

if safe_issubclass(type(item), BaseDoc):
Expand Down
6 changes: 3 additions & 3 deletions docarray/index/backends/in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _rebuild_embedding(self):

Note: '_embedding_map' is a dictionary mapping fields to their corresponding embeddings.
"""
if self.num_docs() == 0:
if self._is_index_empty:
self._embedding_map = dict()
else:
for field_, embedding in self._embedding_map.items():
Expand Down Expand Up @@ -361,7 +361,7 @@ def find(
self._logger.debug(f'Executing `find` for search field {search_field}')
self._validate_search_field(search_field)

if self.num_docs() == 0:
if self._is_index_empty:
return FindResult(documents=[], scores=[]) # type: ignore

config = self._column_infos[search_field].config
Expand Down Expand Up @@ -414,7 +414,7 @@ def find_batched(
self._logger.debug(f'Executing `find_batched` for search field {search_field}')
self._validate_search_field(search_field)

if self.num_docs() == 0:
if self._is_index_empty:
return FindResultBatched(documents=[], scores=[]) # type: ignore

config = self._column_infos[search_field].config
Expand Down