PHPLIB-1789: Add autoEmbed type in VectorSearchIndexShape#1926
Conversation
There was a problem hiding this comment.
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 anautoEmbedfield variant alongside existingvectorandfiltervariants. - Added Psalm-only type fixture methods covering a minimal
autoEmbeddefinition 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| * @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}} | |
There was a problem hiding this comment.
Can we multiline these types of shapes with a lot of different fields? Would make it easier to read the diff
There was a problem hiding this comment.
I have mixed feelings about it, because it also makes the docblock very, very long.
There was a problem hiding this comment.
True, but now it's also long, but horizontally, and hard to read 😅 But I see what you mean. It's not aesthetically pleasing but will make it easier to see what's changed.
Adds
type: 'autoEmbed'to theVectorSearchIndexShapePsalm type inCollection.php, with the following fields:type,modality('text'),path,model(string)numDimensions,quantization('float'|'scalar'|'binary'|'binaryNoRescore'),similarity,indexingMethod,hnswOptionsThe
modelfield is typed asstringrather 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