Skip to content
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

Replaced zrangebylex method in the range method #521

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cheesecake100201
Copy link
Contributor

@cheesecake100201 cheesecake100201 commented Nov 25, 2024

What does this PR do?

In short, provide a summary of what this PR does and why. Usually, the relevant context should be present in a linked issue.

  • [Currently redis as a kvstore is bugged, as the range method uses zrangebylex method. zrangebylex method is used when it is a sorted set but we are storing the value using .set method in the redis. This causes an error. Another issue is that zrangebylex method takes 3 args but only 2 are mentioned in the range method. This causes a runtime error. That method has been replaced with the current implementation in the PR ] Addresses issue (Redis persistence store not working  #520 )

Test Plan

Please describe:

  • tests you ran to verify your changes with result summaries.
  • provide instructions so it can be reproduced.
    python llama_stack/apis/agents/client.py localhost 8001 tools_llama_3_1 meta-llama/Llama-3.1-70B-Instruct
Screenshot 2024-11-25 at 2 59 55 PM Screenshot 2024-11-25 at 3 00 33 PM

Have used redis in the run.yaml file as well for the persistence_store. Also enable_session_persistence turned to True for this test.
Have also tested this in a jupyter notebook to make sure the current flow does not work through multiple turns in the same session.

Sources

Please link relevant resources if necessary.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Ran pre-commit to handle lint / formatting issues.
  • Read the contributor guideline,
    Pull Request section?
  • Updated relevant documentation.
  • Wrote necessary unit or integration tests.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 25, 2024

return await self.redis.zrangebylex(start_key, end_key)
for key in keys:
key_str = key.decode("utf-8") if isinstance(key, bytes) else key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the decode necessary? we already using a str as input when setting the key.

Copy link
Contributor Author

@cheesecake100201 cheesecake100201 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when we fetch the keys using .scan() method, the list of keys fetched is of instance bytes. I tested it on my local machine as well and I am getting the list of keys where each key is of type byte.
@dineshyv
image

return await self.redis.zrangebylex(start_key, end_key)
for key in keys:
key_str = key.decode("utf-8") if isinstance(key, bytes) else key
if start_key <= key_str <= end_key:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a more strict pattern like pattern = f"{namespace}[{start_key}-{end_key}]" to only fetch the keys in range instead of having to filter again here?

if matching_keys:
values = await self.redis.mget(matching_keys)
return [
value.decode("utf-8") if isinstance(value, bytes) else value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a decode here since we are taking only strings as input?

@aidando73
Copy link
Contributor

aidando73 commented Dec 8, 2024

This PR passes the error for me

@cheesecake100201
Copy link
Contributor Author

Can you take a look at this PR again?
@dineshyv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants