From 9a106ad48d6f53d0d0b597e5b043eb0ef6e81fc5 Mon Sep 17 00:00:00 2001 From: Tiago Ferreira Date: Mon, 22 Jun 2026 06:10:51 -0300 Subject: [PATCH] feat: support retrieveVectors in getDocument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The get-one-document endpoint accepts a `retrieveVectors` query parameter to include each document's vector data (the `_vectors` field), but `getDocument` had no way to set it — only `getDocuments` did, via `DocumentsQuery`. Add a `retrieveVectors` parameter to `getDocument`, forwarded as a query parameter. Adds an integration test mirroring the `getDocuments` vector test. Closes #809 --- src/Endpoints/Delegates/HandlesDocuments.php | 11 +++++++++-- tests/Endpoints/DocumentsTest.php | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Endpoints/Delegates/HandlesDocuments.php b/src/Endpoints/Delegates/HandlesDocuments.php index 6032716b..77cd2b89 100644 --- a/src/Endpoints/Delegates/HandlesDocuments.php +++ b/src/Endpoints/Delegates/HandlesDocuments.php @@ -17,10 +17,17 @@ trait HandlesDocuments { /** * @param non-empty-string|int $documentId + * @param list|null $fields */ - public function getDocument(string|int $documentId, ?array $fields = null): array + public function getDocument(string|int $documentId, ?array $fields = null, bool $retrieveVectors = false): array { - $query = isset($fields) ? ['fields' => implode(',', $fields)] : []; + $query = []; + if (isset($fields)) { + $query['fields'] = implode(',', $fields); + } + if ($retrieveVectors) { + $query['retrieveVectors'] = true; + } return $this->http->get(self::PATH.'/'.$this->uid.'/documents/'.$documentId, $query); } diff --git a/tests/Endpoints/DocumentsTest.php b/tests/Endpoints/DocumentsTest.php index 163195ac..d7d3c0d8 100644 --- a/tests/Endpoints/DocumentsTest.php +++ b/tests/Endpoints/DocumentsTest.php @@ -681,6 +681,22 @@ public function testGetDocumentsWithVector(): void self::assertCount(5, $response); } + public function testGetDocumentWithVector(): void + { + $index = $this->createEmptyIndex($this->safeIndexName('movies')); + + $index->updateEmbedders(['manual' => ['source' => 'userProvided', 'dimensions' => 3]])->wait(); + $index->updateDocuments(self::VECTOR_MOVIES)->wait(); + + $documentId = self::VECTOR_MOVIES[0]['id']; + + $response = $index->getDocument($documentId); + self::assertArrayNotHasKey('_vectors', $response); + + $response = $index->getDocument($documentId, null, true); + self::assertArrayHasKey('_vectors', $response); + } + public function testGetDocumentsMessageHintException(): void { $responseMock = $this->createMock(ResponseInterface::class);