Skip to content

fix(retrievers): keep the filter on a Milvus hybrid search - #1175

Open
pcbeingused333 wants to merge 1 commit into
dynamiq-ai:mainfrom
pcbeingused333:fix/milvus-hybrid-filters
Open

pcbeingused333 wants to merge 1 commit into
dynamiq-ai:mainfrom
pcbeingused333:fix/milvus-hybrid-filters

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

The Milvus retriever drops filters whenever a text query is passed, which switches it to hybrid search. MilvusDocumentRetriever.run did not forward them to _hybrid_retrieval, and that method had no way to apply them, so documents outside the filter were returned. The dense-only path was not affected.

_hybrid_retrieval now accepts filters and sets the built expression as expr on both the dense and the BM25 AnnSearchRequest. With no filters, expr stays None.

Compatibility

No change to saved workflows. The new argument is optional and added last. Hybrid searches with a filter configured now return only matching documents.

Verified

  • Added a storage test for the expr of both requests (with a filter, None and {}) and extended the retriever's hybrid test to pass a filter. The four cases fail without the change and pass with it.
  • Milvus storage and retriever tests with the vectorstores extra: 86 passed.
  • Against Milvus Lite with two documents (tenant a and b) and a filter tenant == "a": on main the hybrid search returned both; with the change it returns only a.
  • black, isort and flake8 on the changed files.

This change was prepared with AI assistance.

@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 27, 2026 19:17

This branch has not been deployed

No deployments
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.

1 participant