-
Notifications
You must be signed in to change notification settings - Fork 838
Python: Enable Agentic Mode to Use Existing Knowledge Bases Without index_name #2464
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 refactors the Azure AI Search Knowledge Base initialization logic to support two distinct paths for using agentic mode: users can now either provide an existing knowledge_base_name directly (simplest approach) or provide index_name to auto-create a Knowledge Base. Previously, all parameters were required even when using an existing KB.
Key Changes
- Added
knowledge_base_namefield toAzureAISearchSettingsfor environment variable support - Updated validation logic to require exactly ONE of
index_nameORknowledge_base_namefor agentic mode - Removed unnecessary
azure_ai_project_endpointparameter - Simplified the sample to demonstrate both usage patterns
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
python/packages/azure-ai-search/agent_framework_azure_ai_search/_search_provider.py |
Core refactoring: added knowledge_base_name to settings, updated validation logic to support both KB paths, made _search_client optional, and refactored _ensure_knowledge_base() to handle existing KB vs auto-creation |
python/packages/azure-ai-search/tests/test_search_provider.py |
Updated tests to cover both agentic mode paths, added tests for validation rules, and cleared environment variables in tests to prevent interference |
python/samples/getting_started/context_providers/azure_ai_search/azure_ai_with_search_context_agentic.py |
Updated sample to demonstrate both usage patterns: using existing KB (simplest) and auto-creating KB from index, with improved documentation |
Motivation and Context
When using agentic mode with Azure AI Search, users with an existing Knowledge Base should be able to use it directly by providing
knowledge_base_namewithout needing to specifyindex_name. Previously, the validation logic requiredindex_namefor agentic mode, which forced users to go through the KB auto-creation path even when they already had a Knowledge Base set up.Description
Updated the
AzureAISearchContextProvidervalidation logic for agentic mode to support two paths:Option 1: Use existing Knowledge Base (simplest)
knowledge_base_nameonlyindex_nameormodel_deployment_namerequiredOption 2: Auto-create Knowledge Base from index
index_name+model_deployment_name+azure_openai_resource_url{index_name}-kbValidation rules:
index_nameORknowledge_base_name(not both, not neither)index_name,model_deployment_nameis requiredAZURE_SEARCH_INDEX_NAME/AZURE_SEARCH_KNOWLEDGE_BASE_NAME)Changes:
knowledge_base_namefield toAzureAISearchSettingsfor env var supportContribution Checklist
index_namecontinues to work