Skip to content

fix(azure_ai_search): use a value-safe delimiter for search.in filters - #3846

Open
chakshu-dhannawat wants to merge 2 commits into
deepset-ai:mainfrom
chakshu-dhannawat:fix/azure-search-in-delimiter
Open

fix(azure_ai_search): use a value-safe delimiter for search.in filters#3846
chakshu-dhannawat wants to merge 2 commits into
deepset-ai:mainfrom
chakshu-dhannawat:fix/azure-search-in-delimiter

Conversation

@chakshu-dhannawat

Copy link
Copy Markdown
Contributor

Fixes #3844

Azure's search.in(field, valueList, delimiter) splits valueList on the supplied delimiter before comparing. The previous implementation always joined values with a comma and passed , as the delimiter, so any metadata value that itself contained a comma (e.g. "New York, NY") was split apart by Azure's server-side parsing and never matched.

Changes:

  • _in() now picks a delimiter that does not occur in any of the supplied values (candidates: U+001F, U+001E, U+001D).
  • If every candidate delimiter happens to be present in the values, it falls back to an OR chain of eq comparisons.
  • Updated existing unit-test expectations and added a regression test for comma-containing values.

Verified with hatch run test:unit, hatch run test:types, and hatch run fmt in integrations/azure_ai_search.

@github-actions

Copy link
Copy Markdown
Contributor

Heads-up for maintainers

This PR is from a fork and touches integrations whose integration tests require API keys.
Those tests are skipped in CI because fork PRs don't have access to repo secrets for security reasons.

Affected integrations:

  • azure_ai_search

Please run the integration tests locally (hatch run test:integration inside each folder) before approving.

@github-actions github-actions Bot added the type:documentation Improvements or additions to documentation label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Coverage report (azure_ai_search)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/azure_ai_search/src/haystack_integrations/document_stores/azure_ai_search
  filters.py
Project Total  

This report was generated by python-coverage-comment-action

Azure's search.in() splits its value-list string on the supplied delimiter.
The previous implementation always used a comma, which collided with commas
inside metadata values (e.g. "New York, NY"), causing the server to split a
single value into multiple fragments.

Pick a delimiter that does not appear in any of the values. If every
candidate delimiter is present, fall back to an OR chain of eq comparisons.
Update unit-test expectations and add a regression test for values that
contain commas.
# Pick a delimiter that does not occur in any of the values, so commas (or
# any other character) inside metadata values are preserved. If every
# candidate delimiter is present, fall back to an OR chain of eq clauses.
candidates = ["\u001f", "\u001e", "\u001d"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets expand the candidate list to include common delimiters since its possible that the values don't contain the common ones
candidates = [",", "|", ";", "\u001f", "\u001e", "\u001d"]

if all(delimiter not in v for v in value):
values = delimiter.join(_escape_odata_literal(v) for v in value)
return f"search.in({field},'{values}','{delimiter}')"
return " or ".join(f"{field} eq '{_escape_odata_literal(v)}'" for v in value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets make sure to expand the unit tests to cover this branch, currently it doesn't look like its covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:azure-ai-search type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AzureAISearchDocumentStore's 'in' filter joins values with the same comma Azure uses as its search.in() delimiter

2 participants