Skip to content

Commit cfbd8a4

Browse files
committed
fix(store): qdrant arguments moved to optionals
1 parent 5f498f5 commit cfbd8a4

File tree

4 files changed

+303
-36
lines changed

4 files changed

+303
-36
lines changed

src/ai-bundle/config/options.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@
499499
->arrayPrototype()
500500
->children()
501501
->stringNode('service')->cannotBeEmpty()->defaultValue('cache.app')->end()
502-
->stringNode('cache_key')->end()
502+
->stringNode('cache_key')
503+
->info('The name of the store will be used if the key is not set')
504+
->end()
503505
->stringNode('strategy')->end()
504506
->end()
505507
->end()
@@ -651,7 +653,7 @@
651653
->stringNode('collection_name')->cannotBeEmpty()->end()
652654
->integerNode('dimensions')->end()
653655
->stringNode('distance')->end()
654-
->booleanNode('async')->defaultFalse()->end()
656+
->booleanNode('async')->end()
655657
->end()
656658
->end()
657659
->end()
@@ -772,20 +774,15 @@
772774
->end()
773775
->arrayNode('message_store')
774776
->children()
775-
->arrayNode('memory')
776-
->useAttributeAsKey('name')
777-
->arrayPrototype()
778-
->children()
779-
->stringNode('identifier')->cannotBeEmpty()->end()
780-
->end()
781-
->end()
782-
->end()
783777
->arrayNode('cache')
784778
->useAttributeAsKey('name')
785779
->arrayPrototype()
786780
->children()
787781
->stringNode('service')->cannotBeEmpty()->defaultValue('cache.app')->end()
788-
->stringNode('key')->end()
782+
->stringNode('key')
783+
->info('The name of the message store will be used if the key is not set')
784+
->end()
785+
->integerNode('ttl')->end()
789786
->end()
790787
->end()
791788
->end()
@@ -799,6 +796,14 @@
799796
->end()
800797
->end()
801798
->end()
799+
->arrayNode('memory')
800+
->useAttributeAsKey('name')
801+
->arrayPrototype()
802+
->children()
803+
->stringNode('identifier')->cannotBeEmpty()->end()
804+
->end()
805+
->end()
806+
->end()
802807
->arrayNode('pogocache')
803808
->useAttributeAsKey('name')
804809
->arrayPrototype()

src/ai-bundle/src/AiBundle.php

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use Symfony\AI\AiBundle\Profiler\TraceableToolbox;
3838
use Symfony\AI\AiBundle\Security\Attribute\IsGrantedTool;
3939
use Symfony\AI\Chat\Bridge\HttpFoundation\SessionStore;
40+
use Symfony\AI\Chat\Bridge\Local\CacheStore as CacheMessageStore;
4041
use Symfony\AI\Chat\Bridge\Meilisearch\MessageStore as MeilisearchMessageStore;
4142
use Symfony\AI\Chat\Bridge\Pogocache\MessageStore as PogocacheMessageStore;
4243
use Symfony\AI\Chat\Bridge\Redis\MessageStore as RedisMessageStore;
@@ -917,10 +918,6 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
917918
new Definition(DistanceCalculator::class),
918919
];
919920

920-
if (\array_key_exists('cache_key', $store) && null !== $store['cache_key']) {
921-
$arguments[2] = $store['cache_key'];
922-
}
923-
924921
if (\array_key_exists('strategy', $store) && null !== $store['strategy']) {
925922
if (!$container->hasDefinition('ai.store.distance_calculator.'.$name)) {
926923
$distanceCalculatorDefinition = new Definition(DistanceCalculator::class);
@@ -932,10 +929,14 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
932929
$arguments[1] = new Reference('ai.store.distance_calculator.'.$name);
933930
}
934931

932+
$arguments[2] = \array_key_exists('cache_key', $store) && null !== $store['cache_key']
933+
? $store['cache_key']
934+
: $name;
935+
935936
$definition = new Definition(CacheStore::class);
936937
$definition
937-
->addTag('ai.store')
938-
->setArguments($arguments);
938+
->setArguments($arguments)
939+
->addTag('ai.store');
939940

940941
$container->setDefinition('ai.store.'.$type.'.'.$name, $definition);
941942
$container->registerAliasForArgument('ai.store.'.$type.'.'.$name, StoreInterface::class, $name);
@@ -1470,32 +1471,22 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
14701471
*/
14711472
private function processMessageStoreConfig(string $type, array $messageStores, ContainerBuilder $container): void
14721473
{
1473-
if ('memory' === $type) {
1474-
foreach ($messageStores as $name => $messageStore) {
1475-
$definition = new Definition(InMemoryStore::class);
1476-
$definition
1477-
->setArgument(0, $messageStore['identifier'])
1478-
->addTag('ai.message_store');
1479-
1480-
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);
1481-
$container->registerAliasForArgument('ai.message_store.'.$type.'.'.$name, MessageStoreInterface::class, $name);
1482-
$container->registerAliasForArgument('ai.message_store.'.$type.'.'.$name, MessageStoreInterface::class, $type.'_'.$name);
1483-
}
1484-
}
1485-
14861474
if ('cache' === $type) {
14871475
foreach ($messageStores as $name => $messageStore) {
14881476
$arguments = [
14891477
new Reference($messageStore['service']),
1478+
$messageStore['key'] ?? $name,
14901479
];
14911480

1492-
if (\array_key_exists('key', $messageStore)) {
1493-
$arguments['key'] = $messageStore['key'];
1481+
if (\array_key_exists('ttl', $messageStore)) {
1482+
$arguments[2] = $messageStore['ttl'];
14941483
}
14951484

1496-
$definition = new Definition(CacheStore::class);
1485+
$definition = new Definition(CacheMessageStore::class);
14971486
$definition
1487+
->setLazy(true)
14981488
->setArguments($arguments)
1489+
->addTag('proxy', ['interface' => MessageStoreInterface::class])
14991490
->addTag('ai.message_store');
15001491

15011492
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);
@@ -1508,12 +1499,29 @@ private function processMessageStoreConfig(string $type, array $messageStores, C
15081499
foreach ($messageStores as $name => $messageStore) {
15091500
$definition = new Definition(MeilisearchMessageStore::class);
15101501
$definition
1502+
->setLazy(true)
15111503
->setArguments([
15121504
$messageStore['endpoint'],
15131505
$messageStore['api_key'],
15141506
new Reference(ClockInterface::class),
15151507
$messageStore['index_name'],
15161508
])
1509+
->addTag('proxy', ['interface' => MessageStoreInterface::class])
1510+
->addTag('ai.message_store');
1511+
1512+
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);
1513+
$container->registerAliasForArgument('ai.message_store.'.$type.'.'.$name, MessageStoreInterface::class, $name);
1514+
$container->registerAliasForArgument('ai.message_store.'.$type.'.'.$name, MessageStoreInterface::class, $type.'_'.$name);
1515+
}
1516+
}
1517+
1518+
if ('memory' === $type) {
1519+
foreach ($messageStores as $name => $messageStore) {
1520+
$definition = new Definition(InMemoryStore::class);
1521+
$definition
1522+
->setLazy(true)
1523+
->setArgument(0, $messageStore['identifier'])
1524+
->addTag('proxy', ['interface' => MessageStoreInterface::class])
15171525
->addTag('ai.message_store');
15181526

15191527
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);
@@ -1526,12 +1534,14 @@ private function processMessageStoreConfig(string $type, array $messageStores, C
15261534
foreach ($messageStores as $name => $messageStore) {
15271535
$definition = new Definition(PogocacheMessageStore::class);
15281536
$definition
1537+
->setLazy(true)
15291538
->setArguments([
15301539
new Reference('http_client'),
15311540
$messageStore['endpoint'],
15321541
$messageStore['password'],
15331542
$messageStore['key'],
15341543
])
1544+
->addTag('proxy', ['interface' => MessageStoreInterface::class])
15351545
->addTag('ai.message_store');
15361546

15371547
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);
@@ -1551,11 +1561,13 @@ private function processMessageStoreConfig(string $type, array $messageStores, C
15511561

15521562
$definition = new Definition(RedisMessageStore::class);
15531563
$definition
1564+
->setLazy(true)
15541565
->setArguments([
15551566
$redisClient,
15561567
$messageStore['index_name'],
15571568
new Reference('serializer'),
15581569
])
1570+
->addTag('proxy', ['interface' => MessageStoreInterface::class])
15591571
->addTag('ai.message_store');
15601572

15611573
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);
@@ -1568,10 +1580,12 @@ private function processMessageStoreConfig(string $type, array $messageStores, C
15681580
foreach ($messageStores as $name => $messageStore) {
15691581
$definition = new Definition(SessionStore::class);
15701582
$definition
1583+
->setLazy(true)
15711584
->setArguments([
15721585
new Reference('request_stack'),
15731586
$messageStore['identifier'],
15741587
])
1588+
->addTag('proxy', ['interface' => MessageStoreInterface::class])
15751589
->addTag('ai.message_store');
15761590

15771591
$container->setDefinition('ai.message_store.'.$type.'.'.$name, $definition);

0 commit comments

Comments
 (0)