Skip to content

MONGOID-5924 Add support for flat indexing method in vector search#6152

Open
jamis wants to merge 3 commits into
mongodb:masterfrom
jamis:5924-flat-indexing
Open

MONGOID-5924 Add support for flat indexing method in vector search#6152
jamis wants to merge 3 commits into
mongodb:masterfrom
jamis:5924-flat-indexing

Conversation

@jamis
Copy link
Copy Markdown
Contributor

@jamis jamis commented May 26, 2026

  • Adds exact: false parameter to vector_search (both class-level and instance-level), consistent with the existing auto_embed_search API. When exact: true, numCandidates is omitted from the $vectorSearch aggregation stage — required for exact nearest-neighbor search and correct behavior with flat indexes.
  • Validates at index-definition time that hnswOptions is not combined with indexingMethod: 'flat', per the Atlas Vector Search spec error table.
  • Documents indexingMethod: 'flat' in the vector_search_index DSL with an example.

The indexingMethod field itself already passed through the definition hash unchanged, so no DSL changes were needed for index creation. Per the spec, numCandidates is accepted but ignored by the server for flat indexes, so Mongoid does not strip it automatically — users opt in to exact search via exact: true.

…dex definitions

- Add `exact: false` parameter to `vector_search` (class and instance) so
  callers can request exact nearest-neighbor search; when true, numCandidates
  is omitted from the $vectorSearch stage, matching the behavior already
  present in auto_embed_search.
- Validate at index-definition time that hnswOptions is not combined with
  indexingMethod: flat, per the Atlas Vector Search spec.
- Document the flat indexing method in the vector_search_index DSL.
Copilot AI review requested due to automatic review settings May 26, 2026 22:32
@jamis jamis requested a review from a team as a code owner May 26, 2026 22:32
@jamis jamis requested a review from comandeo-mongo May 26, 2026 22:32
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

This PR adds support for flat vector search indexes and exposes exact: search behavior for vector search APIs.

Changes:

  • Adds exact: keyword support to class-level and instance-level vector_search.
  • Adds validation preventing hnswOptions with indexingMethod: 'flat'.
  • Adds unit coverage for flat index validation and vector search pipeline construction.

Reviewed changes

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

File Description
lib/mongoid/search_indexable.rb Updates vector search API, pipeline construction, validation, and documentation.
spec/mongoid/search_indexable_spec.rb Adds tests for flat indexing validation and exact vector search pipeline behavior.

💡 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/search_indexable.rb
jamis added 2 commits May 26, 2026 16:42
- Send exact: true to the $vectorSearch stage when exact: true is passed,
  matching the auto_embed_search behavior; previously only numCandidates
  was being omitted but the exact flag was never forwarded to MongoDB.
- Add missing @param entry for exact: on the instance-level vector_search
  YARD block.
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