Skip to content

PHPLIB-1789: Add autoEmbed type in VectorSearchIndexShape#1926

Merged
GromNaN merged 1 commit into
mongodb:v2.xfrom
GromNaN:PHPLIB-1789
Jun 16, 2026
Merged

PHPLIB-1789: Add autoEmbed type in VectorSearchIndexShape#1926
GromNaN merged 1 commit into
mongodb:v2.xfrom
GromNaN:PHPLIB-1789

Conversation

@GromNaN

@GromNaN GromNaN commented Jun 15, 2026

Copy link
Copy Markdown
Member

Adds type: 'autoEmbed' to the VectorSearchIndexShape Psalm type in Collection.php, with the following fields:

  • Required: type, modality ('text'), path, model (string)
  • Optional: numDimensions, quantization ('float'|'scalar'|'binary'|'binaryNoRescore'), similarity, indexingMethod, hnswOptions

The model field is typed as string rather than a string enum to avoid having to update the type every time a new model is released.

Two Psalm type tests added in SearchIndexShapes.php.

Jira: https://jira.mongodb.org/browse/PHPLIB-1789

Copilot AI review requested due to automatic review settings June 15, 2026 12:49
@GromNaN GromNaN requested a review from a team as a code owner June 15, 2026 12:49
@GromNaN GromNaN requested a review from paulinevos June 15, 2026 12:49

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

This PR extends the library’s Psalm typing for Atlas Vector Search index definitions so that vector search indexes can declare fields entries using the autoEmbed field type, and validates the new shape via Psalm type-check fixtures.

Changes:

  • Expanded VectorSearchIndexShape (Psalm array shape) to include an autoEmbed field variant alongside existing vector and filter variants.
  • Added Psalm-only type fixture methods covering a minimal autoEmbed definition and one including optional tuning parameters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Collection.php Adds an autoEmbed alternative to the VectorSearchIndexShape['fields'] union so createSearchIndex() accepts the new field configuration in static analysis.
tests/Type/SearchIndexShapes.php Adds two Psalm type fixtures to ensure autoEmbed vector search index definitions are accepted.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@GromNaN GromNaN enabled auto-merge (squash) June 15, 2026 13:01
Comment thread src/Collection.php
* @psalm-type VectorSearchIndexShape = array{
* fields: list<
* array{type: 'vector', path: string, numDimensions: int, similarity: 'euclidean'|'cosine'|'dotProduct', quantization?: 'none'|'scalar'|'binary', indexingMethod?: 'flat'|'hnsw', hnswOptions?: array{maxEdges?: int, numEdgeCandidates?: int}} |
* array{type: 'autoEmbed', modality: 'text', path: string, model: string, numDimensions?: int, quantization?: 'float'|'scalar'|'binary'|'binaryNoRescore', similarity?: 'euclidean'|'cosine'|'dotProduct', indexingMethod?: 'flat'|'hnsw', hnswOptions?: array{maxEdges?: int, numEdgeCandidates?: int}} |

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.

Can we multiline these types of shapes with a lot of different fields? Would make it easier to read the diff

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have mixed feelings about it, because it also makes the docblock very, very long.

@GromNaN GromNaN merged commit 7ba853f into mongodb:v2.x Jun 16, 2026
36 checks passed
@GromNaN GromNaN deleted the PHPLIB-1789 branch June 16, 2026 09:07
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.

4 participants