-
Notifications
You must be signed in to change notification settings - Fork 99
perf: replace DELETE with UNLINK in EmbeddingsCache for better memory management #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -512,6 +512,8 @@ def drop(self, content: bytes | str, model_name: str) -> None: | |
| def drop_by_key(self, key: str) -> None: | ||
| """Remove an embedding from the cache by its Redis key. | ||
|
|
||
| Uses UNLINK instead of DELETE for better performance by freeing memory asynchronously. | ||
|
|
||
| Args: | ||
| key (str): The full Redis key for the embedding. | ||
|
|
||
|
|
@@ -520,7 +522,7 @@ def drop_by_key(self, key: str) -> None: | |
| cache.drop_by_key("embedcache:1234567890abcdef") | ||
| """ | ||
| client = self._get_redis_client() | ||
| client.delete(key) | ||
| client.unlink(key) | ||
|
|
||
| def mdrop_by_keys(self, keys: list[str]) -> None: | ||
| """Remove multiple embeddings from the cache by their Redis keys. | ||
|
|
@@ -542,7 +544,7 @@ def mdrop_by_keys(self, keys: list[str]) -> None: | |
|
|
||
| with client.pipeline(transaction=False) as pipeline: | ||
| for key in keys: | ||
| pipeline.delete(key) | ||
| pipeline.unlink(key) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This queues one single-key |
||
| pipeline.execute() | ||
|
|
||
| def mdrop(self, contents: Iterable[bytes | str], model_name: str) -> None: | ||
|
|
@@ -883,7 +885,7 @@ async def amdrop_by_keys(self, keys: list[str]) -> None: | |
| return | ||
|
|
||
| client = await self._get_async_redis_client() | ||
| await client.delete(*keys) | ||
| await client.unlink(*keys) | ||
|
|
||
| async def amdrop(self, contents: Iterable[bytes | str], model_name: str) -> None: | ||
| """Async remove multiple embeddings from the cache by their contents and model name. | ||
|
|
@@ -982,4 +984,4 @@ async def adrop_by_key(self, key: str) -> None: | |
| await cache.adrop_by_key("embedcache:1234567890abcdef") | ||
| """ | ||
| client = await self._get_async_redis_client() | ||
| await client.delete(key) | ||
| await client.unlink(key) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please drop these two lines. Which command runs isn't part of the method's contract, and
docs/api/cache.rst:68autoclasses this class, so the note ships to docs.redisvl.com. It also only describes one of the four methods you changed.