Symfony AI - Store Component
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:
- Similarity Search with Cloudflare (RAG)
- Similarity Search with Manticore (RAG)
- Similarity Search with MariaDB (RAG)
- Similarity Search with Meilisearch (RAG)
- Similarity Search with memory storage (RAG)
- Similarity Search with Milvus (RAG)
- Similarity Search with MongoDB (RAG)
- Similarity Search with Neo4j (RAG)
- Similarity Search with Pinecone (RAG)
- Similarity Search with Qdrant (RAG)
- Similarity Search with SurrealDB (RAG)
- Similarity Search with Symfony Cache (RAG)
- Similarity Search with Typesense (RAG)
- Similarity Search with Weaviate (RAG)
- Similarity Search with Supabase (RAG)
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
- Azure AI Search
- Chroma (requires
codewithkyrian/chromadb-phpas additional dependency) - Cloudflare
- InMemory
- Manticore
- MariaDB (requires
ext-pdo) - Meilisearch
- Milvus
- MongoDB Atlas (requires
mongodb/mongodbas additional dependency) - Neo4j
- Pinecone (requires
probots-io/pinecone-phpas additional dependency) - Postgres (requires
ext-pdo) - Qdrant
- Supabase (requires manual database setup)
- SurrealDB
- Symfony Cache (requires
symfony/cacheas additional dependency) - Typesense
- Weaviate
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;
}
}