-
-
Notifications
You must be signed in to change notification settings - Fork 513
PHPORM-382 Add $vectorSearch stage to the aggregation builder #2822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
VectorSearch
stage 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path
should be mapped to the field name using the class metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
$vectorSearch
stage builder.