Skip to content

Python: Preserve Azure AI Search source kinds - #7875

Open
NekoPunch (orangeCatDeveloper) wants to merge 1 commit into
microsoft:mainfrom
orangeCatDeveloper:fix/azure-search-mixed-source-params
Open

Python: Preserve Azure AI Search source kinds#7875
NekoPunch (orangeCatDeveloper) wants to merge 1 commit into
microsoft:mainfrom
orangeCatDeveloper:fix/azure-search-mixed-source-params

Conversation

@orangeCatDeveloper

@orangeCatDeveloper NekoPunch (orangeCatDeveloper) commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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 with InvalidRequestParameter.

Description & Review Guide

  • What are the major changes? The provider reads each referenced source definition and creates common KnowledgeSourceParams with 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.
  • What is the impact of these changes? Heterogeneous knowledge bases retrieve successfully while retaining include_reference_source_data=True. Passing the discriminator through the SDK base type also preserves kinds introduced by newer SDK versions.
  • What do you want reviewers to focus on? Please review the use of the common parameter model for discriminator passthrough and the atomic cache update across asynchronous source discovery.

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:

{"before":"failed_as_expected","status":400,"code":"InvalidRequestParameter","message":"Knowledge source params kind 'searchIndex' does not match the kind 'web' of knowledge source 'af7856-web-source'."}

{"after":"success","source_params":[{"name":"af7856-web-source","kind":"web"},{"name":"af7856-index-source","kind":"searchIndex"}],"message_count":1,"contains_marker":true}

Related Issue

Linked by the closing reference above.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (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.

Mixed knowledge bases fail retrieval when every source is declared as a search index.

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.

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.

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.

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 stable azure-search-documents 12.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

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

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AzureAISearchContextProvider sends SearchIndexKnowledgeSourceParams for web sources in mixed knowledge bases

3 participants