Skip to content

Commit c538f07

Browse files
committed
ref
1 parent 069215e commit c538f07

File tree

3 files changed

+396
-43
lines changed

3 files changed

+396
-43
lines changed

src/ai-bundle/config/options.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@
549549
->stringNode('table')->isRequired()->cannotBeEmpty()->end()
550550
->end()
551551
->validate()
552-
->ifTrue(static fn ($v) => !isset($v['dsn']) && !isset($v['http_client']))
552+
->ifTrue(static fn ($v): bool => !isset($v['dsn']) && !isset($v['http_client']))
553553
->thenInvalid('Either "dsn" or "http_client" must be configured.')
554554
->end()
555555
->end()
@@ -561,8 +561,11 @@
561561
->stringNode('account_id')->cannotBeEmpty()->end()
562562
->stringNode('api_key')->cannotBeEmpty()->end()
563563
->stringNode('index_name')->cannotBeEmpty()->end()
564-
->integerNode('dimensions')->end()
565-
->stringNode('metric')->end()
564+
->integerNode('dimensions')->isRequired()->end()
565+
->stringNode('metric')
566+
->cannotBeEmpty()
567+
->defaultValue('cosine')
568+
->end()
566569
->stringNode('endpoint_url')->end()
567570
->end()
568571
->end()
@@ -573,10 +576,10 @@
573576
->children()
574577
->stringNode('endpoint')->cannotBeEmpty()->end()
575578
->stringNode('table')->cannotBeEmpty()->end()
576-
->stringNode('field')->end()
577-
->stringNode('type')->end()
578-
->stringNode('similarity')->end()
579-
->integerNode('dimensions')->end()
579+
->stringNode('field')->cannotBeEmpty()->end()
580+
->stringNode('type')->cannotBeEmpty()->end()
581+
->stringNode('similarity')->cannotBeEmpty()->end()
582+
->integerNode('dimensions')->isRequired()->end()
580583
->stringNode('quantization')->end()
581584
->end()
582585
->end()

src/ai-bundle/src/AiBundle.php

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
use Symfony\AI\Store\Bridge\ChromaDb\Store as ChromaDbStore;
7979
use Symfony\AI\Store\Bridge\ClickHouse\Store as ClickHouseStore;
8080
use Symfony\AI\Store\Bridge\Cloudflare\Store as CloudflareStore;
81-
use Symfony\AI\Store\Bridge\Local\CacheStore;
81+
use Symfony\AI\Store\Bridge\Local\CacheStore as LocalCacheStore;
8282
use Symfony\AI\Store\Bridge\Local\DistanceCalculator;
8383
use Symfony\AI\Store\Bridge\Local\DistanceStrategy;
84-
use Symfony\AI\Store\Bridge\Local\InMemoryStore;
84+
use Symfony\AI\Store\Bridge\Local\InMemoryStore as LocalInMemoryStore;
8585
use Symfony\AI\Store\Bridge\Manticore\Store as ManticoreStore;
8686
use Symfony\AI\Store\Bridge\MariaDb\Store as MariaDbStore;
8787
use Symfony\AI\Store\Bridge\Meilisearch\Store as MeilisearchStore;
@@ -959,7 +959,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
959959
$arguments[1] = new Reference('ai.store.distance_calculator.'.$name);
960960
}
961961

962-
$definition = new Definition(CacheStore::class);
962+
$definition = new Definition(LocalCacheStore::class);
963963
$definition
964964
->setLazy(true)
965965
->setArguments($arguments)
@@ -997,9 +997,9 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
997997
} else {
998998
$httpClient = new Definition(HttpClientInterface::class);
999999
$httpClient
1000+
->setLazy(true)
10001001
->setFactory([HttpClient::class, 'createForBaseUri'])
1001-
->setArguments([$store['dsn']])
1002-
;
1002+
->setArguments([$store['dsn']]);
10031003
}
10041004

10051005
$definition = new Definition(ClickHouseStore::class);
@@ -1011,8 +1011,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10111011
$store['table'],
10121012
])
10131013
->addTag('proxy', ['interface' => StoreInterface::class])
1014-
->addTag('ai.store')
1015-
;
1014+
->addTag('ai.store');
10161015

10171016
$container->setDefinition('ai.store.'.$type.'.'.$name, $definition);
10181017
$container->registerAliasForArgument('ai.store.'.$type.'.'.$name, StoreInterface::class, $name);
@@ -1027,16 +1026,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10271026
$store['account_id'],
10281027
$store['api_key'],
10291028
$store['index_name'],
1029+
$store['dimensions'],
1030+
$store['metric'],
10301031
];
10311032

1032-
if (\array_key_exists('dimensions', $store)) {
1033-
$arguments[4] = $store['dimensions'];
1034-
}
1035-
1036-
if (\array_key_exists('metric', $store)) {
1037-
$arguments[5] = $store['metric'];
1038-
}
1039-
10401033
if (\array_key_exists('endpoint_url', $store)) {
10411034
$arguments[6] = $store['endpoint_url'];
10421035
}
@@ -1060,34 +1053,22 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10601053
new Reference('http_client'),
10611054
$store['endpoint'],
10621055
$store['table'],
1056+
$store['field'],
1057+
$store['type'],
1058+
$store['similarity'],
1059+
$store['dimensions'],
10631060
];
10641061

1065-
if (\array_key_exists('field', $store)) {
1066-
$arguments[3] = $store['field'];
1067-
}
1068-
1069-
if (\array_key_exists('type', $store)) {
1070-
$arguments[4] = $store['type'];
1071-
}
1072-
1073-
if (\array_key_exists('similarity', $store)) {
1074-
$arguments[5] = $store['similarity'];
1075-
}
1076-
1077-
if (\array_key_exists('dimensions', $store)) {
1078-
$arguments[6] = $store['dimensions'];
1079-
}
1080-
10811062
if (\array_key_exists('quantization', $store)) {
10821063
$arguments[7] = $store['quantization'];
10831064
}
10841065

10851066
$definition = new Definition(ManticoreStore::class);
10861067
$definition
10871068
->setLazy(true)
1088-
->addTag('ai.store')
1069+
->setArguments($arguments)
10891070
->addTag('proxy', ['interface' => StoreInterface::class])
1090-
->setArguments($arguments);
1071+
->addTag('ai.store');
10911072

10921073
$container->setDefinition('ai.store.'.$type.'.'.$name, $definition);
10931074
$container->registerAliasForArgument('ai.store.'.$type.'.'.$name, StoreInterface::class, $name);
@@ -1098,9 +1079,9 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10981079
if ('mariadb' === $type) {
10991080
foreach ($stores as $name => $store) {
11001081
$definition = new Definition(MariaDbStore::class);
1101-
$definition->setFactory([MariaDbStore::class, 'fromDbal']);
11021082
$definition
11031083
->setLazy(true)
1084+
->setFactory([MariaDbStore::class, 'fromDbal'])
11041085
->setArguments([
11051086
new Reference(\sprintf('doctrine.dbal.%s_connection', $store['connection'])),
11061087
$store['table_name'],
@@ -1171,7 +1152,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11711152
$arguments[0] = new Reference('ai.store.distance_calculator.'.$name);
11721153
}
11731154

1174-
$definition = new Definition(InMemoryStore::class);
1155+
$definition = new Definition(LocalInMemoryStore::class);
11751156
$definition
11761157
->setLazy(true)
11771158
->setArguments($arguments)
@@ -1621,7 +1602,7 @@ private function processMessageStoreConfig(string $type, array $messageStores, C
16211602

16221603
if ('memory' === $type) {
16231604
foreach ($messageStores as $name => $messageStore) {
1624-
$definition = new Definition(InMemoryStore::class);
1605+
$definition = new Definition(LocalInMemoryStore::class);
16251606
$definition
16261607
->setLazy(true)
16271608
->setArgument(0, $messageStore['identifier'])

0 commit comments

Comments
 (0)