Skip to content

Commit 0f1cc8e

Browse files
GuikingoneOskarStark
authored andcommitted
[AI Bundle] Improvements on configuration / tags - II
1 parent c72b187 commit 0f1cc8e

File tree

3 files changed

+538
-112
lines changed

3 files changed

+538
-112
lines changed

src/ai-bundle/config/options.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,11 @@
576576
->stringNode('account_id')->cannotBeEmpty()->end()
577577
->stringNode('api_key')->cannotBeEmpty()->end()
578578
->stringNode('index_name')->cannotBeEmpty()->end()
579-
->integerNode('dimensions')->end()
580-
->stringNode('metric')->end()
579+
->integerNode('dimensions')->isRequired()->end()
580+
->stringNode('metric')
581+
->cannotBeEmpty()
582+
->defaultValue('cosine')
583+
->end()
581584
->stringNode('endpoint_url')->end()
582585
->end()
583586
->end()
@@ -588,24 +591,40 @@
588591
->children()
589592
->stringNode('endpoint')->cannotBeEmpty()->end()
590593
->stringNode('table')->cannotBeEmpty()->end()
591-
->stringNode('field')->end()
592-
->stringNode('type')->end()
593-
->stringNode('similarity')->end()
594-
->integerNode('dimensions')->end()
594+
->stringNode('field')->isRequired()->end()
595+
->stringNode('type')->isRequired()->end()
596+
->stringNode('similarity')->isRequired()->end()
597+
->integerNode('dimensions')->isRequired()->end()
595598
->stringNode('quantization')->end()
596599
->end()
597600
->end()
598601
->end()
602+
->arrayNode('mariadb')
603+
->useAttributeAsKey('name')
604+
->arrayPrototype()
605+
->children()
606+
->stringNode('connection')->cannotBeEmpty()->end()
607+
->stringNode('table_name')->cannotBeEmpty()->end()
608+
->stringNode('index_name')->cannotBeEmpty()->end()
609+
->stringNode('vector_field_name')->cannotBeEmpty()->end()
610+
->arrayNode('setup_options')
611+
->children()
612+
->integerNode('dimensions')->end()
613+
->end()
614+
->end()
615+
->end()
616+
->end()
617+
->end()
599618
->arrayNode('meilisearch')
600619
->useAttributeAsKey('name')
601620
->arrayPrototype()
602621
->children()
603622
->stringNode('endpoint')->cannotBeEmpty()->end()
604623
->stringNode('api_key')->cannotBeEmpty()->end()
605624
->stringNode('index_name')->cannotBeEmpty()->end()
606-
->stringNode('embedder')->end()
607-
->stringNode('vector_field')->end()
608-
->integerNode('dimensions')->end()
625+
->stringNode('embedder')->isRequired()->end()
626+
->stringNode('vector_field')->isRequired()->end()
627+
->integerNode('dimensions')->isRequired()->end()
609628
->floatNode('semantic_ratio')
610629
->info('The ratio between semantic (vector) and full-text search (0.0 to 1.0). Default: 1.0 (100% semantic)')
611630
->defaultValue(1.0)
@@ -623,22 +642,6 @@
623642
->end()
624643
->end()
625644
->end()
626-
->arrayNode('mariadb')
627-
->useAttributeAsKey('name')
628-
->arrayPrototype()
629-
->children()
630-
->stringNode('connection')->cannotBeEmpty()->end()
631-
->stringNode('table_name')->cannotBeEmpty()->end()
632-
->stringNode('index_name')->cannotBeEmpty()->end()
633-
->stringNode('vector_field_name')->cannotBeEmpty()->end()
634-
->arrayNode('setup_options')
635-
->children()
636-
->integerNode('dimensions')->end()
637-
->end()
638-
->end()
639-
->end()
640-
->end()
641-
->end()
642645
->arrayNode('milvus')
643646
->useAttributeAsKey('name')
644647
->arrayPrototype()
@@ -647,8 +650,8 @@
647650
->stringNode('api_key')->isRequired()->end()
648651
->stringNode('database')->isRequired()->end()
649652
->stringNode('collection')->isRequired()->end()
650-
->stringNode('vector_field')->end()
651-
->integerNode('dimensions')->end()
653+
->stringNode('vector_field')->isRequired()->end()
654+
->integerNode('dimensions')->isRequired()->end()
652655
->stringNode('metric_type')->end()
653656
->end()
654657
->end()

src/ai-bundle/src/AiBundle.php

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,18 +1050,12 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10501050
$store['account_id'],
10511051
$store['api_key'],
10521052
$store['index_name'],
1053+
$store['dimensions'],
1054+
$store['metric'],
10531055
];
10541056

1055-
if (\array_key_exists('dimensions', $store)) {
1056-
$arguments[4] = $store['dimensions'];
1057-
}
1058-
1059-
if (\array_key_exists('metric', $store)) {
1060-
$arguments[5] = $store['metric'];
1061-
}
1062-
1063-
if (\array_key_exists('endpoint', $store)) {
1064-
$arguments[6] = $store['endpoint'];
1057+
if (\array_key_exists('endpoint_url', $store)) {
1058+
$arguments[6] = $store['endpoint_url'];
10651059
}
10661060

10671061
$definition = new Definition(CloudflareStore::class);
@@ -1084,35 +1078,23 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10841078
new Reference('http_client'),
10851079
$store['endpoint'],
10861080
$store['table'],
1081+
$store['field'],
1082+
$store['type'],
1083+
$store['similarity'],
1084+
$store['dimensions'],
10871085
];
10881086

1089-
if (\array_key_exists('field', $store)) {
1090-
$arguments[3] = $store['field'];
1091-
}
1092-
1093-
if (\array_key_exists('type', $store)) {
1094-
$arguments[4] = $store['type'];
1095-
}
1096-
1097-
if (\array_key_exists('similarity', $store)) {
1098-
$arguments[5] = $store['similarity'];
1099-
}
1100-
1101-
if (\array_key_exists('dimensions', $store)) {
1102-
$arguments[6] = $store['dimensions'];
1103-
}
1104-
11051087
if (\array_key_exists('quantization', $store)) {
11061088
$arguments[7] = $store['quantization'];
11071089
}
11081090

11091091
$definition = new Definition(ManticoreStore::class);
11101092
$definition
11111093
->setLazy(true)
1112-
->addTag('ai.store')
1094+
->setArguments($arguments)
11131095
->addTag('proxy', ['interface' => StoreInterface::class])
11141096
->addTag('proxy', ['interface' => ManagedStoreInterface::class])
1115-
->setArguments($arguments);
1097+
->addTag('ai.store');
11161098

11171099
$container->setDefinition('ai.store.'.$type.'.'.$name, $definition);
11181100
$container->registerAliasForArgument('ai.store.'.$type.'.'.$name, StoreInterface::class, $name);
@@ -1122,18 +1104,16 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11221104

11231105
if ('mariadb' === $type) {
11241106
foreach ($stores as $name => $store) {
1125-
$arguments = [
1126-
new Reference(\sprintf('doctrine.dbal.%s_connection', $store['connection'])),
1127-
$store['table_name'],
1128-
$store['index_name'],
1129-
$store['vector_field_name'],
1130-
];
1131-
11321107
$definition = new Definition(MariaDbStore::class);
11331108
$definition->setFactory([MariaDbStore::class, 'fromDbal']);
11341109
$definition
11351110
->setLazy(true)
1136-
->setArguments($arguments)
1111+
->setArguments([
1112+
new Reference(\sprintf('doctrine.dbal.%s_connection', $store['connection'])),
1113+
$store['table_name'],
1114+
$store['index_name'],
1115+
$store['vector_field_name'],
1116+
])
11371117
->addTag('proxy', ['interface' => StoreInterface::class])
11381118
->addTag('proxy', ['interface' => ManagedStoreInterface::class])
11391119
->addTag('ai.store');
@@ -1154,20 +1134,11 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11541134
$store['endpoint'],
11551135
$store['api_key'],
11561136
$store['index_name'],
1137+
$store['embedder'],
1138+
$store['vector_field'],
1139+
$store['dimensions'],
11571140
];
11581141

1159-
if (\array_key_exists('embedder', $store)) {
1160-
$arguments[4] = $store['embedder'];
1161-
}
1162-
1163-
if (\array_key_exists('vector_field', $store)) {
1164-
$arguments[5] = $store['vector_field'];
1165-
}
1166-
1167-
if (\array_key_exists('dimensions', $store)) {
1168-
$arguments[6] = $store['dimensions'];
1169-
}
1170-
11711142
if (\array_key_exists('semantic_ratio', $store)) {
11721143
$arguments[7] = $store['semantic_ratio'];
11731144
}
@@ -1193,12 +1164,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
11931164
];
11941165

11951166
if (\array_key_exists('strategy', $store) && null !== $store['strategy']) {
1196-
if (!$container->hasDefinition('ai.store.distance_calculator.'.$name)) {
1197-
$distanceCalculatorDefinition = new Definition(DistanceCalculator::class);
1198-
$distanceCalculatorDefinition->setArgument(0, DistanceStrategy::from($store['strategy']));
1167+
$distanceCalculatorDefinition = new Definition(DistanceCalculator::class);
1168+
$distanceCalculatorDefinition->setArgument(0, DistanceStrategy::from($store['strategy']));
11991169

1200-
$container->setDefinition('ai.store.distance_calculator.'.$name, $distanceCalculatorDefinition);
1201-
}
1170+
$container->setDefinition('ai.store.distance_calculator.'.$name, $distanceCalculatorDefinition);
12021171

12031172
$arguments[0] = new Reference('ai.store.distance_calculator.'.$name);
12041173
}
@@ -1225,16 +1194,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
12251194
$store['api_key'],
12261195
$store['database'],
12271196
$store['collection'],
1197+
$store['vector_field'],
1198+
$store['dimensions'],
12281199
];
12291200

1230-
if (\array_key_exists('vector_field', $store)) {
1231-
$arguments[5] = $store['vector_field'];
1232-
}
1233-
1234-
if (\array_key_exists('dimensions', $store)) {
1235-
$arguments[6] = $store['dimensions'];
1236-
}
1237-
12381201
if (\array_key_exists('metric_type', $store)) {
12391202
$arguments[7] = $store['metric_type'];
12401203
}

0 commit comments

Comments
 (0)