-
-
Notifications
You must be signed in to change notification settings - Fork 45
[Store] Add PSR-6 support for vector store #257
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
base: main
Are you sure you want to change the base?
Conversation
That is really an interesting idea, since the PSR 6 cache has quite some implementations. I wonder tho if we would still recommend to use that only in testing or development. I would assume that it doesn't scale well with a lot of documents since the search needs to happen in PHP runtime with all documents loaded, right? |
Not sure about the performances side, IMO, that's not a big problem (we already use the Cache layer from Sf for heavy operations, that's not a big deal), If you fear that it can impact applications, we can recommend to use it only in dev/test envs, it's just a documentation concern 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Guikingone - especially for going the extra mile of refactoring/extracting the calculation - def worth it tho 👍
The configuration in the bundle package has been added (better to do it now than in another PR 😄 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces PSR-6 cache support for vector stores by adding a new CacheStore
implementation and refactoring the existing InMemoryStore
to use shared distance calculation logic.
Key changes:
- Refactored distance calculation logic into a separate
DistanceCalculator
class with aDistanceStrategy
enum - Added new
CacheStore
implementation that uses PSR-6 cache interfaces for persistent vector storage - Updated documentation and configuration to include the new cache store option
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/store/src/CacheStore.php |
New PSR-6 cache-based vector store implementation |
src/store/src/DistanceCalculator.php |
Extracted distance calculation logic from InMemoryStore |
src/store/src/DistanceStrategy.php |
Enum defining available distance calculation strategies |
src/store/src/InMemoryStore.php |
Refactored to use shared DistanceCalculator |
src/store/tests/CacheStoreTest.php |
Comprehensive test coverage for CacheStore |
src/store/tests/InMemoryStoreTest.php |
Updated tests to use new DistanceCalculator API |
src/ai-bundle/src/AiBundle.php |
Bundle configuration for cache store integration |
src/ai-bundle/config/options.php |
Configuration schema for cache store |
examples/rag/cache.php |
Example demonstrating cache store usage |
src/store/doc/index.rst |
Documentation updates for cache store |
PS: Both `InMemory` and `PSR-6 cache` vector stores will load all the data into the memory of the PHP process. | ||
They can be used only the amount of data fits in the PHP memory limit, typically for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: Both `InMemory` and `PSR-6 cache` vector stores will load all the data into the memory of the PHP process. | |
They can be used only the amount of data fits in the PHP memory limit, typically for testing. | |
.. note:: | |
Both `InMemory` and `PSR-6 cache` vector stores will load all the data into the | |
memory of the PHP process. They can be used only the amount of data fits in the | |
PHP memory limit, typically for testing. |
|
||
public function add(VectorDocument ...$documents): void | ||
{ | ||
$cacheItem = $this->cache->getItem($this->cacheKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can w use something like:
// The callable will only be executed on a cache miss.
$value = $pool->get('my_cache_key', function (ItemInterface $item): string {
$item->expiresAfter(3600);
// ... do some HTTP request or heavy computations
$computedValue = 'foobar';
return $computedValue;
});
Hi 👋🏻
This PR aims to introduce a
CacheStore
based on PSR-6, it's heavily inspired by theCacheStore
fromMessageStore
layer, this store introduce a refactoring of theInMemoryStore
to use common logic for both stores (as we can't rely on theCacheItemPool
implementation).Thanks for the feedback.