-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Core] implement redis cache mode #1222
Conversation
f5f9d39
to
17d2c9e
Compare
@microsoft-github-policy-service agree company="Regrello" |
17d2c9e
to
7cbead0
Compare
I agree. This will certainly cause problems in future if not unified. |
@sonichi @vijaykramesh @davorrunje Sorry I was incorrect to say that Redis and DiskCache will have different exit behaviors. I tested myself and there is no difference. Both caches will stay alive and re-opens once you use it again. |
I pushed another commit to make sure |
* implement redis cache mode, if redis_url is set in the llm_config then it will try to use this. also adds a test to validate both the existing and the redis cache behavior. * PR feedback, add unit tests * more PR feedback, move the new style cache to a context manager * Update agent_chat.md * more PR feedback, remove tests from contrib and have them run with the normal jobs * doc * updated * Update website/docs/Use-Cases/agent_chat.md Co-authored-by: Chi Wang <[email protected]> * update docs * update docs; let openaiwrapper to use cache object * typo * Update website/docs/Use-Cases/enhanced_inference.md Co-authored-by: Chi Wang <[email protected]> * save previous client cache and reset it after send/a_send * a_run_chat --------- Co-authored-by: Vijay Ramesh <[email protected]> Co-authored-by: Eric Zhu <[email protected]> Co-authored-by: Chi Wang <[email protected]>
* implement redis cache mode, if redis_url is set in the llm_config then it will try to use this. also adds a test to validate both the existing and the redis cache behavior. * PR feedback, add unit tests * more PR feedback, move the new style cache to a context manager * Update agent_chat.md * more PR feedback, remove tests from contrib and have them run with the normal jobs * doc * updated * Update website/docs/Use-Cases/agent_chat.md Co-authored-by: Chi Wang <[email protected]> * update docs * update docs; let openaiwrapper to use cache object * typo * Update website/docs/Use-Cases/enhanced_inference.md Co-authored-by: Chi Wang <[email protected]> * save previous client cache and reset it after send/a_send * a_run_chat --------- Co-authored-by: Vijay Ramesh <[email protected]> Co-authored-by: Eric Zhu <[email protected]> Co-authored-by: Chi Wang <[email protected]>
Why are these changes needed?
This adds a redis mode to the cache. This way I can have multiple processes in separate containers running the same application (that is using autogen) and they can share LLM cache (vs in the current disk cache implementation the SQLIte instance ends up being machine local and can't be easily shared across multiple containers/pods).
The actual redis caching is using pickling, same as the disk cache implementation uses. So the cache should be functionally equivalent to the disk cache version.
Docs added inline and then also agent_chat.md:
LLM Caching
Legacy Disk Cache
By default, you can specify a
cache_seed
in yourllm_config
in order to take advantage of a local DiskCache backed cache. This cache will be used to store the results of your LLM calls, and will be used to return results for the same input without making a call to the LLM. This is useful for saving on compute costs, and for speeding up inference.Setting this
cache_seed
param toNone
will disable the cache.Configurable Context Manager
A new configurable context manager allows you to easily turn on and off LLM cache, using either DiskCache or Redis. All LLM agents inside the context manager will use the same cache.
Here's an example of the new integration test running in CI (note I had to setup my fork to get it to run, I think it will only run when it is on
main
that is being merged into? - and in my fork the other tests fail due to my OAI_CONFIG_LIST not being correct.Integration test coverage for the new code I added:
And then per PR feedback I added some unit tests for the cache implementations.
Related issue number
Checks