Python: Preserve Azure AI Search source kinds - #7875
Python: Preserve Azure AI Search source kinds#7875NekoPunch (orangeCatDeveloper) wants to merge 1 commit into
Conversation
Mixed knowledge bases fail retrieval when every source is declared as a search index.
There was a problem hiding this comment.
Pull request overview
Preserves Azure AI Search knowledge-source kinds during agentic retrieval.
Changes:
- Resolves each source’s actual kind and caches parameters atomically.
- Clears stale parameters after provider reuse.
- Adds mixed-source, reuse, and concurrency regression tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
_context_provider.py |
Builds kind-aware source parameters. |
test_aisearch_context_provider.py |
Adds regression coverage. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Luis Rodriguez (luisangelrod)
left a comment
There was a problem hiding this comment.
Reviewed the source-kind resolution and initialization paths at 5078dcbb.
Using KnowledgeSourceParams with the discriminator returned by Azure avoids forcing heterogeneous sources into the searchIndex shape. Building the parameter list locally before assigning _knowledge_source_params also prevents concurrent initialization from publishing a partial cache, and the existing-KB path clears stale parameters when a closed provider is reused. I did not find a correctness issue in the change.
Verification:
test_aisearch_context_provider.py: 138 passed with the locked stableazure-search-documents12.0.0- the same 138 tests passed with preview 12.1.0b1
- package Ruff checks passed
- strict Pyright: 0 errors, 0 warnings
- test typing: mypy, pyright, pyrefly, ty, and zuban all passed
Fixes #7856
Motivation & Context
Agentic retrieval fails for an existing Azure AI Search Knowledge Base that combines web and search-index sources. The provider resolves every source name but declares every runtime parameter as
searchIndex, so Azure rejects the web source withInvalidRequestParameter.Description & Review Guide
KnowledgeSourceParamswith its actual kind. It builds the parameter list locally before publishing it, clears stale parameters when a closed provider is reused, and adds mixed-source, reuse, and concurrent-initialization regression coverage.include_reference_source_data=True. Passing the discriminator through the SDK base type also preserves kinds introduced by newer SDK versions.The change retains one source-definition read per Knowledge Base reference and doesn't add single-flight initialization.
Verified before and after against live Azure resources using the same mixed-source Knowledge Base and query:
Related Issue
Linked by the closing reference above.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.