redis/redis-vl-python

Filtering with Tag type data is not working in SemanticCache

Closed this issue · 3 comments

I am using SemanticCache to cache the LLM responses in my application, following this document. However, I am not getting any results using the Tag type filter.

Here are some snippets of my code:

# Intitialization
llm_cache = SemanticCache(
      name='llmcache',
      prefix='llmcache',
      redis_url='redis://localhost:6379',
      distance_threshold=0.03,
      vectorizer=vectorizer, # using OpenAITextVectorizer
      filterable_fields=[{"name": "user_id", "type": "tag"}]
)

# Storing
llm_cache.store(
    prompt=question,
    response=answer,
    filters={"user_id": "abc"},
)

# Fetching
access_role_filter = Tag("user_id") == "abc"
cache = self.llm_cache.check(prompt=question, filter_expression=access_role_filter)

If I try to fetch without applying the filter, I am able to retrieve all the entries.

Hi @simon-enosis thanks for opening this. We're looking into it. Currently, I'm unable to reproduce this issue on redisvl==0.3.1.

One possibility is that this semantic cache attached to an old index, maybe created in an earlier version of redisvl without the filter? Try creating the cache with a different name than llmcache (you can also drop the prefix arg).

Also, can you confirm the redisvl version? The redis-py version? And lastly, what is the output of MODULE LIST command on the database using the redis cli?

Thanks!

Hello @tylerhutcherson, thank you for your prompt response. It appears that if we create an index with a specific configuration and then attempt to add or modify the configuration later, the changes do not apply or overwrite the existing settings. Based on your reply, I removed the previous index and recreated it with the same name, and it is now working correctly.

Regarding the redisvl version, I initially tried version 0.3.1, but I encountered this issue. Since your documentation was last updated for version 0.3.0 with a stable tag, I downgraded it to 0.3.0 and am currently using this version.

I am closing this issue as it has been resolved, but it would be very helpful if this information is prominently highlighted in the documentation.

Hi @simon-enosis, we recently mades some updates included in release 0.3.2 that address this. We welcome any feedback.
Thanks!