Skip to content

MONGOID-5923 Support auto emdedding vector search indexes and searches#6130

Merged
jamis merged 8 commits into
mongodb:masterfrom
jamis:5923-auto-emdedding
Apr 17, 2026
Merged

MONGOID-5923 Support auto emdedding vector search indexes and searches#6130
jamis merged 8 commits into
mongodb:masterfrom
jamis:5923-auto-emdedding

Conversation

@jamis
Copy link
Copy Markdown
Contributor

@jamis jamis commented Apr 14, 2026

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 String field using the voyage-4 model.

class Article
  include Mongoid::Document
  
  # Define `body` as a String field, indexed using the `voyage-4` auto-embedding model.
  auto_embed_field :body
end

You may declare the model and other parameters as well, if desired:

class Article
  include Mongoid::Document

  auto_embed_field :body,
                       model: 'voyage-4-large'
                       num_dimensions: 512,
                       quantization: 'binary',
                       similarity: 'cosine',
                       index: :body_index
end

Then, create the new search indexes:

$ rake db:mongoid:create_search_indexes

Once the indexes are created, you can query them using the auto_embed_search method:

articles = Article.auto_embed_search('machine learning', limit: 5)

# or, search for documents that are similar to an existing document
neighbors = article.auto_embed_search(limit: 5)

jamis added 5 commits April 14, 2026 15:12
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.
@jamis jamis requested a review from a team as a code owner April 14, 2026 21:59
@jamis jamis requested review from comandeo-mongo and Copilot and removed request for Copilot April 14, 2026 21:59
Copilot AI review requested due to automatic review settings April 15, 2026 19:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_field to declare a String field and register a vectorSearch index spec with an autoEmbed field definition.
  • Adds .auto_embed_search and #auto_embed_search APIs to execute $vectorSearch auto-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.

Comment thread lib/mongoid/search_indexable.rb
Comment thread lib/mongoid/fields.rb
@jamis jamis merged commit 844f083 into mongodb:master Apr 17, 2026
76 checks passed
@jamis jamis deleted the 5923-auto-emdedding branch April 17, 2026 14:03
@jamis jamis added the feature Adds a new feature, without breaking compatibility label Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Adds a new feature, without breaking compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants