Skip to content
Open
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
13 changes: 13 additions & 0 deletions haystack/document_stores/in_memory/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,19 @@ async def delete_documents_async(self, document_ids: list[str]) -> None:
self.executor, lambda: self.delete_documents(document_ids=document_ids)
)

async def delete_by_filter_async(self, filters: dict[str, Any]) -> int:
"""
Deletes all documents that match the provided filters.

:param filters: The filters to apply to select documents for deletion.
For filter syntax, see filter_documents.
:returns: The number of documents deleted.
:raises ValueError: if filters have invalid syntax.
"""
return await asyncio.get_running_loop().run_in_executor(
self.executor, lambda: self.delete_by_filter(filters=filters)
)

async def update_by_filter_async(self, filters: dict[str, Any], meta: dict[str, Any]) -> int:
"""
Updates the metadata of all documents that match the provided filters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Added the missing ``delete_by_filter_async()`` method to ``InMemoryDocumentStore``.
Previously, only the sync ``delete_by_filter()`` was available, unlike the other methods of the store,
which all have an async counterpart. The new method runs ``delete_by_filter()`` in the store's
thread-pool executor and returns the number of deleted documents.
2 changes: 2 additions & 0 deletions test/document_stores/test_in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CountDocumentsByFilterAsyncTest,
CountUniqueMetadataByFilterAsyncTest,
DeleteAllAsyncTest,
DeleteByFilterAsyncTest,
DeleteDocumentsAsyncTest,
FilterDocumentsAsyncTest,
GetMetadataFieldMinMaxAsyncTest,
Expand All @@ -52,6 +53,7 @@ class TestMemoryDocumentStore(
CountDocumentsAsyncTest,
WriteDocumentsAsyncTest,
DeleteAllAsyncTest,
DeleteByFilterAsyncTest,
DeleteDocumentsAsyncTest,
CountDocumentsByFilterTest,
CountUniqueMetadataByFilterAsyncTest,
Expand Down