Skip to content

Commit 3066ce5

Browse files
committed
feat(ai-bundle): add semantic_ratio to meilisearch store config
1 parent e2d01ac commit 3066ce5

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
@@ -525,6 +525,14 @@
525525
->stringNode('embedder')->end()
526526
->stringNode('vector_field')->end()
527527
->integerNode('dimensions')->end()
528+
->floatNode('semantic_ratio')
529+
->info('The ratio between semantic (vector) and keyword (BM25) search (0.0 to 1.0). Default: 1.0 (100% semantic)')
530+
->defaultValue(1.0)
531+
->validate()
532+
->ifTrue(fn ($v) => $v < 0.0 || $v > 1.0)
533+
->thenInvalid('The semantic ratio must be between 0.0 and 1.0.')
534+
->end()
535+
->end()
528536
->end()
529537
->end()
530538
->end()

src/ai-bundle/src/AiBundle.php

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

922+
if (\array_key_exists('semantic_ratio', $store)) {
923+
$arguments[7] = $store['semantic_ratio'];
924+
}
925+
922926
$definition = new Definition(MeilisearchStore::class);
923927
$definition
924928
->addTag('ai.store')

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,7 @@ private function getFullConfig(): array
29042904
'embedder' => 'default',
29052905
'vector_field' => '_vectors',
29062906
'dimensions' => 768,
2907+
'semantic_ratio' => 0.5,
29072908
],
29082909
],
29092910
'memory' => [
@@ -3060,4 +3061,28 @@ private function getFullConfig(): array
30603061
],
30613062
];
30623063
}
3064+
3065+
#[TestDox('Meilisearch store with custom semantic_ratio can be configured')]
3066+
public function testMeilisearchStoreWithCustomSemanticRatioCanBeConfigured()
3067+
{
3068+
$container = $this->buildContainer([
3069+
'ai' => [
3070+
'store' => [
3071+
'meilisearch' => [
3072+
'test_store' => [
3073+
'endpoint' => 'http://127.0.0.1:7700',
3074+
'api_key' => 'test_key',
3075+
'index_name' => 'test_index',
3076+
'semantic_ratio' => 0.5,
3077+
],
3078+
],
3079+
],
3080+
],
3081+
]);
3082+
3083+
$this->assertTrue($container->hasDefinition('ai.store.meilisearch.test_store'));
3084+
$definition = $container->getDefinition('ai.store.meilisearch.test_store');
3085+
$arguments = $definition->getArguments();
3086+
$this->assertSame(0.5, $arguments[7]);
3087+
}
30633088
}

0 commit comments

Comments
 (0)