@@ -592,6 +592,27 @@ def drop_keys(self, keys: Union[str, List[str]]) -> int:
592592 else :
593593 return self ._redis_client .delete (keys ) # type: ignore
594594
595+ def drop_documents (self , ids : Union [str , List [str ]]) -> int :
596+ """Remove documents from the index by their document IDs.
597+
598+ This method converts document IDs to Redis keys automatically by applying
599+ the index's key prefix and separator configuration.
600+
601+ Args:
602+ ids (Union[str, List[str]]): The document ID or IDs to remove from the index.
603+
604+ Returns:
605+ int: Count of documents deleted from Redis.
606+ """
607+ if isinstance (ids , list ):
608+ if not ids :
609+ return 0
610+ keys = [self .key (id ) for id in ids ]
611+ return self ._redis_client .delete (* keys ) # type: ignore
612+ else :
613+ key = self .key (ids )
614+ return self ._redis_client .delete (key ) # type: ignore
615+
595616 def expire_keys (
596617 self , keys : Union [str , List [str ]], ttl : int
597618 ) -> Union [int , List [int ]]:
@@ -1236,6 +1257,28 @@ async def drop_keys(self, keys: Union[str, List[str]]) -> int:
12361257 else :
12371258 return await client .delete (keys )
12381259
1260+ async def drop_documents (self , ids : Union [str , List [str ]]) -> int :
1261+ """Remove documents from the index by their document IDs.
1262+
1263+ This method converts document IDs to Redis keys automatically by applying
1264+ the index's key prefix and separator configuration.
1265+
1266+ Args:
1267+ ids (Union[str, List[str]]): The document ID or IDs to remove from the index.
1268+
1269+ Returns:
1270+ int: Count of documents deleted from Redis.
1271+ """
1272+ client = await self ._get_client ()
1273+ if isinstance (ids , list ):
1274+ if not ids :
1275+ return 0
1276+ keys = [self .key (id ) for id in ids ]
1277+ return await client .delete (* keys )
1278+ else :
1279+ key = self .key (ids )
1280+ return await client .delete (key )
1281+
12391282 async def expire_keys (
12401283 self , keys : Union [str , List [str ]], ttl : int
12411284 ) -> Union [int , List [int ]]:
@@ -1356,7 +1399,7 @@ async def fetch(self, id: str) -> Optional[Dict[str, Any]]:
13561399 async def _aggregate (
13571400 self , aggregation_query : AggregationQuery
13581401 ) -> List [Dict [str , Any ]]:
1359- """Execute an aggretation query and processes the results."""
1402+ """Execute an aggregation query and processes the results."""
13601403 results = await self .aggregate (
13611404 aggregation_query , query_params = aggregation_query .params # type: ignore[attr-defined]
13621405 )
0 commit comments