Skip to content

Fix semantic cache with empty metadata #201

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

Merged
merged 4 commits into from
Aug 16, 2024
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
4 changes: 2 additions & 2 deletions redisvl/extensions/llmcache/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def non_empty_metadata(cls, v):
def to_dict(self) -> Dict:
data = self.dict(exclude_none=True)
data["prompt_vector"] = array_to_buffer(self.prompt_vector)
if self.metadata:
if self.metadata is not None:
data["metadata"] = serialize(self.metadata)
if self.filters:
if self.filters is not None:
data.update(self.filters)
del data["filters"]
return data
Expand Down
2 changes: 0 additions & 2 deletions redisvl/extensions/llmcache/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ def check(
key = cache_search_result["id"]
self._refresh_ttl(key)

print(cache_search_result, flush=True)

# Create cache hit
cache_hit = CacheHit(**cache_search_result)
cache_hit_dict = {
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_llmcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ def test_store_with_metadata(cache, vectorizer):
assert check_result[0]["prompt"] == prompt


def test_store_with_empty_metadata(cache, vectorizer):
prompt = "This is another test prompt."
response = "This is another test response."
metadata = {}
vector = vectorizer.embed(prompt)

cache.store(prompt, response, vector=vector, metadata=metadata)
check_result = cache.check(vector=vector, num_results=1)

assert len(check_result) == 1
print(check_result, flush=True)
assert check_result[0]["response"] == response
assert check_result[0]["metadata"] == metadata
assert check_result[0]["prompt"] == prompt


def test_store_with_invalid_metadata(cache, vectorizer):
prompt = "This is another test prompt."
response = "This is another test response."
Expand Down
Loading