Skip to content

Conversation

@farzad528
Copy link

@farzad528 farzad528 commented Oct 17, 2025

Motivation and Context

This PR introduces Azure AI Search as a context provider for Retrieval-Augmented Generation (RAG) scenarios, enabling agents to retrieve and ground responses in knowledge sources stored within Azure AI Search.
It addresses the need for agents to perform knowledge-grounded reasoning across indexed enterprise content, improving response accuracy and transparency.

Description

Key changes:

  • Added AzureAISearchContextProvider class in _search_provider.py with two retrieval modes:

    • Semantic mode (default): Fast hybrid (vector + keyword) search with semantic ranking
    • Agentic mode: Multi-hop reasoning via Azure AI Search Knowledge primitives for complex, cross-source retrieval
  • Added a complete example: azure_ai_with_search_context.py demonstrating both modes

  • Updated README.md with documentation and usage guidance

  • Added dependency: azure-search-documents >= 11.7.0b1 to pyproject.toml

Features:

  • Semantic and Agentic retrieval Modes
  • Async context manager support
  • Streaming and non-streaming response modes

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where applicable
  • Is this a breaking change? No

@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 16:45
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Oct 17, 2025
@github-actions github-actions bot changed the title feat(Azure AI Search Context Provider): Add Python Azure AI Search Context Provider with toggle for "semantic" mode and "agentic" mode in azure ai Python: feat(Azure AI Search Context Provider): Add Python Azure AI Search Context Provider with toggle for "semantic" mode and "agentic" mode in azure ai Oct 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a Python Azure AI Search Context Provider with support for two retrieval modes: semantic (fast hybrid search) and agentic (slower multi-hop reasoning with Knowledge Bases).

  • Implements AzureAISearchContextProvider with dual-mode functionality for different use cases
  • Adds comprehensive sample demonstrating both semantic and agentic retrieval modes
  • Integrates azure-search-documents dependency for search capabilities

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/packages/azure-ai/agent_framework_azure_ai/_search_provider.py Core implementation of AzureAISearchContextProvider with semantic and agentic modes
python/samples/getting_started/agents/azure_ai/azure_ai_with_search_context.py Sample demonstrating usage of the search context provider with both modes
python/packages/azure-ai/pyproject.toml Adds azure-search-documents dependency
python/packages/azure-ai/agent_framework_azure_ai/__init__.py Exports the new AzureAISearchContextProvider class
python/samples/getting_started/agents/azure_ai/README.md Documents the new sample and required environment variables

Comment on lines +183 to +186
# Extract Azure OpenAI endpoint from project endpoint
# Project endpoint format: https://<project>.services.ai.azure.com
# OpenAI endpoint format: https://<resource>.openai.azure.com
# For now, use the project endpoint directly as Knowledge Base accepts it
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

The comment mentions extracting Azure OpenAI endpoint from project endpoint but the code doesn't actually perform the extraction - it just assigns the project endpoint directly. Either update the comment to reflect the actual behavior or implement the extraction logic as described.

Suggested change
# Extract Azure OpenAI endpoint from project endpoint
# Project endpoint format: https://<project>.services.ai.azure.com
# OpenAI endpoint format: https://<resource>.openai.azure.com
# For now, use the project endpoint directly as Knowledge Base accepts it
# Use Azure AI project endpoint directly as Knowledge Base accepts it
# Project endpoint format: https://<project>.services.ai.azure.com
# OpenAI endpoint format: https://<resource>.openai.azure.com
# No extraction performed; project endpoint is used as-is

Copilot uses AI. Check for mistakes.

aoai_params = AzureOpenAIVectorizerParameters(
resource_url=self.azure_openai_endpoint,
deployment_name=self.azure_openai_deployment_name,
model_name=self.azure_openai_deployment_name, # Model name for Knowledge Base
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

The model_name parameter is being set to the same value as deployment_name. This may not be correct as model_name typically refers to the underlying model (e.g., 'gpt-4') while deployment_name is the user-defined deployment identifier. Consider clarifying whether these should be the same or if model_name should be derived differently.

Suggested change
model_name=self.azure_openai_deployment_name, # Model name for Knowledge Base
model_name=self.azure_openai_model_name, # Model name for Knowledge Base

Copilot uses AI. Check for mistakes.

Comment on lines +375 to +377
# Try to get existing knowledge source
await self._index_client.get_knowledge_source(knowledge_source_name)
except Exception:
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Using a bare 'except Exception' is too broad and can hide important errors. Consider catching specific exceptions like ResourceNotFoundError or the actual exception type that indicates the resource doesn't exist.

Copilot uses AI. Check for mistakes.

Comment on lines +389 to +392
try:
# Try to get existing Knowledge Base
await self._index_client.get_agent(self.knowledge_base_name)
except Exception:
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Using a bare 'except Exception' is too broad and can hide important errors. Consider catching specific exceptions like ResourceNotFoundError or the actual exception type that indicates the resource doesn't exist.

Copilot uses AI. Check for mistakes.

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Oct 17, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _search_provider.py13811218%47–48, 170–178, 182, 187–188, 190, 192, 194–196, 199–200, 202–204, 208–209, 212–213, 216–217, 220, 228–230, 235, 239, 260, 278–279, 281–282, 285–286, 288, 291–292, 294, 296, 312, 315–317, 326, 331–332, 335–338, 341, 344–345, 347–351, 354–356, 358, 368–369, 372, 374, 376–377, 379, 386, 389, 391–392, 394, 401, 422, 424, 445, 449, 459–460, 462, 468, 470, 473, 476, 478–479, 481–484, 486–487, 490, 502–504, 507–510, 512
TOTAL11789200882% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
1371 98 💤 0 ❌ 0 🔥 28.100s ⏱️

@farzad528 farzad528 changed the title Python: feat(Azure AI Search Context Provider): Add Python Azure AI Search Context Provider with toggle for "semantic" mode and "agentic" mode in azure ai Python: feat(Azure AI Search Context Provider): Add Azure AI Search Context Provider with toggle for "semantic" mode and "agentic" mode in azure ai Oct 17, 2025
| [`azure_ai_with_existing_thread.py`](azure_ai_with_existing_thread.py) | Shows how to work with a pre-existing thread by providing the thread ID to the Azure AI chat client. This example also demonstrates proper cleanup of manually created threads. |
| [`azure_ai_with_explicit_settings.py`](azure_ai_with_explicit_settings.py) | Shows how to create an agent with explicitly configured `AzureAIAgentClient` settings, including project endpoint, model deployment, credentials, and agent name. |
| [`azure_ai_with_azure_ai_search.py`](azure_ai_with_azure_ai_search.py) | Demonstrates how to use Azure AI Search with Azure AI agents to search through indexed data. Shows how to configure search parameters, query types, and integrate with existing search indexes. |
| [`azure_ai_with_azure_ai_search.py`](azure_ai_with_azure_ai_search.py) | Demonstrates how to use Azure AI Search with Azure AI agents to search through indexed data using HostedFileSearchTool. Shows how to configure search parameters, query types, and integrate with existing search indexes. |
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this sample present?

@moonbox3
Copy link
Contributor

@farzad528 there are also several pyright typing issues we'll need to address: https://github.com/microsoft/agent-framework/actions/runs/18756209717/job/53508713618?pr=1546#step:5:269

You'll want to make sure you have the pre-commit checks install so they run before committing code: https://github.com/microsoft/agent-framework/blob/main/python/DEV_SETUP.md#after-installing-uv

Copy link
Member

@dmytrostruk dmytrostruk left a comment

Choose a reason for hiding this comment

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

Looks good in general, just need to resolve CI errors and it would be great to add some unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should add this to core/agent_framework/azure so that it's exposed via from agent_framework.azure import ... instead of it purely being tied to the Azure AI (Foundry) package.

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

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants