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);