Python: Azure AI Search provider improvements - EmbeddingGenerator, async context manager, KB message handling#4212
Merged
eavanvalkenburg merged 3 commits intomicrosoft:mainfrom Feb 25, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the Azure AI Search context provider with several improvements to support richer embedding workflows, proper resource cleanup, and better knowledge base message handling.
Changes:
- Added support for
SupportsGetEmbeddingsinstances in addition to plain async callables for theembedding_functionparameter - Implemented proper async context manager cleanup with a dedicated
close()method that resets internal state flags - Refactored KB message conversion with dedicated helper methods (
_prepare_messages_for_kb_search,_parse_messages_from_kb_response,_parse_references_to_annotations) - Changed return types from
list[str]tolist[Message]for both search paths, with rich annotation support for KB references
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py | Core changes: Added SupportsGetEmbeddings support, close() method, message conversion helpers, fixed k_nearest_neighbors→k parameter, and unified return types to Message objects |
| python/packages/azure-ai-search/tests/test_aisearch_context_provider.py | Updated all test assertions for new list[Message] return type, added comprehensive test classes for the three new helper methods |
| python/samples/02-agents/context_providers/azure_ai_search/azure_ai_with_search_context_semantic.py | Added optional embedding client configuration for hybrid search demonstration |
| python/samples/02-agents/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py | Updated default retrieval settings and added annotation display in streaming output |
.../samples/02-agents/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py
Outdated
Show resolved
Hide resolved
python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py
Outdated
Show resolved
Hide resolved
python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py
Show resolved
Hide resolved
.../samples/02-agents/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py
Outdated
Show resolved
Hide resolved
Member
- Use separate variable for embeddings result to avoid mypy type reassignment error - Fix test_vectorized_query_with_embedding_function: use real async function instead of AsyncMock which falsely matches SupportsGetEmbeddings protocol Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aeabf8c to
e73908c
Compare
TaoChenOSU
approved these changes
Feb 24, 2026
dmytrostruk
approved these changes
Feb 25, 2026
python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py
Show resolved
Hide resolved
moonbox3
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the Azure AI Search context provider with several fixes and enhancements:
Key Changes
SupportsGetEmbeddingsinstances in addition to plain async callables for theembedding_functionparameter, enabling richer embedding workflows.close()method that properly cleans up all clients (search, index, and retrieval), and refactored__aexit__to delegate to it._prepare_messages_for_kb_searchand_parse_messages_from_kb_responsehelpers that handle both text and image content types between frameworkMessageobjects and KB SDK types.Annotationobjects with all available metadata:doc_key,reranker_score,source_data,reference_type,sensitivity_label, and the raw reference object.Messageobjects —_semantic_searchand_agentic_searchnow both returnlist[Message], simplifying thebefore_runhook.Testing
_prepare_messages_for_kb_search,_parse_messages_from_kb_response, and_parse_references_to_annotationsFixes #3001
Supersedes #3333