Skip to content

[MDS-6562] Fix filtering of permit conditions#3595

Merged
simensma-fresh merged 3 commits intodevelopfrom
MDS-6562_Fix-filtering
Jul 14, 2025
Merged

[MDS-6562] Fix filtering of permit conditions#3595
simensma-fresh merged 3 commits intodevelopfrom
MDS-6562_Fix-filtering

Conversation

@simensma-fresh
Copy link
Collaborator

Objective

MDS-6562

There's a bug in the Haystack Azure AI Search integration where it doesn't handle collection index field types correctly.
Issue: Filters on a field of the type Collection(...) fails with an error (it works for single fields).

Expected Odata filter syntax for a collection field is:

field/any(field: <filter>) where field is the name of the field and value is the value to filter on. The haystack integration spits out just the part.

Example: search.in(field, 'value1,value2', ',') should be field/any(field: search.in(field, 'value1,value2', ',')), but is not.

The following code overrides the comparison operators to handle a collection index field type.
Why override and not fix the bug in Haystack? This aims to fix it specifically for our use case,
a more general fix would require more considerations (e.g. handle 'any' vs 'all', complex types etc.).

Reference: https://learn.microsoft.com/en-us/azure/search/search-query-odata-filter

query_embedding: List[float],
top_k: int = 25,
filters: Optional[Dict[str, Any]] = None,
filters: Optional[str] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The filters param here is now just the Odata expression, so str is correct

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 7, 2025

fields_dict = {field.name: field for field in fields}
og_fltr = fltrs.COMPARISON_OPERATORS

def override_comparison_operators(op, func):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Don't like this one bit, but here we are 😅

Copy link
Contributor

@sggerard sggerard left a comment

Choose a reason for hiding this comment

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

Yay! Good work Simen, even if it's not pretty I'm glad you found a solution

Copy link
Collaborator

@matbusby-fw matbusby-fw left a comment

Choose a reason for hiding this comment

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

😬. Nice workaround. Too bad we need it though.

@simensma-fresh simensma-fresh merged commit d47528b into develop Jul 14, 2025
10 checks passed
@simensma-fresh simensma-fresh deleted the MDS-6562_Fix-filtering branch July 14, 2025 21:16
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.

4 participants