Skip to content

feat: support retrieveVectors in getDocument - #920

Open
tcferreira wants to merge 1 commit into
meilisearch:mainfrom
tcferreira:feat/get-document-retrieve-vectors
Open

feat: support retrieveVectors in getDocument#920
tcferreira wants to merge 1 commit into
meilisearch:mainfrom
tcferreira:feat/get-document-retrieve-vectors

Conversation

@tcferreira

@tcferreira tcferreira commented Jun 22, 2026

Copy link
Copy Markdown

Summary

The get-one-document endpoint accepts a retrieveVectors query parameter (to
include each document's vector data in the _vectors field), but
Index::getDocument() had no way to set it — only getDocuments() did, through
DocumentsQuery. This closes that gap. Closes #809.

Changes

  • getDocument(string|int $documentId, ?array $fields = null, bool $retrieveVectors = false):
    when true, the request now sends retrieveVectors=true. New optional
    parameter, so it's non-breaking for existing callers.
  • Integration test (testGetDocumentWithVector) mirroring the existing
    testGetDocumentsWithVector, asserting _vectors is absent by default and
    present when retrieveVectors is enabled.

Overview

This PR adds support for the retrieveVectors query parameter to the getDocument() method in the Meilisearch PHP SDK, enabling retrieval of vector data for individual documents through the single-document endpoint. Previously, this functionality was only available through the getDocuments() method.

Changes

API Method Update

  • Modified getDocument() signature to accept an optional $retrieveVectors boolean parameter (defaults to false for backward compatibility)
  • When $retrieveVectors is true, the method includes retrieveVectors=true in the query parameters sent to the /documents/{id} endpoint
  • Refactored query parameter construction to conditionally build the request based on provided parameters

Test Coverage

  • Added integration test testGetDocumentWithVector() that verifies:
    • The _vectors field is absent from the response by default
    • The _vectors field is included when retrieveVectors is enabled
    • Test uses a manual embedder with 3 dimensions and the VECTOR_MOVIES dataset

Impact

This change brings feature parity between the single-document and multi-document retrieval methods, allowing developers to retrieve vector data via getDocument() just as they can with getDocuments(). Since the new parameter is optional with a default value of false, this is a non-breaking change for existing code.

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 meilisearch#809
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87e48233-f016-4892-9234-1a62e44a1547

📥 Commits

Reviewing files that changed from the base of the PR and between c651751 and 9a106ad.

📒 Files selected for processing (2)
  • src/Endpoints/Delegates/HandlesDocuments.php
  • tests/Endpoints/DocumentsTest.php

📝 Walkthrough

Walkthrough

getDocument() in HandlesDocuments gains a third bool $retrieveVectors = false parameter. Query construction switches from a ternary to an isset($fields) conditional and conditionally appends retrieveVectors => true. A new integration test verifies that _vectors is absent by default and present when the flag is passed.

Changes

getDocument retrieveVectors support

Layer / File(s) Summary
getDocument signature, query construction, and integration test
src/Endpoints/Delegates/HandlesDocuments.php, tests/Endpoints/DocumentsTest.php
getDocument accepts a new bool $retrieveVectors = false parameter; query building switches to an isset($fields) block and appends retrieveVectors => true when the flag is set. testGetDocumentWithVector() configures a manual embedder, indexes vector fixtures, and asserts _vectors is absent on a default call and present when true is passed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

🐰 A flag hops in, small but true,
retrieveVectors now passes through!
The query builds with isset care,
And vectors bloom when you dare.
Hop hop hooray, the test confirms — vectors are there!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature addition: support for the retrieveVectors parameter in the getDocument method.
Linked Issues check ✅ Passed The pull request fully addresses issue #809 by adding the retrieveVectors parameter to getDocument() with proper implementation and test coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the retrieveVectors parameter for getDocument() as specified in issue #809; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.40%. Comparing base (0078a8c) to head (9a106ad).
⚠️ Report is 157 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #920      +/-   ##
==========================================
- Coverage   89.78%   88.40%   -1.39%     
==========================================
  Files          59       92      +33     
  Lines        1449     1932     +483     
==========================================
+ Hits         1301     1708     +407     
- Misses        148      224      +76     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Strift Strift left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is not passing; please fix linter issues.

Probably no need to fix PHPStan issues, as they will be fixed by #925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getDocument can't use retrieveVectors

2 participants