diff --git a/.changeset/fluffy-waves-love.md b/.changeset/fluffy-waves-love.md new file mode 100644 index 00000000..bd5cdabd --- /dev/null +++ b/.changeset/fluffy-waves-love.md @@ -0,0 +1,5 @@ +--- +"@meilisearch/instant-meilisearch": minor +--- + +Enable experimental hybrid search diff --git a/packages/instant-meilisearch/README.md b/packages/instant-meilisearch/README.md index 36b61041..d5ef5f52 100644 --- a/packages/instant-meilisearch/README.md +++ b/packages/instant-meilisearch/README.md @@ -222,7 +222,8 @@ The following options can be overridden: [`showMatchesPosition`](https://www.meilisearch.com/docs/reference/api/search#show-matches-position), [`matchingStrategy`](https://www.meilisearch.com/docs/reference/api/search#matching-strategy), [`showRankingScore`](https://www.meilisearch.com/docs/reference/api/search#ranking-score), -[`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time). +[`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time), +[`hybrid`](https://www.meilisearch.com/docs/learn/experimental/vector_search) ```js instantMeiliSearch( diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts index fbea01fb..473a9fd4 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts @@ -78,6 +78,22 @@ describe('Parameters adapter', () => { meiliSearchParams.matchingStrategy ) }) + + test('hybrid search configuration can be set via search parameters', () => { + const hybridSearchConfig = { + semanticRatio: 0, + embedder: 'default', + } + + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + meiliSearchParams: { + hybrid: hybridSearchConfig, + }, + }) + + expect(searchParams.hybrid).toBe(hybridSearchConfig) + }) }) describe('Geo filter adapter', () => { diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts index e646b8f7..efdec9b5 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts @@ -232,6 +232,12 @@ export function MeiliParamsCreator(searchContext: SearchContext) { meiliSearchParams.attributesToSearchOn = value } }, + addHybridSearch() { + const value = overrideParams?.hybrid + if (value !== undefined) { + meiliSearchParams.hybrid = value + } + }, } } @@ -263,6 +269,7 @@ export function adaptSearchParams( meilisearchParams.addMatchingStrategy() meilisearchParams.addShowRankingScore() meilisearchParams.addAttributesToSearchOn() + meilisearchParams.addHybridSearch() return meilisearchParams.getParams() } diff --git a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts index fa864daa..1db62faa 100644 --- a/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts +++ b/packages/instant-meilisearch/src/client/instant-meilisearch-client.ts @@ -79,9 +79,11 @@ export function instantMeiliSearch( const instantMeilisearchConfig = getInstantMeilisearchConfig( instantMeiliSearchOptions ) + return { setMeiliSearchParams: (params): void => { const { meiliSearchParams } = instantMeiliSearchOptions + instantMeiliSearchOptions.meiliSearchParams = meiliSearchParams === undefined ? params diff --git a/packages/instant-meilisearch/src/types/types.ts b/packages/instant-meilisearch/src/types/types.ts index 22bdeffc..2f24d581 100644 --- a/packages/instant-meilisearch/src/types/types.ts +++ b/packages/instant-meilisearch/src/types/types.ts @@ -53,6 +53,7 @@ export type OverridableMeiliSearchSearchParameters = Pick< | 'matchingStrategy' | 'showRankingScore' | 'attributesToSearchOn' + | 'hybrid' > type BaseInstantMeiliSearchOptions = {