Skip to content

Python: Alternative fix for #1546 - Add comprehensive tests and fix CI issues for Azure AI Search Context Provider#2247

Closed
hayato-kishikawa wants to merge 6 commits intomicrosoft:mainfrom
hayato-kishikawa:feature/azure-ai-search-agentic-rag
Closed

Python: Alternative fix for #1546 - Add comprehensive tests and fix CI issues for Azure AI Search Context Provider#2247
hayato-kishikawa wants to merge 6 commits intomicrosoft:mainfrom
hayato-kishikawa:feature/azure-ai-search-agentic-rag

Conversation

@hayato-kishikawa
Copy link
Contributor

@hayato-kishikawa hayato-kishikawa commented Nov 15, 2025

Context

This PR provides an alternative fix for #1546 by @farzad528.

Why an alternative PR?

PR #1546 has excellent implementation (633 lines) but has been blocked by CI issues since Nov 2nd (13 days). I attempted to collaborate by offering patches, but decided to submit this alternative PR to maintain momentum while remaining transparent about the situation.

Credit where it's due: The core Azure AI Search Context Provider implementation is entirely @farzad528's work. I only added CI fixes and comprehensive tests.

Relationship with #1546

Farzad Sunavala and others added 6 commits November 15, 2025 21:44
- Fixes mypy error: Cannot assign to final name 'DEFAULT_CONTEXT_PROMPT'
- Base class ContextProvider already defines this as Final
- Instance variable self.context_prompt correctly set in __init__ (Line 197)

Related to microsoft#1546
Added comprehensive test coverage for Azure AI Search provider:
- Agentic mode end-to-end flow (invoking → retrieval)
- Agentic mode empty response fallback handling
- Auto-discovery exception handling for network errors
- Semantic search with semantic_configuration_name parameter

Coverage improved from 73% to 84% (target: 80%+)

Test results: 25 passed, 0 failed
Added 4 comprehensive tests for vector field auto-discovery (lines 351-384):
- test_single_vector_field_with_embedding_function: Tests successful auto-discovery when embedding function is provided
- test_single_vector_field_warning_without_embedding: Tests warning when vector field found but no embedding function
- test_multiple_vector_fields_warning: Tests warning when multiple vector fields detected
- test_index_client_cleanup_when_not_provided: Tests proper cleanup of internally-created index client

Coverage improved from 84% to 91% (target: 90%+)

Test results: 29 passed, 0 failed

Key fix: Patched Azure SDK classes at source (azure.search.documents.*.aio) instead of module level to handle dynamic imports correctly
Systematically added comprehensive tests across 4 phases:

**Phase 1 (91%→94%):** Agentic mode validation + resource cleanup
- 7 tests for parameter validation (init-time and runtime)
- Retrieval client cleanup verification

**Phase 2 (94%→95%):** Import error handling
- 1 test for SDK unavailability (ImportError)

**Phase 3 (95%→96%):** Edge cases and alternative paths
- Empty search results handling
- External index client usage
- Early return optimization

**Phase 4 (96%→98%):** Helper functions
- Document text extraction fallback logic

Coverage: 91% → 98% (186 statements, 3 missed)
Tests: 29 → 41 passed (+12 tests)

**Remaining 3 uncovered lines (acceptable):**
- Lines 60-61: Module import exception (impossible to unit test)
- Line 580: Agentic RuntimeError (requires complex SDK mocking)

All tests pass. 98% coverage exceeds industry best practices.
@hayato-kishikawa hayato-kishikawa force-pushed the feature/azure-ai-search-agentic-rag branch 2 times, most recently from d77b042 to 968acb3 Compare November 15, 2025 14:24
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.

2 participants