Skip to content

Python: Fix Cosmos hybrid search field validation - #14650

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
mainfrom
cosmos-hybrid-validation
Oct 23, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
mainfrom
cosmos-hybrid-validation

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Motivation and Context

Cosmos DB NoSQL hybrid search previously inserted the requested text-field name directly into the generated query. This change limits hybrid text search to fields declared by the collection definition and safely renders the resolved storage property.

Description

  • Resolve additional_property_name against declared data-field logical and storage names.
  • Reject unknown field names before executing a Cosmos query.
  • Render the resolved property using Cosmos bracket notation with JSON string encoding.
  • Add regression coverage for logical names, storage aliases, and injection-shaped unknown names.

Validation:

  • uv run --frozen pytest tests\unit\connectors\memory\azure_cosmos_db\test_azure_cosmos_db_no_sql_collection.py -q — passed (30 tests).
  • uv run --frozen ruff check semantic_kernel\connectors\azure_cosmos_db.py tests\unit\connectors\memory\azure_cosmos_db\test_azure_cosmos_db_no_sql_collection.py — passed.
  • uv run --frozen ruff format --check semantic_kernel\connectors\azure_cosmos_db.py tests\unit\connectors\memory\azure_cosmos_db\test_azure_cosmos_db_no_sql_collection.py — passed.
  • uv run --frozen mypy semantic_kernel\connectors\azure_cosmos_db.py --config-file mypy.ini — passed.
  • uv run --frozen python -m compileall -q semantic_kernel\connectors\azure_cosmos_db.py tests\unit\connectors\memory\azure_cosmos_db\test_azure_cosmos_db_no_sql_collection.py — passed.
  • uv run --project python --frozen pre-commit run --config python\.pre-commit-config.yaml --files python\semantic_kernel\connectors\azure_cosmos_db.py python\tests\unit\connectors\memory\azure_cosmos_db\test_azure_cosmos_db_no_sql_collection.py — passed (all applicable hooks).
  • git diff --check — passed.

Contribution Checklist

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 12:55
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 23, 2026
@github-actions github-actions Bot changed the title Fix Cosmos hybrid search field validation Python: Fix Cosmos hybrid search field validation Oct 23, 2026

Copilot AI left a comment

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.

🟢 Approval recommended

The focused implementation matches the stated requirements, includes regression coverage, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR hardens Cosmos DB NoSQL hybrid search by validating text-field names against the collection definition and safely rendering the resolved storage property.

Changes:

  • Accept declared logical field names and storage aliases.
  • Reject unknown fields before query execution and use JSON-encoded bracket notation.
  • Add regression tests for field resolution and injection-shaped unknown names.
File Description
python/​tests/​unit/​connectors/​memory/​azure_cosmos_db/​test_azure_cosmos_db_no_sql_collection.py Tests logical names, storage aliases, and rejection of unknown fields.
python/​semantic_kernel/​connectors/​azure_cosmos_db.py Validates hybrid text fields and safely renders storage-property references.

Review effort: Balanced

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
connectors
   azure_cosmos_db.py42812371%183, 200, 206–208, 318, 320, 395, 399, 415–418, 420–423, 425–426, 439–442, 445–447, 453–454, 456, 463–465, 469–471, 494–496, 502–504, 510–511, 513, 518, 535, 610, 627, 630–631, 639, 649–653, 710, 713–714, 751, 753, 766–767, 771–773, 787, 791, 827, 839, 857, 869–870, 905–908, 916, 923, 930, 932, 935–944, 947–948, 950–957, 963, 977–980, 988, 992, 1016, 1044–1045, 1049–1054, 1146–1151
TOTAL29164545981% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4521 22 💤 0 ❌ 0 🔥 2m 17s ⏱️

This branch was previously deployed

2 inactive deployments
github-app-auth — f98c4d1e Deployed Oct 23, 2026 by eavanvalkenburg via add_label #29429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants