MONGOID-5924 Add support for flat indexing method in vector search#6152
Open
jamis wants to merge 3 commits into
Open
MONGOID-5924 Add support for flat indexing method in vector search#6152jamis wants to merge 3 commits into
jamis wants to merge 3 commits into
Conversation
…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.
Contributor
There was a problem hiding this comment.
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-levelvector_search. - Adds validation preventing
hnswOptionswithindexingMethod: '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.
- 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.
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.
exact: falseparameter tovector_search(both class-level and instance-level), consistent with the existingauto_embed_searchAPI. Whenexact: true,numCandidatesis omitted from the$vectorSearchaggregation stage — required for exact nearest-neighbor search and correct behavior with flat indexes.hnswOptionsis not combined withindexingMethod: 'flat', per the Atlas Vector Search spec error table.indexingMethod: 'flat'in thevector_search_indexDSL with an example.The
indexingMethodfield itself already passed through the definition hash unchanged, so no DSL changes were needed for index creation. Per the spec,numCandidatesis accepted but ignored by the server for flat indexes, so Mongoid does not strip it automatically — users opt in to exact search viaexact: true.