Skip to content

PHPLIB-1734: Add query and model arguments for automated embedding to $vectorSearch stage#1937

Open
GromNaN wants to merge 1 commit into
mongodb:v2.xfrom
GromNaN:vectorsearch-automated-embedding
Open

PHPLIB-1734: Add query and model arguments for automated embedding to $vectorSearch stage#1937
GromNaN wants to merge 1 commit into
mongodb:v2.xfrom
GromNaN:vectorsearch-automated-embedding

Conversation

@GromNaN

@GromNaN GromNaN commented Jul 3, 2026

Copy link
Copy Markdown
Member

Add the optional query (string) and model (string) arguments to the $vectorSearch pipeline stage, introduced in MongoDB 8.2 for the Automated Embedding feature.

These arguments allow passing a natural language text query instead of a pre-computed queryVector; MongoDB automatically generates the vector embedding at query time using the embedding model configured in the index, or an optionally overridden compatible model via model.

  • queryVector is now optional (either queryVector or query must be provided)
  • New query optional string argument (minVersion: '8.2')
  • New model optional string argument (minVersion: '8.2')

@GromNaN GromNaN force-pushed the vectorsearch-automated-embedding branch from c49fcbf to 55f6333 Compare July 7, 2026 11:12
@semgrep-code-mongodb

This comment was marked as outdated.

@GromNaN GromNaN force-pushed the vectorsearch-automated-embedding branch 2 times, most recently from 2eb2a55 to a1ee223 Compare July 9, 2026 09:51
… VectorSearchStage

Support the automated embedding feature introduced in MongoDB 8.2, which allows
passing a natural language text query instead of a pre-computed queryVector. The
$vectorSearch stage now accepts query (string) and model (string) optional arguments.
Depends on mongodb/mql-specifications#55.
@GromNaN GromNaN force-pushed the vectorsearch-automated-embedding branch from a1ee223 to ff0b6c4 Compare July 9, 2026 09:51
@GromNaN GromNaN marked this pull request as ready for review July 9, 2026 09:51
@GromNaN GromNaN requested a review from a team as a code owner July 9, 2026 09:51
@GromNaN GromNaN requested review from Copilot and paulinevos July 9, 2026 09:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends the aggregation builder’s $vectorSearch stage to support MongoDB 8.2 “automated embedding” usage by accepting a natural-language query and optional model override, in addition to the existing queryVector flow.

Changes:

  • Added query and model arguments to VectorSearchStage (and corresponding factory methods).
  • Made queryVector optional to enable query-text-based vector search.
  • Added new pipeline fixtures and tests covering the new automated embedding examples.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Builder/Stage/VectorSearchStage.php Adds query/model properties and makes queryVector optional for $vectorSearch.
src/Builder/Stage/FactoryTrait.php Updates Stage::vectorSearch() signature to accept optional queryVector, plus query/model.
src/Builder/Stage/FluentFactoryTrait.php Updates fluent ->vectorSearch() signature and forwarding call to include query/model.
tests/Builder/Stage/VectorSearchStageTest.php Adds new test cases building pipelines for automated embedding and model override.
tests/Builder/Stage/Pipelines.php Adds canonical extended JSON fixtures for the new automated embedding pipelines.
Comments suppressed due to low confidence (1)

src/Builder/Stage/VectorSearchStage.php:154

  • The stage currently allows constructing/encoding a $vectorSearch stage without either queryVector or query, even though the docblocks (and MongoDB 8.2 automated embedding semantics) require one of them. This results in an invalid pipeline being sent to the server. Consider validating that at least one of $queryVector or $query is provided, and that $model is only accepted when $query is set (as documented).
        $this->index = $index;
        $this->limit = $limit;
        $this->path = $path;
        if (is_array($queryVector) && ! array_is_list($queryVector)) {
            throw new InvalidArgumentException('Expected $queryVector argument to be a list, got an associative array.');

Comment on lines +107 to +109
$this->assertSamePipeline(Pipelines::VectorSearchAutomatedEmbeddingWithModelOverride, $pipeline);
}

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.

2 participants