Skip to content

Symfony AI - Store Component

Edit this page

The Store component provides a low-level abstraction for storing and retrieving documents in a vector store.

Installation

1
$ composer require symfony/ai-store

Purpose

A typical use-case in agentic applications is a dynamic context-extension with similar and useful information, for so called Retrieval Augmented Generation (RAG). The Store component implements low-level interfaces, that can be implemented by different concrete and vendor-specific implementations, so called bridges. On top of those bridges, the Store component provides higher level features to populate and query those stores with and for documents.

Indexing

One higher level feature is the Indexer. The purpose of this service is to populate a store with documents. Therefore it accepts one or multiple TextDocument objects, converts them into embeddings and stores them in the used vector store:

1
2
3
4
5
6
use Symfony\AI\Store\Document\TextDocument;
use Symfony\AI\Store\Indexer;

$indexer = new Indexer($platform, $model, $store);
$document = new TextDocument('This is a sample document.');
$indexer->index($document);

You can find more advanced usage in combination with an Agent using the store for RAG in the examples folder:

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.

Supported Stores

Commands

While using the `Store` component in your Symfony application along with the AiBundle, you can use the bin/console ai:store:setup command to initialize the store and bin/console ai:store:drop to clean up the store:

1
2
3
4
5
6
7
8
# config/packages/ai.yaml
ai:
    # ...

    store:
        chroma_db:
            symfonycon:
                collection: 'symfony_blog'
1
2
$ php bin/console ai:store:setup symfonycon
$ php bin/console ai:store:drop symfonycon

Implementing a Bridge

The main extension points of the Store component is the StoreInterface, that defines the methods for adding vectorized documents to the store, and querying the store for documents with a vector.

This leads to a store implementing two methods:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use Symfony\AI\Store\StoreInterface;
use Symfony\AI\Store\Vector;
use Symfony\AI\Store\VectorDocument;

class MyStore implements StoreInterface
{
    public function add(VectorDocument ...$documents): void
    {
        // Implementation to add a document to the store
    }

    public function query(Vector $vector, array $options = []): array
    {
        // Implementation to query the store for documents
        return $documents;
    }
}
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version