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

Improve redis semantic cache implementation #5412

Conversation

tylerhutcherson
Copy link

@tylerhutcherson tylerhutcherson commented Aug 28, 2024

Improve Redis semantic caching

Relevant issues

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation

Changes

  • Use latest version of RedisVL (0.3.2) and fix pydantic & schema version issues
  • Support isolated/customized index names to allow for multitenancy
  • Support arbitrary embedding model in index schema provided through litellm.embeddings module
  • Use built-in SemanticCache extension for cleaner code and processing
  • Add TTL support to redis semantic cache (OOTB feature of Redis rather than a tack-on)

Copy link

vercel bot commented Aug 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 0:26am

Copy link

@rbs333 rbs333 left a comment

Choose a reason for hiding this comment

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

Generally LGTM had a question about the todo

litellm/caching.py Outdated Show resolved Hide resolved
@ishaan-jaff ishaan-jaff changed the base branch from main to litellm_stable_branch_staging August 29, 2024 01:14
Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

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

Is this missing async support @tylerhutcherson ?

If yes, can you add async support on this PR. Majority of users are trying to use this our llm gateway - which requires all async functions

@tylerhutcherson
Copy link
Author

Is this missing async support @tylerhutcherson ?

If yes, can you add async support on this PR. Majority of users are trying to use this our llm gateway - which requires all async functions

Hey @ishaan-jaff @krrishdholakia see my comment here:
#5412 (comment)

Let me know what you think!

@ishaan-jaff
Copy link
Contributor

@tylerhutcherson

Async Support is a hard requirement for LiteLLM. Majority of our users use async. If we merge this and users use this in prod their litellm service will go down. We have seen this before when a non-async function was used.

We're happy to wait on this until redisvl add async support

@tylerhutcherson
Copy link
Author

@tylerhutcherson

Async Support is a hard requirement for LiteLLM. Majority of our users use async. If we merge this and users use this in prod their litellm service will go down. We have seen this before when a non-async function was used.

We're happy to wait on this until redisvl add async support

Understood -- thanks for the clarity. Will see what we can do, thanks!

@tylerhutcherson
Copy link
Author

FYI redis/redis-vl-python#214 We are close to finalizing support.

tylerhutcherson added a commit to redis/redis-vl-python that referenced this pull request Sep 6, 2024
This PR introduces new async compliant methods to the semantic cache
class using lazy index construction. Because the `AsyncSearchIndex`
requires an async redis python client, we needed to construct that class
lazily upon first usage within the semantic cache class. This PR fixes
some unclosed connection errors and is also in support of
BerriAI/litellm#5412 at LiteLLM.
@tylerhutcherson
Copy link
Author

Now that https://github.com/redis/redis-vl-python 0.3.3 is out with async sem cache support.... I have updated this branch to reflect that. Thanks!

@ishaan-jaff @krrishdholakia

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

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

looks good - could you send a screenshot of your tests passing for you locally ? Happy to merge after that

litellm/caching.py Outdated Show resolved Hide resolved
litellm/caching.py Outdated Show resolved Hide resolved
litellm/caching.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

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

looks good - could you send a screenshot of your tests passing for you locally ? Happy to merge after that @tylerhutcherson

@tylerhutcherson
Copy link
Author

looks good - could you send a screenshot of your tests passing for you locally ? Happy to merge after that @tylerhutcherson

Sure thing -- screenshot below. A few caveats:

  • There seems to be some issue with async tests here. The poetry env does not include pytest-asyncio or anything so the test module skips all async tests and throws warnings like this?
litellm/tests/test_caching.py: 20 warnings
  /Users/tyler.hutcherson/Library/Caches/pypoetry/virtualenvs/litellm-g3ANcoZD-py3.11/lib/python3.11/site-packages/_pytest/python.py:183: PytestUnhandledCoroutineWarning: async def functions are not natively supported and have been skipped.
  You need to install a suitable plugin for your async framework, for example:
    - anyio
    - pytest-asyncio
    - pytest-tornasync
    - pytest-trio
    - pytest-twisted
    warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
  • Also I don't have Azure API access nor a dependency called diskcache for these tests... so there are 3 tests that fail (seen below). All of the Redis cases pass using poetry run pytest litellm/tests/test_caching.py.

Screenshot 2024-09-10 at 2 20 24 PM

@ishaan-jaff

@ishaan-jaff ishaan-jaff changed the base branch from litellm_stable_branch_staging to litellm_stable_pr_merges September 11, 2024 00:23
@ishaan-jaff ishaan-jaff merged commit 2b181a7 into BerriAI:litellm_stable_pr_merges Sep 11, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants