diff --git a/src/Contracts/HybridSearchOptions.php b/src/Contracts/HybridSearchOptions.php new file mode 100644 index 00000000..eb1695e4 --- /dev/null +++ b/src/Contracts/HybridSearchOptions.php @@ -0,0 +1,36 @@ +semanticRatio = $ratio; + + return $this; + } + + /** + * @param non-empty-string + */ + public function setEmbedder(string $embedder): HybridSearchOptions + { + $this->embedder = $embedder; + + return $this; + } + + public function toArray(): array + { + return array_filter([ + 'semanticRatio' => $this->semanticRatio, + 'embedder' => $this->embedder, + ], static function ($item) { return null !== $item; }); + } +} diff --git a/src/Contracts/SearchQuery.php b/src/Contracts/SearchQuery.php index a6aac4b1..afd06ca0 100644 --- a/src/Contracts/SearchQuery.php +++ b/src/Contracts/SearchQuery.php @@ -27,6 +27,7 @@ class SearchQuery private ?int $hitsPerPage; private ?int $page; private ?array $vector; + private ?HybridSearchOptions $hybrid; private ?array $attributesToSearchOn = null; private ?bool $showRankingScore = null; private ?bool $showRankingScoreDetails = null; @@ -237,6 +238,21 @@ public function setVector(array $vector): SearchQuery return $this; } + /** + * This is an EXPERIMENTAL feature, which may break without a major version. + * + * Set hybrid search options + * (new HybridSearchOptions()) + * ->setSemanticRatio(0.8) + * ->setEmbedder('manual'); + */ + public function setHybrid(HybridSearchOptions $hybridOptions): SearchQuery + { + $this->hybrid = $hybridOptions; + + return $this; + } + /** * @param list $attributesToSearchOn */ @@ -270,6 +286,7 @@ public function toArray(): array 'hitsPerPage' => $this->hitsPerPage ?? null, 'page' => $this->page ?? null, 'vector' => $this->vector ?? null, + 'hybrid' => null !== $this->hybrid ? $this->hybrid->toArray() : null, 'attributesToSearchOn' => $this->attributesToSearchOn, 'showRankingScore' => $this->showRankingScore, 'showRankingScoreDetails' => $this->showRankingScoreDetails,