Skip to content

fix: wire MongoDB label filters through prepare_filter - #853

Open
daviddallakyan2005 wants to merge 5 commits into
zilliztech:mainfrom
daviddallakyan2005:mongodb-filtered-search
Open

fix: wire MongoDB label filters through prepare_filter#853
daviddallakyan2005 wants to merge 5 commits into
zilliztech:mainfrom
daviddallakyan2005:mongodb-filtered-search

Conversation

@daviddallakyan2005

@daviddallakyan2005 daviddallakyan2005 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

MongoDB label-filter cases were silently unfiltered (recall ~0.111 vs ~0.982 once labels actually reach $vectorSearch). The runner already passes labels_data= into insert and calls prepare_filter then search_embedding(query, k). It never passes filters= into search. This wires the four missing pieces, matching qdrant_cloud:

  • declare supported_filter_types = [NonFilter, StrEqual] so label cases are not skipped
  • persist labels_data on documents as label when with_scalar_labels
  • prepare_filter stashes {label: <value>} for search to apply
  • add {type: "filter", path: "label"} to the vector search index when with_scalar_labels (Atlas rejects undeclared filter paths)

Does not add ingest-once metadata_fields, dict labels_data, or NumGE.

Rebased onto #852 so production MongoDBIndexConfig.search_param() includes exact. Filter tests construct MongoDBIndexConfig() rather than a stub subclass.

How to test

PYTHONPATH=. python3 -m pytest tests/test_mongodb_client.py tests/test_mongodb_config.py -q
make lint

make unittest is the network dataset download only and does not run these files.

21 passed. make lint clean. tests/test_db_client_resolution.py 43 passed.

search_embedding indexes search_params["exact"] on every query, but
search_param() only returned num_candidates_ratio, so MongoDB search
crashed with KeyError. Default remains False (ANN).
Mock collection.aggregate so ANN vs exact pipelines and a missing
exact key are covered; pymongo is stubbed when the extra is absent.
@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: daviddallakyan2005
To complete the pull request process, please assign xuanyang-cn after the PR has been reviewed.
You can assign the PR to them by writing /assign @xuanyang-cn in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment thread tests/test_mongodb_client.py Outdated
}


class _IndexConfig(MongoDBIndexConfig):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Test the production config instead of hiding the PR #852 dependency

_IndexConfig adds exact=False, but the production MongoDBIndexConfig.search_param() on this head does not return exact, while search_embedding() reads search_params["exact"]. A focused reproduction using MongoDBIndexConfig() raises KeyError: 'exact' before $vectorSearch is built. Thus this PR only works if PR #852 lands first, but these tests mask that dependency. Please rebase onto #852 (and link it in the PR description), or include its fix here, then remove this subclass so the regression tests exercise the production config.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I rebased this onto #852 and dropped _IndexConfig. The filter tests now construct MongoDBIndexConfig().

@jamesgao-jpg

Copy link
Copy Markdown
Collaborator

/assign @jamesgao-jpg

Filtered search silently ignored labels because insert dropped
labels_data, prepare_filter was a no-op, and the vector index never
declared path label. Mirror qdrant_cloud for StrEqual only.
Expand offline mocks for filter_supported, runner insert kwargs,
leftover filters= on search, and optimize index declaration.
Drop the _IndexConfig stub that hid the missing exact key. Filter
search tests now construct MongoDBIndexConfig() after rebasing onto zilliztech#852.
@jamesgao-jpg

Copy link
Copy Markdown
Collaborator

Hi, 852 is merged and seems that a conflict needs to be resolved before 853 can get merged

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.

3 participants