Skip to content

Add cachetools key-value store #18883

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

Conversation

Florian-BACHO
Copy link
Contributor

Description

I propose a new CachetoolsKVStore class, a key-value store that wraps cachetools Cache objects. This will allow creating different implementations of cache stores, mainly in the context of the BaseEmbedding's new caching system being implemented in PR #18864.

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 28, 2025
@AstraBert
Copy link
Member

AstraBert commented May 28, 2025

Thanks a lot @Florian-BACHO!
Once we merge the other PR, we will merge this one! :))

@AstraBert AstraBert self-assigned this May 28, 2025
@AstraBert AstraBert self-requested a review May 28, 2025 14:00
readme = "README.md"
license = "MIT"
dependencies = [
"cachetools>=6.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thoughts on cachetools-utils? https://github.com/zx80/cachetools-utils

Its the same, but extended for supporting redis and memcache (which feels like it would make this class more useful)

@AstraBert AstraBert removed their request for review May 28, 2025 15:24
Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

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

I think, apart from the use of cachetools-utils instead of cachetools as already Logan pointed out, this is a good PR!
They only thing I would add is a README, at least to give an idea of how to initialize this :))

@Florian-BACHO
Copy link
Contributor Author

Florian-BACHO commented May 28, 2025

Thanks for your feedbacks @AstraBert and @logan-markewich !
I agree about supporting cachetools-utils. I had a look at the code of both packages and every cache class essentially inherits MutableMapping. Thinking about it, KVStores are somehow wrappers around MutableMapping objects. The best example being the SimpleKVStore, which stores key-value pairs in dictionaries. I wonder if it would be a good idea to create a generic MutableMappingKVStore class in the core package that would take a MutableMapping type and init args/kwargs (same way as my CachetoolKVStore). The SimpleKVStore could then inherit from this class by specialising with a dictionary. That would then enable anyone to easily create new stores with mappable objects, including all the different caches mentioned before. What do you think?

@AstraBert
Copy link
Member

Hey there @Florian-BACHO,

My sense is that this would require discarding the BaseKVStore, or refactoring it as the MutableMapping store that you propose: it might be an idea for future releases, but for now I'd keep things as they are :))

@Florian-BACHO
Copy link
Contributor Author

My sense is that this would require discarding the BaseKVStore, or refactoring it as the MutableMapping store that you propose

This is something that crossed my mind but so many kv stores already inherit BaseKVStore that it would require a lot of refactoring... Maybe an intermediate class that the SimpleKVStore would inherit could be the solution but it would require rethinking the inheritance hierarchy a little bit, which might be a breaking change...

@Florian-BACHO Florian-BACHO mentioned this pull request May 29, 2025
14 tasks
@Florian-BACHO
Copy link
Contributor Author

@AstraBert @logan-markewich I opened a new PR (#18893) with an alternative approach that is more generic.
Feel free to choose the approach that is best according to you.

@Florian-BACHO Florian-BACHO deleted the add_cachetools_kvstore branch June 2, 2025 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants