Skip to content

Commit 850aa84

Browse files
committed
minor #650 [AI Bundle] Document store dependency injection improvement (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [AI Bundle] Document store dependency injection improvement | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | yes | Issues | Follows #641 | License | MIT Add documentation for the improved store alias functionality that allows multiple stores with the same name across different types. The feature provides both simple aliases and type-prefixed aliases for flexible dependency injection without conflicts. Commits ------- 46d92ab [AI Bundle] Document store dependency injection improvement
2 parents 498745c + 46d92ab commit 850aa84

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/ai-bundle/doc/index.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,55 @@ Configuration
145145
vectorizer: 'ai.vectorizer.mistral_embeddings'
146146
store: 'ai.store.memory.research'
147147
148+
Store Dependency Injection
149+
--------------------------
150+
151+
When using multiple stores in your application, the AI Bundle provides flexible dependency injection through store aliases.
152+
This allows you to inject specific stores into your services without conflicts, even when stores share the same name across different types.
153+
154+
For each configured store, the bundle automatically creates two types of aliases:
155+
156+
1. **Simple alias**: ``StoreInterface $storeName`` - Direct reference by store name
157+
2. **Type-prefixed alias**: ``StoreInterface $typeStoreName`` - Reference with store type prefix in camelCase
158+
159+
.. code-block:: yaml
160+
161+
ai:
162+
store:
163+
memory:
164+
main:
165+
strategy: 'cosine'
166+
products:
167+
strategy: 'manhattan'
168+
chroma_db:
169+
main:
170+
collection: 'documents'
171+
172+
From the configuration above, the following aliases are automatically registered:
173+
174+
- ``StoreInterface $main`` - References the memory store (first occurrence)
175+
- ``StoreInterface $memoryMain`` - Explicitly references the memory store
176+
- ``StoreInterface $chromaDbMain`` - Explicitly references the chroma_db store
177+
- ``StoreInterface $products`` - References the memory products store
178+
- ``StoreInterface $memoryProducts`` - Explicitly references the memory products store
179+
180+
You can inject stores into your services using the generated aliases::
181+
182+
use Symfony\AI\Store\StoreInterface;
183+
184+
final readonly class DocumentService
185+
{
186+
public function __construct(
187+
private StoreInterface $main, // Uses memory store (first occurrence)
188+
private StoreInterface $chromaDbMain, // Explicitly uses chroma_db store
189+
private StoreInterface $memoryProducts, // Explicitly uses memory products store
190+
) {
191+
}
192+
}
193+
194+
When multiple stores share the same name (like ``main`` in the example), the simple alias (``$main``) will reference the first occurrence.
195+
Use type-prefixed aliases (``$memoryMain``, ``$chromaDbMain``) for explicit disambiguation.
196+
148197
Model Configuration
149198
-------------------
150199

0 commit comments

Comments
 (0)