-
Notifications
You must be signed in to change notification settings - Fork 581
Python: feat(Azure AI Search Context Provider): Add Azure AI Search Context Provider with toggle for "semantic" mode and "agentic" mode in azure ai #1546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
| # 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 |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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.
| # 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 |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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.
| 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.
| # Try to get existing knowledge source | ||
| await self._index_client.get_knowledge_source(knowledge_source_name) | ||
| except Exception: |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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.
| try: | ||
| # Try to get existing Knowledge Base | ||
| await self._index_client.get_agent(self.knowledge_base_name) | ||
| except Exception: |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
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.
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
| | [`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. | |
There was a problem hiding this comment.
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?
|
@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 |
There was a problem hiding this 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.
There was a problem hiding this comment.
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.
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
AzureAISearchContextProviderclass in_search_provider.pywith two retrieval modes:Added a complete example:
azure_ai_with_search_context.pydemonstrating both modesUpdated
README.mdwith documentation and usage guidanceAdded dependency:
azure-search-documents >= 11.7.0b1topyproject.tomlFeatures:
Contribution Checklist