From dbdf963c10b8e9f17ffd57a61a48f36a8ed86287 Mon Sep 17 00:00:00 2001 From: Soong Ming Liang Date: Tue, 12 Aug 2025 11:25:06 +0800 Subject: [PATCH] Change Typesense action mode to emplace when import documents This PR changes the action mode to emplace when importing documents to Typesense. This is useful to make sure data will not be overwritten when user have other fields in Typesense that is managed seperately (like externally generated embeddings). Related documentation: https://typesense.org/docs/29.0/api/documents.html#action-modes-create-upsert-update-emplace --- src/Engines/TypesenseEngine.php | 2 +- tests/Unit/TypesenseEngineTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index e77cb9df..d8e3a6ff 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -111,7 +111,7 @@ public function update($models) * @throws \Typesense\Exceptions\TypesenseClientError * @throws \Http\Client\Exception */ - protected function importDocuments(TypesenseCollection $collectionIndex, array $documents, string $action = 'upsert'): Collection + protected function importDocuments(TypesenseCollection $collectionIndex, array $documents, string $action = 'emplace'): Collection { $importedDocuments = $collectionIndex->getDocuments()->import($documents, ['action' => $action]); diff --git a/tests/Unit/TypesenseEngineTest.php b/tests/Unit/TypesenseEngineTest.php index 8808ffca..f4cfd313 100644 --- a/tests/Unit/TypesenseEngineTest.php +++ b/tests/Unit/TypesenseEngineTest.php @@ -133,7 +133,7 @@ public function test_update_method(): void $documents->expects($this->once()) ->method('import') ->with( - [['id' => 1, 'name' => 'Model 1']], ['action' => 'upsert'], + [['id' => 1, 'name' => 'Model 1']], ['action' => 'emplace'], ) ->willReturn([[ 'success' => true,