MONGOID-5923 Support auto emdedding vector search indexes and searches#6130
Merged
Conversation
Adds auto_embed_search to ClassMethods for Atlas auto-embedding queries
(query: {text:...} instead of queryVector). Includes resolve_auto_embed_index
and infer_auto_embed_path private helpers, plus select_auto_embed_spec
extracted to keep cyclomatic complexity in check.
Adds an instance-level #auto_embed_search method that reads the text field from the document itself, excludes itself from results via a self-filter, and delegates to the class-level auto_embed_search.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Mongoid support for Atlas Vector Search auto-embedding indexes (autoEmbed) and a convenience query API to search by semantic text similarity.
Changes:
- Introduces
auto_embed_fieldto declare a String field and register avectorSearchindex spec with anautoEmbedfield definition. - Adds
.auto_embed_searchand#auto_embed_searchAPIs to execute$vectorSearchauto-embedding queries (including filtering, exact mode, and optional model override). - Expands RSpec coverage with argument-validation tests and (currently skipped) Atlas integration test scaffolding for auto-embed indexes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/mongoid/fields.rb | Adds auto_embed_field macro that defines a text field and registers an autoEmbed vector search index spec. |
| lib/mongoid/search_indexable.rb | Adds class/instance auto_embed_search implementations plus index/path inference helpers for auto-embed specs. |
| spec/mongoid/fields_spec.rb | Adds unit specs asserting index spec registration, defaults, and field behavior for auto_embed_field. |
| spec/mongoid/search_indexable_spec.rb | Adds argument validation specs for auto_embed_search and scaffolds skipped Atlas integration coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
comandeo-mongo
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mongoid can now define vector search indexes with auto-embedding, and provides a helper interface for querying documents by their semantic meaning using those indexed vector fields.
The simplest interface will define a
Stringfield using thevoyage-4model.You may declare the model and other parameters as well, if desired:
Then, create the new search indexes:
Once the indexes are created, you can query them using the
auto_embed_searchmethod: