Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions src/ai-bundle/config/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,11 @@
->stringNode('account_id')->cannotBeEmpty()->end()
->stringNode('api_key')->cannotBeEmpty()->end()
->stringNode('index_name')->cannotBeEmpty()->end()
->integerNode('dimensions')->end()
->stringNode('metric')->end()
->integerNode('dimensions')->isRequired()->end()
->stringNode('metric')
->cannotBeEmpty()
->defaultValue('cosine')
->end()
->stringNode('endpoint_url')->end()
->end()
->end()
Expand All @@ -588,24 +591,40 @@
->children()
->stringNode('endpoint')->cannotBeEmpty()->end()
->stringNode('table')->cannotBeEmpty()->end()
->stringNode('field')->end()
->stringNode('type')->end()
->stringNode('similarity')->end()
->integerNode('dimensions')->end()
->stringNode('field')->isRequired()->end()
->stringNode('type')->isRequired()->end()
->stringNode('similarity')->isRequired()->end()
->integerNode('dimensions')->isRequired()->end()
->stringNode('quantization')->end()
->end()
->end()
->end()
->arrayNode('mariadb')
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->stringNode('connection')->cannotBeEmpty()->end()
->stringNode('table_name')->cannotBeEmpty()->end()
->stringNode('index_name')->cannotBeEmpty()->end()
->stringNode('vector_field_name')->cannotBeEmpty()->end()
->arrayNode('setup_options')
->children()
->integerNode('dimensions')->end()
->end()
->end()
->end()
->end()
->end()
->arrayNode('meilisearch')
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->stringNode('endpoint')->cannotBeEmpty()->end()
->stringNode('api_key')->cannotBeEmpty()->end()
->stringNode('index_name')->cannotBeEmpty()->end()
->stringNode('embedder')->end()
->stringNode('vector_field')->end()
->integerNode('dimensions')->end()
->stringNode('embedder')->isRequired()->end()
->stringNode('vector_field')->isRequired()->end()
->integerNode('dimensions')->isRequired()->end()
->floatNode('semantic_ratio')
->info('The ratio between semantic (vector) and full-text search (0.0 to 1.0). Default: 1.0 (100% semantic)')
->defaultValue(1.0)
Expand All @@ -623,22 +642,6 @@
->end()
->end()
->end()
->arrayNode('mariadb')
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->stringNode('connection')->cannotBeEmpty()->end()
->stringNode('table_name')->cannotBeEmpty()->end()
->stringNode('index_name')->cannotBeEmpty()->end()
->stringNode('vector_field_name')->cannotBeEmpty()->end()
->arrayNode('setup_options')
->children()
->integerNode('dimensions')->end()
->end()
->end()
->end()
->end()
->end()
->arrayNode('milvus')
->useAttributeAsKey('name')
->arrayPrototype()
Expand All @@ -647,8 +650,8 @@
->stringNode('api_key')->isRequired()->end()
->stringNode('database')->isRequired()->end()
->stringNode('collection')->isRequired()->end()
->stringNode('vector_field')->end()
->integerNode('dimensions')->end()
->stringNode('vector_field')->isRequired()->end()
->integerNode('dimensions')->isRequired()->end()
->stringNode('metric_type')->end()
->end()
->end()
Expand Down
85 changes: 24 additions & 61 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,18 +1050,12 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
$store['account_id'],
$store['api_key'],
$store['index_name'],
$store['dimensions'],
$store['metric'],
];

if (\array_key_exists('dimensions', $store)) {
$arguments[4] = $store['dimensions'];
}

if (\array_key_exists('metric', $store)) {
$arguments[5] = $store['metric'];
}

if (\array_key_exists('endpoint', $store)) {
$arguments[6] = $store['endpoint'];
if (\array_key_exists('endpoint_url', $store)) {
$arguments[6] = $store['endpoint_url'];
}

$definition = new Definition(CloudflareStore::class);
Expand All @@ -1084,35 +1078,23 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
new Reference('http_client'),
$store['endpoint'],
$store['table'],
$store['field'],
$store['type'],
$store['similarity'],
$store['dimensions'],
];

if (\array_key_exists('field', $store)) {
$arguments[3] = $store['field'];
}

if (\array_key_exists('type', $store)) {
$arguments[4] = $store['type'];
}

if (\array_key_exists('similarity', $store)) {
$arguments[5] = $store['similarity'];
}

if (\array_key_exists('dimensions', $store)) {
$arguments[6] = $store['dimensions'];
}

if (\array_key_exists('quantization', $store)) {
$arguments[7] = $store['quantization'];
}

$definition = new Definition(ManticoreStore::class);
$definition
->setLazy(true)
->addTag('ai.store')
->setArguments($arguments)
->addTag('proxy', ['interface' => StoreInterface::class])
->addTag('proxy', ['interface' => ManagedStoreInterface::class])
->setArguments($arguments);
->addTag('ai.store');

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

if ('mariadb' === $type) {
foreach ($stores as $name => $store) {
$arguments = [
new Reference(\sprintf('doctrine.dbal.%s_connection', $store['connection'])),
$store['table_name'],
$store['index_name'],
$store['vector_field_name'],
];

$definition = new Definition(MariaDbStore::class);
$definition->setFactory([MariaDbStore::class, 'fromDbal']);
$definition
->setLazy(true)
->setArguments($arguments)
->setArguments([
new Reference(\sprintf('doctrine.dbal.%s_connection', $store['connection'])),
$store['table_name'],
$store['index_name'],
$store['vector_field_name'],
])
->addTag('proxy', ['interface' => StoreInterface::class])
->addTag('proxy', ['interface' => ManagedStoreInterface::class])
->addTag('ai.store');
Expand All @@ -1154,20 +1134,11 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
$store['endpoint'],
$store['api_key'],
$store['index_name'],
$store['embedder'],
$store['vector_field'],
$store['dimensions'],
];

if (\array_key_exists('embedder', $store)) {
$arguments[4] = $store['embedder'];
}

if (\array_key_exists('vector_field', $store)) {
$arguments[5] = $store['vector_field'];
}

if (\array_key_exists('dimensions', $store)) {
$arguments[6] = $store['dimensions'];
}

if (\array_key_exists('semantic_ratio', $store)) {
$arguments[7] = $store['semantic_ratio'];
}
Expand All @@ -1193,12 +1164,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
];

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

$container->setDefinition('ai.store.distance_calculator.'.$name, $distanceCalculatorDefinition);
}
$container->setDefinition('ai.store.distance_calculator.'.$name, $distanceCalculatorDefinition);

$arguments[0] = new Reference('ai.store.distance_calculator.'.$name);
}
Expand All @@ -1225,16 +1194,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
$store['api_key'],
$store['database'],
$store['collection'],
$store['vector_field'],
$store['dimensions'],
];

if (\array_key_exists('vector_field', $store)) {
$arguments[5] = $store['vector_field'];
}

if (\array_key_exists('dimensions', $store)) {
$arguments[6] = $store['dimensions'];
}

if (\array_key_exists('metric_type', $store)) {
$arguments[7] = $store['metric_type'];
}
Expand Down
Loading