|
| 1 | +Symfony AI - Store Component |
| 2 | +============================ |
| 3 | + |
| 4 | +The Store component provides a low-level abstraction for storing and retrieving documents in a vector store. |
| 5 | + |
| 6 | +Installation |
| 7 | +------------ |
| 8 | + |
| 9 | +Install the bundle using Composer: |
| 10 | + |
| 11 | +.. code-block:: terminal |
| 12 | +
|
| 13 | + $ composer require symfony/ai-store |
| 14 | +
|
| 15 | +Purpose |
| 16 | +------- |
| 17 | + |
| 18 | +A typical use-case in agentic applications is a dynamic context-extension with similar and useful information, for so |
| 19 | +called **Retrieval Augmented Generation** (RAG). The Store component implements low-level interfaces, that can be |
| 20 | +implemented by different concrete and vendor-specific implementations, so called bridges. |
| 21 | +On top of those bridges, the Store component provides higher level features to populate and query those stores with and |
| 22 | +for documents. |
| 23 | + |
| 24 | +Embedder |
| 25 | +-------- |
| 26 | + |
| 27 | +One higher level feature is the ``Symfony\AI\Store\Embedder``. The purpose of this service is to populate a store with documents. |
| 28 | +Therefore it accepts one or multiple ``Symfony\AI\Store\Document\TextDocument`` objects, converts them into embeddings and stores them in the |
| 29 | +used vector store. |
| 30 | + |
| 31 | +Simple usage example: |
| 32 | + |
| 33 | +.. code-block: php |
| 34 | +
|
| 35 | + use Symfony\AI\Store\Embedder; |
| 36 | + use Symfony\AI\Store\Document\TextDocument; |
| 37 | +
|
| 38 | + $embedder = new Embedder($storeBridge); |
| 39 | + $document = new TextDocument('This is a sample document.'); |
| 40 | + $embedder->embed($document); |
| 41 | +
|
| 42 | +You can find more advanced usage in combination with an Agent using the store for RAG in the examples folder: |
| 43 | + |
| 44 | +1. `Similarity Search with MongoDB (RAG)`_ |
| 45 | +1. `Similarity Search with Pinecone (RAG)`_ |
| 46 | + |
| 47 | +Supported Stores |
| 48 | +---------------- |
| 49 | + |
| 50 | +1. Azure Search |
| 51 | +1. ChromaDB |
| 52 | +1. MongoDB |
| 53 | +1. Pinecone |
| 54 | + |
| 55 | +See `GitHub`_ for planned stores. |
| 56 | + |
| 57 | + |
| 58 | +Implementing a Bridge |
| 59 | +--------------------- |
| 60 | + |
| 61 | +The main extension points of the Store component are |
| 62 | + |
| 63 | +1. **Symfony\AI\Store\StoreInterface**: That takes care of adding documents to the store |
| 64 | +1. **Symfony\AI\Store\VectorStoreInterface**: That takes care of querying the store for documents |
| 65 | + |
| 66 | +This leads to a store implementing two methods: |
| 67 | + |
| 68 | +.. code-block: php |
| 69 | +
|
| 70 | + use Symfony\AI\Store\StoreInterface; |
| 71 | + use Symfony\AI\Store\VectorStoreInterface; |
| 72 | +
|
| 73 | + class MyStore implements StoreInterface, VectorStoreInterface |
| 74 | + { |
| 75 | + public function add(VectorDocument ...$documents): void |
| 76 | + { |
| 77 | + // Implementation to add a document to the store |
| 78 | + } |
| 79 | +
|
| 80 | + public function query(Vector $vector, array $options = [], ?float $minScore = null): array |
| 81 | + { |
| 82 | + // Implementation to query the store for documents |
| 83 | + return []; |
| 84 | + } |
| 85 | + } |
| 86 | +
|
| 87 | +.. _`Similarity Search with MongoDB (RAG)`: https://github.com/symfony/ai/blob/main/examples/store/mongodb-similarity-search.php |
| 88 | +.. _`Similarity Search with Pinecone (RAG)`: https://github.com/symfony/ai/blob/main/examples/store/pinecone-similarity-search.php |
| 89 | +.. _`GitHub`: https://github.com/symfony/ai/issues/16 |
0 commit comments