@@ -910,7 +910,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
910910 * @param array<string, mixed> $stores
911911 * @param array<string, mixed> $setupStoresOptions
912912 */
913- private function processStoreConfig (string $ type , array $ stores , ContainerBuilder $ container , &$ setupStoresOptions ): void
913+ private function processStoreConfig (string $ type , array $ stores , ContainerBuilder $ container , array &$ setupStoresOptions ): void
914914 {
915915 if ('azure_search ' === $ type ) {
916916 foreach ($ stores as $ name => $ store ) {
@@ -928,8 +928,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
928928
929929 $ definition = new Definition (AzureSearchStore::class);
930930 $ definition
931- ->addTag ('ai.store ' )
932- ->setArguments ($ arguments );
931+ ->setLazy (true )
932+ ->setArguments ($ arguments )
933+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
934+ ->addTag ('ai.store ' );
933935
934936 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
935937 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -942,11 +944,13 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
942944 $ arguments = [
943945 new Reference ($ store ['service ' ]),
944946 new Definition (DistanceCalculator::class),
947+ $ store ['cache_key ' ] ?? $ name ,
945948 ];
946949
947950 if (\array_key_exists ('strategy ' , $ store ) && null !== $ store ['strategy ' ]) {
948951 if (!$ container ->hasDefinition ('ai.store.distance_calculator. ' .$ name )) {
949952 $ distanceCalculatorDefinition = new Definition (DistanceCalculator::class);
953+ $ distanceCalculatorDefinition ->setLazy (true );
950954 $ distanceCalculatorDefinition ->setArgument (0 , DistanceStrategy::from ($ store ['strategy ' ]));
951955
952956 $ container ->setDefinition ('ai.store.distance_calculator. ' .$ name , $ distanceCalculatorDefinition );
@@ -955,13 +959,11 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
955959 $ arguments [1 ] = new Reference ('ai.store.distance_calculator. ' .$ name );
956960 }
957961
958- $ arguments [2 ] = \array_key_exists ('cache_key ' , $ store ) && null !== $ store ['cache_key ' ]
959- ? $ store ['cache_key ' ]
960- : $ name ;
961-
962962 $ definition = new Definition (CacheStore::class);
963963 $ definition
964+ ->setLazy (true )
964965 ->setArguments ($ arguments )
966+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
965967 ->addTag ('ai.store ' );
966968
967969 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
@@ -974,10 +976,12 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
974976 foreach ($ stores as $ name => $ store ) {
975977 $ definition = new Definition (ChromaDbStore::class);
976978 $ definition
979+ ->setLazy (true )
977980 ->setArguments ([
978981 new Reference ($ store ['client ' ]),
979982 $ store ['collection ' ],
980983 ])
984+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
981985 ->addTag ('ai.store ' );
982986
983987 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
@@ -1000,11 +1004,13 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10001004
10011005 $ definition = new Definition (ClickHouseStore::class);
10021006 $ definition
1007+ ->setLazy (true )
10031008 ->setArguments ([
10041009 $ httpClient ,
10051010 $ store ['database ' ],
10061011 $ store ['table ' ],
10071012 ])
1013+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
10081014 ->addTag ('ai.store ' )
10091015 ;
10101016
@@ -1037,8 +1043,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10371043
10381044 $ definition = new Definition (CloudflareStore::class);
10391045 $ definition
1040- ->addTag ('ai.store ' )
1041- ->setArguments ($ arguments );
1046+ ->setLazy (true )
1047+ ->setArguments ($ arguments )
1048+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1049+ ->addTag ('ai.store ' );
10421050
10431051 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
10441052 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1076,7 +1084,9 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10761084
10771085 $ definition = new Definition (ManticoreStore::class);
10781086 $ definition
1087+ ->setLazy (true )
10791088 ->addTag ('ai.store ' )
1089+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
10801090 ->setArguments ($ arguments );
10811091
10821092 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
@@ -1087,25 +1097,24 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10871097
10881098 if ('mariadb ' === $ type ) {
10891099 foreach ($ stores as $ name => $ store ) {
1090- $ arguments = [
1091- new Reference (\sprintf ('doctrine.dbal.%s_connection ' , $ store ['connection ' ])),
1092- $ store ['table_name ' ],
1093- $ store ['index_name ' ],
1094- $ store ['vector_field_name ' ],
1095- ];
1096-
10971100 $ definition = new Definition (MariaDbStore::class);
10981101 $ definition ->setFactory ([MariaDbStore::class, 'fromDbal ' ]);
10991102 $ definition
1100- ->addTag ('ai.store ' )
1101- ->setArguments ($ arguments );
1103+ ->setLazy (true )
1104+ ->setArguments ([
1105+ new Reference (\sprintf ('doctrine.dbal.%s_connection ' , $ store ['connection ' ])),
1106+ $ store ['table_name ' ],
1107+ $ store ['index_name ' ],
1108+ $ store ['vector_field_name ' ],
1109+ ])
1110+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1111+ ->addTag ('ai.store ' );
11021112
1103- $ serviceId = 'ai.store. ' .$ type .'. ' .$ name ;
1104- $ container ->setDefinition ($ serviceId , $ definition );
1105- $ container ->registerAliasForArgument ($ serviceId , StoreInterface::class, $ name );
1106- $ container ->registerAliasForArgument ($ serviceId , StoreInterface::class, $ type .'_ ' .$ name );
1113+ $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
1114+ $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
1115+ $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ type .'_ ' .$ name );
11071116
1108- $ setupStoresOptions [$ serviceId ] = $ store ['setup_options ' ] ?? [];
1117+ $ setupStoresOptions [' ai.store. ' . $ type . ' . ' . $ name ] = $ store ['setup_options ' ] ?? [];
11091118 }
11101119 }
11111120
@@ -1136,8 +1145,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11361145
11371146 $ definition = new Definition (MeilisearchStore::class);
11381147 $ definition
1139- ->addTag ('ai.store ' )
1140- ->setArguments ($ arguments );
1148+ ->setLazy (true )
1149+ ->setArguments ($ arguments )
1150+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1151+ ->addTag ('ai.store ' );
11411152
11421153 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
11431154 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1162,8 +1173,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11621173
11631174 $ definition = new Definition (InMemoryStore::class);
11641175 $ definition
1165- ->addTag ('ai.store ' )
1166- ->setArguments ($ arguments );
1176+ ->setLazy (true )
1177+ ->setArguments ($ arguments )
1178+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1179+ ->addTag ('ai.store ' );
11671180
11681181 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
11691182 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1195,8 +1208,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11951208
11961209 $ definition = new Definition (MilvusStore::class);
11971210 $ definition
1198- ->addTag ('ai.store ' )
1199- ->setArguments ($ arguments );
1211+ ->setLazy (true )
1212+ ->setArguments ($ arguments )
1213+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1214+ ->addTag ('ai.store ' );
12001215
12011216 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
12021217 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1223,8 +1238,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
12231238
12241239 $ definition = new Definition (MongoDbStore::class);
12251240 $ definition
1226- ->addTag ('ai.store ' )
1227- ->setArguments ($ arguments );
1241+ ->setLazy (true )
1242+ ->setArguments ($ arguments )
1243+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1244+ ->addTag ('ai.store ' );
12281245
12291246 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
12301247 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1262,8 +1279,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
12621279
12631280 $ definition = new Definition (Neo4jStore::class);
12641281 $ definition
1265- ->addTag ('ai.store ' )
1266- ->setArguments ($ arguments );
1282+ ->setLazy (true )
1283+ ->setArguments ($ arguments )
1284+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1285+ ->addTag ('ai.store ' );
12671286
12681287 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
12691288 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1288,8 +1307,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
12881307
12891308 $ definition = new Definition (PineconeStore::class);
12901309 $ definition
1291- ->addTag ('ai.store ' )
1292- ->setArguments ($ arguments );
1310+ ->setLazy (true )
1311+ ->setArguments ($ arguments )
1312+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1313+ ->addTag ('ai.store ' );
12931314
12941315 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
12951316 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1320,8 +1341,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
13201341
13211342 $ definition = new Definition (QdrantStore::class);
13221343 $ definition
1323- ->addTag ('ai.store ' )
1324- ->setArguments ($ arguments );
1344+ ->setLazy (true )
1345+ ->setArguments ($ arguments )
1346+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1347+ ->addTag ('ai.store ' );
13251348
13261349 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
13271350 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1340,16 +1363,19 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
13401363
13411364 $ definition = new Definition (RedisStore::class);
13421365 $ definition
1343- ->addTag ( ' ai.store ' )
1366+ ->setLazy ( true )
13441367 ->setArguments ([
13451368 $ redisClient ,
13461369 $ store ['index_name ' ],
13471370 $ store ['key_prefix ' ],
13481371 $ store ['distance ' ],
13491372 ])
1350- ;
1373+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1374+ ->addTag ('ai.store ' );
13511375
13521376 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
1377+ $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
1378+ $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ type .'_ ' .$ name );
13531379 }
13541380 }
13551381
@@ -1362,12 +1388,9 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
13621388 $ store ['password ' ],
13631389 $ store ['namespace ' ],
13641390 $ store ['database ' ],
1391+ $ store ['table ' ] ?? $ name ,
13651392 ];
13661393
1367- if (\array_key_exists ('table ' , $ store )) {
1368- $ arguments [6 ] = $ store ['table ' ];
1369- }
1370-
13711394 if (\array_key_exists ('vector_field ' , $ store )) {
13721395 $ arguments [7 ] = $ store ['vector_field ' ];
13731396 }
@@ -1386,8 +1409,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
13861409
13871410 $ definition = new Definition (SurrealDbStore::class);
13881411 $ definition
1389- ->addTag ('ai.store ' )
1390- ->setArguments ($ arguments );
1412+ ->setLazy (true )
1413+ ->setArguments ($ arguments )
1414+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1415+ ->addTag ('ai.store ' );
13911416
13921417 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
13931418 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1414,8 +1439,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
14141439
14151440 $ definition = new Definition (TypesenseStore::class);
14161441 $ definition
1417- ->addTag ('ai.store ' )
1418- ->setArguments ($ arguments );
1442+ ->setLazy (true )
1443+ ->setArguments ($ arguments )
1444+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1445+ ->addTag ('ai.store ' );
14191446
14201447 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
14211448 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1425,17 +1452,17 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
14251452
14261453 if ('weaviate ' === $ type ) {
14271454 foreach ($ stores as $ name => $ store ) {
1428- $ arguments = [
1429- new Reference ('http_client ' ),
1430- $ store ['endpoint ' ],
1431- $ store ['api_key ' ],
1432- $ store ['collection ' ],
1433- ];
1434-
14351455 $ definition = new Definition (WeaviateStore::class);
14361456 $ definition
1437- ->addTag ('ai.store ' )
1438- ->setArguments ($ arguments );
1457+ ->setLazy (true )
1458+ ->setArguments ([
1459+ new Reference ('http_client ' ),
1460+ $ store ['endpoint ' ],
1461+ $ store ['api_key ' ],
1462+ $ store ['collection ' ],
1463+ ])
1464+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1465+ ->addTag ('ai.store ' );
14391466
14401467 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
14411468 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1476,8 +1503,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
14761503 }
14771504
14781505 $ definition
1479- ->addTag ('ai.store ' )
1480- ->setArguments ($ arguments );
1506+ ->setLazy (true )
1507+ ->setArguments ($ arguments )
1508+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1509+ ->addTag ('ai.store ' );
14811510
14821511 $ container ->setDefinition ('ai.store. ' .$ type .'. ' .$ name , $ definition );
14831512 $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
@@ -1488,15 +1517,12 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
14881517 if ('supabase ' === $ type ) {
14891518 foreach ($ stores as $ name => $ store ) {
14901519 $ arguments = [
1491- isset ($ store ['http_client ' ]) ? new Reference ( $ store [ 'http_client ' ]) : new Definition (HttpClientInterface::class ),
1520+ new Reference ($ store ['http_client ' ] ?? 'http_client ' ),
14921521 $ store ['url ' ],
14931522 $ store ['api_key ' ],
1523+ $ store ['table ' ] ?? $ name ,
14941524 ];
14951525
1496- if (\array_key_exists ('table ' , $ store )) {
1497- $ arguments [3 ] = $ store ['table ' ];
1498- }
1499-
15001526 if (\array_key_exists ('vector_field ' , $ store )) {
15011527 $ arguments [4 ] = $ store ['vector_field ' ];
15021528 }
@@ -1511,11 +1537,14 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
15111537
15121538 $ definition = new Definition (SupabaseStore::class);
15131539 $ definition
1514- ->addTag ('ai.store ' )
1515- ->setArguments ($ arguments );
1540+ ->setLazy (true )
1541+ ->setArguments ($ arguments )
1542+ ->addTag ('proxy ' , ['interface ' => StoreInterface::class])
1543+ ->addTag ('ai.store ' );
15161544
15171545 $ container ->setDefinition ('ai.store.supabase. ' .$ name , $ definition );
1518- $ container ->registerAliasForArgument ('ai.store. ' .$ name , StoreInterface::class, (new Target ($ name .'Store ' ))->getParsedName ());
1546+ $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ name );
1547+ $ container ->registerAliasForArgument ('ai.store. ' .$ type .'. ' .$ name , StoreInterface::class, $ type .'_ ' .$ name );
15191548 }
15201549 }
15211550 }
0 commit comments