Skip to content

Commit ddd137b

Browse files
committed
Align implementation of SemanticCache.check and .acheck (closes #444)
1 parent 708e7f5 commit ddd137b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

redisvl/extensions/cache/llm/semantic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ async def acheck(
508508
num_results=num_results,
509509
return_score=True,
510510
filter_expression=filter_expression,
511-
normalize_vector_distance=True,
511+
dtype=self._vectorizer.dtype,
512512
)
513513

514514
# Search the cache!

tests/integration/test_llmcache.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,29 @@ async def test_async_store_and_check(cache, vectorizer):
187187
assert "metadata" not in check_result[0]
188188

189189

190+
@pytest.mark.asyncio
191+
async def test_check_acheck_consistency(cache, vectorizer):
192+
"""Test that acheck and check return the same results."""
193+
cache.store(
194+
prompt="Who is the CEO?",
195+
response="John Smith",
196+
)
197+
198+
prompt = "Who is CEO?"
199+
sync_result = cache.check(prompt=prompt)
200+
async_result = await cache.acheck(prompt=prompt)
201+
print(sync_result, async_result, flush=True)
202+
assert sync_result # Both should return a result
203+
assert sync_result == async_result
204+
205+
prompt = "Who is CFO?"
206+
sync_result = cache.check(prompt=prompt)
207+
async_result = await cache.acheck(prompt=prompt)
208+
print(sync_result, async_result, flush=True)
209+
assert not sync_result # Both should return no result
210+
assert sync_result == async_result
211+
212+
190213
def test_return_fields(cache, vectorizer):
191214
prompt = "This is a test prompt."
192215
response = "This is a test response."

0 commit comments

Comments
 (0)