Skip to content

Conversation

ahmed-bhs
Copy link

@ahmed-bhs ahmed-bhs commented Oct 14, 2025

Q A
Bug fix? no
New feature? yes
BC breaks? nope
Deprecations? no
Tests pass? yes
Fixed tickets #93
License MIT
Doc PR no

This PR drops a new configurable semanticRatio parameter into the Meilisearch Store. It's all about letting you fine-tune the vibe between classic full-text search and the new-school semantic (vector) search in Meilisearch's hybrid setup.

Right now, the ratio is hardcoded to 1.0 (100% semantic), which is a bit rigid. This change gives you the freedom to slide between super-precise full-text matches and more conceptual. For anyone curious about the nitty-gritty, Meilisearch has a great article on [Full-Text Search vs. Vector Search].

It's fully backward-compatible, defaulting to 1.0, so no old code gets broken.

Example Usage

1. Set the vibe on instantiation:

// A perfect 50/50 split
$store = new Store(..., semanticRatio: 0.5);

2. Override it for a specific query:

// Let's go old-school: pure full-text search for this one
$results = $store->query($vector, [
    'semanticRatio' => 0.0,
    'q' => 'PHP 8.2', // The text query for full-text matching
]);

Now end users can configure the semantic ratio in their config/packages/ai.yaml:

  ai:
      store:
          meilisearch:
              my_store:
                  endpoint: '%env(MEILISEARCH_URL)%'
                  api_key: '%env(MEILISEARCH_API_KEY)%'
                  index_name: 'my_index'
                  semantic_ratio: 0.5  # 50/50 hybrid search

@carsonbot carsonbot added Store Issues & PRs about the AI Store component Status: Needs Review labels Oct 14, 2025
This adds a semanticRatio parameter to control the balance between
keyword-based (BM25) and semantic (vector) search in hybrid queries.

- Add semanticRatio constructor parameter (default: 1.0 for BC)
- Allow per-query override via options array
- Add validation (0.0-1.0 range)
- Add support for 'q' parameter in query options for BM25 text queries
- Add comprehensive tests covering all scenarios

Use cases:
- 0.0 = Pure keyword search (IDs, codes, exact terms)
- 0.5 = Balanced hybrid search (general use)
- 1.0 = Pure semantic search (conceptual similarity)

Backward compatible - default behavior unchanged.
@ahmed-bhs ahmed-bhs force-pushed the feature/meilisearch-configurable-semantic-ratio branch from 5263652 to e2d01ac Compare October 15, 2025 07:34
@Guikingone
Copy link
Contributor

Don't forget to add the support for the option in AiBundle.php, as you can configure it in the constructor, end users must be in capacity of configuring it via the semantic configuration 🙂

@ahmed-bhs ahmed-bhs force-pushed the feature/meilisearch-configurable-semantic-ratio branch from 0be5f6d to 25b4785 Compare October 15, 2025 18:35
->integerNode('dimensions')->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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have ->min() and ->max(), can you please check. Unsure if we have ->between()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @OskarStark, it is cleaner using min and max, but unfortunately, a between function doesn't exist in the symfony/config component.

- Use min/max constraints instead of custom validation callback
- Remove redundant comments from meilisearch example
- Clean up changelog entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Reviewed Store Issues & PRs about the AI Store component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants