Skip to content

Commit 4b40b49

Browse files
committed
feat(ai-bundle): add semantic_ratio to meilisearch store config
1 parent 963ad12 commit 4b40b49

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

examples/rag/meilisearch.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
endpointUrl: env('MEILISEARCH_HOST'),
3434
apiKey: env('MEILISEARCH_API_KEY'),
3535
indexName: 'movies',
36+
// Optional: configure hybrid search ratio (0.0 = keyword, 1.0 = semantic)
37+
// semanticRatio: 0.5, // 50/50 hybrid search
3638
);
3739

3840
// create embeddings and documents

src/ai-bundle/config/options.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@
538538
->stringNode('embedder')->end()
539539
->stringNode('vector_field')->end()
540540
->integerNode('dimensions')->end()
541+
->floatNode('semantic_ratio')
542+
->info('The ratio between semantic (vector) and keyword (BM25) search (0.0 to 1.0). Default: 1.0 (100% semantic)')
543+
->defaultValue(1.0)
544+
->validate()
545+
->ifTrue(fn ($v) => $v < 0.0 || $v > 1.0)
546+
->thenInvalid('The semantic ratio must be between 0.0 and 1.0.')
547+
->end()
548+
->end()
541549
->end()
542550
->end()
543551
->end()

src/ai-bundle/src/AiBundle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,10 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10151015
$arguments[6] = $store['dimensions'];
10161016
}
10171017

1018+
if (\array_key_exists('semantic_ratio', $store)) {
1019+
$arguments[7] = $store['semantic_ratio'];
1020+
}
1021+
10181022
$definition = new Definition(MeilisearchStore::class);
10191023
$definition
10201024
->addTag('ai.store')

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,6 +2966,7 @@ private function getFullConfig(): array
29662966
'embedder' => 'default',
29672967
'vector_field' => '_vectors',
29682968
'dimensions' => 768,
2969+
'semantic_ratio' => 0.5,
29692970
],
29702971
],
29712972
'memory' => [
@@ -3152,4 +3153,28 @@ private function getFullConfig(): array
31523153
],
31533154
];
31543155
}
3156+
3157+
#[TestDox('Meilisearch store with custom semantic_ratio can be configured')]
3158+
public function testMeilisearchStoreWithCustomSemanticRatioCanBeConfigured()
3159+
{
3160+
$container = $this->buildContainer([
3161+
'ai' => [
3162+
'store' => [
3163+
'meilisearch' => [
3164+
'test_store' => [
3165+
'endpoint' => 'http://127.0.0.1:7700',
3166+
'api_key' => 'test_key',
3167+
'index_name' => 'test_index',
3168+
'semantic_ratio' => 0.5,
3169+
],
3170+
],
3171+
],
3172+
],
3173+
]);
3174+
3175+
$this->assertTrue($container->hasDefinition('ai.store.meilisearch.test_store'));
3176+
$definition = $container->getDefinition('ai.store.meilisearch.test_store');
3177+
$arguments = $definition->getArguments();
3178+
$this->assertSame(0.5, $arguments[7]);
3179+
}
31553180
}

0 commit comments

Comments
 (0)