Skip to content

Filtering with Tag type data is not working in SemanticCache #207

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

Closed
simon-enosis opened this issue Aug 23, 2024 · 3 comments · Fixed by #208
Closed

Filtering with Tag type data is not working in SemanticCache #207

simon-enosis opened this issue Aug 23, 2024 · 3 comments · Fixed by #208
Assignees
Labels
bug Something isn't working

Comments

@simon-enosis
Copy link

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.

@tylerhutcherson
Copy link
Collaborator

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!

@justin-cechmanek justin-cechmanek linked a pull request Aug 23, 2024 that will close this issue
@simon-enosis
Copy link
Author

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.

@justin-cechmanek
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants