-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add embedders management methods * Fix vector search calls after v1.6
- Loading branch information
1 parent
c5ae8b9
commit 264620e
Showing
6 changed files
with
163 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Meilisearch\Contracts\Index; | ||
|
||
use Meilisearch\Contracts\Data; | ||
|
||
class Embedders extends Data implements \JsonSerializable | ||
{ | ||
public function jsonSerialize(): object | ||
{ | ||
return (object) $this->getIterator()->getArrayCopy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Settings; | ||
|
||
use Meilisearch\Http\Client; | ||
use Tests\TestCase; | ||
|
||
final class EmbeddersTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$http = new Client($this->host, getenv('MEILISEARCH_API_KEY')); | ||
$http->patch('/experimental-features', ['vectorStore' => true]); | ||
} | ||
|
||
public function testGetEmbedders(): void | ||
{ | ||
$index = $this->createEmptyIndex($this->safeIndexName('books-1')); | ||
$embedders = $index->getEmbedders(); | ||
|
||
$this->assertEquals([], $embedders); | ||
} | ||
|
||
public function testUpdateEmbeddersWithOpenAi(): void | ||
{ | ||
$embedderConfig = [ | ||
'source' => 'openAi', | ||
'apiKey' => '<your-OpenAI-API-key>', | ||
'model' => 'text-embedding-ada-002', | ||
'documentTemplate' => "A movie titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}", | ||
]; | ||
$index = $this->createEmptyIndex($this->safeIndexName()); | ||
|
||
$promise = $index->updateEmbedders(['myEmbedder' => $embedderConfig]); | ||
|
||
$this->assertIsValidPromise($promise); | ||
$index->waitForTask($promise['taskUid']); | ||
|
||
$embedders = $index->getEmbedders(); | ||
|
||
$this->assertEquals($embedderConfig, $embedders['myEmbedder']); | ||
} | ||
|
||
public function testUpdateEmbeddersWithUserProvided(): void | ||
{ | ||
$embedderConfig = [ | ||
'source' => 'userProvided', | ||
'dimensions' => 1, | ||
]; | ||
$index = $this->createEmptyIndex($this->safeIndexName()); | ||
|
||
$promise = $index->updateEmbedders(['myEmbedder' => $embedderConfig]); | ||
|
||
$this->assertIsValidPromise($promise); | ||
$index->waitForTask($promise['taskUid']); | ||
|
||
$embedders = $index->getEmbedders(); | ||
|
||
$this->assertEquals($embedderConfig, $embedders['myEmbedder']); | ||
} | ||
|
||
public function testUpdateEmbeddersWithHuggingFace(): void | ||
{ | ||
$embedderConfig = [ | ||
'source' => 'huggingFace', | ||
'model' => 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2', | ||
'documentTemplate' => "A movie titled '{{doc.title}}' whose description starts with {{doc.overview|truncatewords: 20}}", | ||
]; | ||
$index = $this->createEmptyIndex($this->safeIndexName()); | ||
|
||
$promise = $index->updateEmbedders(['myEmbedder' => $embedderConfig]); | ||
|
||
$this->assertIsValidPromise($promise); | ||
$index->waitForTask($promise['taskUid']); | ||
|
||
$embedders = $index->getEmbedders(); | ||
|
||
$this->assertEquals($embedderConfig, $embedders['myEmbedder']); | ||
} | ||
|
||
public function testResetEmbedders(): void | ||
{ | ||
$embedderConfig = [ | ||
'source' => 'userProvided', | ||
'dimensions' => 1, | ||
]; | ||
$index = $this->createEmptyIndex($this->safeIndexName()); | ||
|
||
$promise = $index->updateEmbedders(['myEmbedder' => $embedderConfig]); | ||
$this->assertIsValidPromise($promise); | ||
$index->waitForTask($promise['taskUid']); | ||
|
||
$promise = $index->resetEmbedders(); | ||
$this->assertIsValidPromise($promise); | ||
$index->waitForTask($promise['taskUid']); | ||
|
||
$embedders = $index->getEmbedders(); | ||
$this->assertEquals([], $embedders); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters