Skip to content

Commit ae4f430

Browse files
Merge #677
677: feat: Adds hybrid search options contract for multisearch r=brunoocasali a=apozeus # Pull Request ## Related issue Fixes #676 ## What does this PR do? Adds hybrid search options contract for multisearch ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: marksun <[email protected]> Co-authored-by: apozeus <[email protected]>
2 parents 884789e + f9432dd commit ae4f430

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/Contracts/HybridSearchOptions.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Meilisearch\Contracts;
6+
7+
class HybridSearchOptions
8+
{
9+
private ?float $semanticRatio = null;
10+
11+
/**
12+
* @var non-empty-string|null
13+
*/
14+
private ?string $embedder = null;
15+
16+
public function setSemanticRatio(float $ratio): HybridSearchOptions
17+
{
18+
$this->semanticRatio = $ratio;
19+
20+
return $this;
21+
}
22+
23+
/**
24+
* @param non-empty-string $embedder
25+
*/
26+
public function setEmbedder(string $embedder): HybridSearchOptions
27+
{
28+
$this->embedder = $embedder;
29+
30+
return $this;
31+
}
32+
33+
/**
34+
* @return array{
35+
* semanticRatio?: float,
36+
* embedder?: non-empty-string
37+
* }
38+
*/
39+
public function toArray(): array
40+
{
41+
return array_filter([
42+
'semanticRatio' => $this->semanticRatio,
43+
'embedder' => $this->embedder,
44+
], static function ($item) { return null !== $item; });
45+
}
46+
}

src/Contracts/SearchQuery.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SearchQuery
2727
private ?int $hitsPerPage;
2828
private ?int $page;
2929
private ?array $vector;
30+
private ?HybridSearchOptions $hybrid = null;
3031
private ?array $attributesToSearchOn = null;
3132
private ?bool $showRankingScore = null;
3233
private ?bool $showRankingScoreDetails = null;
@@ -237,6 +238,21 @@ public function setVector(array $vector): SearchQuery
237238
return $this;
238239
}
239240

241+
/**
242+
* This is an EXPERIMENTAL feature, which may break without a major version.
243+
*
244+
* Set hybrid search options
245+
* (new HybridSearchOptions())
246+
* ->setSemanticRatio(0.8)
247+
* ->setEmbedder('manual');
248+
*/
249+
public function setHybrid(HybridSearchOptions $hybridOptions): SearchQuery
250+
{
251+
$this->hybrid = $hybridOptions;
252+
253+
return $this;
254+
}
255+
240256
/**
241257
* @param list<non-empty-string> $attributesToSearchOn
242258
*/
@@ -270,6 +286,7 @@ public function toArray(): array
270286
'hitsPerPage' => $this->hitsPerPage ?? null,
271287
'page' => $this->page ?? null,
272288
'vector' => $this->vector ?? null,
289+
'hybrid' => null !== $this->hybrid ? $this->hybrid->toArray() : null,
273290
'attributesToSearchOn' => $this->attributesToSearchOn,
274291
'showRankingScore' => $this->showRankingScore,
275292
'showRankingScoreDetails' => $this->showRankingScoreDetails,

0 commit comments

Comments
 (0)