Repository navigation
Commit 1b22fd7
Python: Fix Cosmos hybrid search field validation (#14650)
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required?
2. What problem does it solve?
3. What scenario does it contribute to?
4. If it fixes an open issue, please link to the issue here.
-->
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
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
- 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
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent 6f1ae42 commit 1b22fd7
2 files changed
Lines changed: 101 additions & 3 deletions
File tree
- python
- semantic_kernel/connectors
- tests/unit/connectors/memory/azure_cosmos_db
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
833 | 834 | | |
834 | 835 | | |
835 | 836 | | |
836 | | - | |
837 | | - | |
| 837 | + | |
| 838 | + | |
838 | 839 | | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
839 | 853 | | |
840 | | - | |
| 854 | + | |
841 | 855 | | |
842 | 856 | | |
843 | 857 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
255 | 339 | | |
256 | 340 | | |
257 | 341 | | |
| |||
0 commit comments