PHPORM-382 Add $vectorSearch stage to the aggregation builder#2822
PHPORM-382 Add $vectorSearch stage to the aggregation builder#2822GromNaN merged 4 commits intodoctrine:2.13.xfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for the MongoDB $vectorSearch aggregation stage to the Doctrine ODM aggregation builder. This enables vector similarity search functionality for MongoDB Atlas Vector Search.
- Implements a new
VectorSearchstage class with fluent API methods for all supported options - Adds comprehensive test coverage for all stage methods and option combinations
- Supports all vector search parameters: exact matching, filtering, indexing, limits, candidates, path, and query vectors
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/Doctrine/ODM/MongoDB/Aggregation/Stage/VectorSearch.php | Main implementation of the VectorSearch stage with fluent API methods |
| tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/VectorSearchTest.php | Comprehensive test suite covering all VectorSearch functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if ($this->exact !== null) { | ||
| $params['exact'] = $this->exact; | ||
| } | ||
|
|
||
| if ($this->filter !== null) { | ||
| $params['filter'] = $this->filter->getQuery(); | ||
| } | ||
|
|
||
| if ($this->index !== null) { | ||
| $params['index'] = $this->index; | ||
| } | ||
|
|
||
| if ($this->limit !== null) { | ||
| $params['limit'] = $this->limit; | ||
| } | ||
|
|
||
| if ($this->numCandidates !== null) { | ||
| $params['numCandidates'] = $this->numCandidates; | ||
| } | ||
|
|
||
| if ($this->path !== null) { | ||
| $params['path'] = $this->path; | ||
| } | ||
|
|
||
| if ($this->queryVector !== null) { | ||
| $params['queryVector'] = $this->queryVector; | ||
| } |
There was a problem hiding this comment.
index, limit, path and queryVector are required. The server will return an error if they are not used.
Looking at the other stages, it seems that we don't check this before.
There was a problem hiding this comment.
Makes sense to me. Maybe it's nice to document this as a standard in some sort of development decision documentation in the repo, as I think we've had conversations about this before.
| if ($this->path !== null) { | ||
| $params['path'] = $this->path; | ||
| } |
There was a problem hiding this comment.
The path should be mapped to the field name using the class metadata.
There was a problem hiding this comment.
Is this a TODO item? If so, is there another ticket to track this?
This seems related to #2820 (comment) from the PR that introduced a VectorSearchIndex mapping.
Not added to the Stage class as this stage must be first
| * | ||
| * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#mongodb-pipeline-pipe.-vectorSearch | ||
| */ | ||
| public function vectorSearch(): Stage\VectorSearch |
There was a problem hiding this comment.
IIUC, this PR does not add a Stage::vectorSearch() method for the same reason that you deprecated Stage::search() in #2823, correct?
| if ($this->path !== null) { | ||
| $params['path'] = $this->path; | ||
| } |
There was a problem hiding this comment.
Is this a TODO item? If so, is there another ticket to track this?
This seems related to #2820 (comment) from the PR that introduced a VectorSearchIndex mapping.
Summary
Add the
$vectorSearchstage builder.