Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Guikingone
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues None
License MIT

Hi 👋🏻

This PR aims to introduce a CacheStore based on PSR-6, it's heavily inspired by the CacheStore from MessageStore layer, this store introduce a refactoring of the InMemoryStore to use common logic for both stores (as we can't rely on the CacheItemPool implementation).

Thanks for the feedback.

@fabpot fabpot added Status: Needs Review Feature New feature Store Issues & PRs about the AI Store component labels Aug 4, 2025
@chr-hertel
Copy link
Member

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?

@Guikingone
Copy link
Contributor Author

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 🤔

@Guikingone Guikingone requested a review from GromNaN August 5, 2025 09:16
Copy link
Member

@chr-hertel chr-hertel left a 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 👍

@Guikingone
Copy link
Contributor Author

Guikingone commented Aug 5, 2025

The configuration in the bundle package has been added (better to do it now than in another PR 😄 )

Copy link

@Copilot Copilot AI left a 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 a DistanceStrategy 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

Comment on lines +50 to +51
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
Copy link
Contributor

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;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature Status: Needs Review Store Issues & PRs about the AI Store component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants