Skip to content

Commit 04e711c

Browse files
farzad528claude
andauthored
Python: Feature/azure ai search agentic rag (search as separate package) (#2328)
* Python: Fix pyright errors and move search provider to core (#1546) * address pablo coments * update azure ai search pypi version to latest prev * init update * Fix MyPy type annotation errors in search provider - Add type annotation to DEFAULT_CONTEXT_PROMPT - Add type annotation to vectorizable_fields - Add union type annotation to vector_queries * Fix DEFAULT_CONTEXT_PROMPT MyPy error and update test - Rename DEFAULT_CONTEXT_PROMPT to _DEFAULT_SEARCH_CONTEXT_PROMPT to avoid conflict with base class Final variable - Update test to use new constant name - All core package tests passing (1123 passed) * Python: Move Azure AI Search to separate package per PR feedback Addresses reviewer feedback from PR #1546 by isolating the beta dependency (azure-search-documents==11.7.0b2) into a new agent-framework-aisearch package. Changes: - Created new agent-framework-aisearch package with complete structure - Moved AzureAISearchContextProvider from core to aisearch package - Added AzureAISearchSettings class for environment variable auto-loading - Added support for direct API key string (auto-converts to AzureKeyCredential) - Added azure_openai_api_key parameter for Knowledge Base authentication - Updated embedding_function type to Callable[[str], Awaitable[list[float]]] - Moved Role import to top-level imports - Maintained lazy loading through agent_framework.azure module - Removed beta dependency from core package - Updated all tests to use new package location - All quality checks pass: ruff format/lint, pyright, mypy (0 errors) - All 21 unit tests pass with 59% coverage Semantic search mode verified working with both API key and managed identity authentication. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Python: Clarify top_k parameter only applies to semantic mode Updated documentation to clarify that the top_k parameter only affects semantic search mode. In agentic mode, the server-side Knowledge Base determines retrieval based on query complexity and reasoning effort. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Python: Add Knowledge Base output mode and retrieval reasoning effort parameters Added support for configurable Knowledge Base behavior in agentic mode: - knowledge_base_output_mode: "extractive_data" (default) or "answer_synthesis" Some knowledge sources require answer_synthesis mode for proper functionality. - retrieval_reasoning_effort: "minimal" (default), "medium", or "low" Controls query planning complexity and multi-hop reasoning depth. These parameters give users fine-grained control over Knowledge Base behavior and enable support for knowledge sources that require answer synthesis. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * effort and outputmode query params * Address PR review feedback for Azure AI Search context provider * comments eduward * ed latest comments --------- Co-authored-by: Farzad Sunavala <farzad.sunavala.enovate.ai> Co-authored-by: farzad528 <farzad528@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent ab3d898 commit 04e711c

14 files changed

Lines changed: 2330 additions & 0 deletions

File tree

python/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ AZURE_AI_PROJECT_ENDPOINT=""
33
AZURE_AI_MODEL_DEPLOYMENT_NAME=""
44
# Bing connection for web search (optional, used by samples with web search)
55
BING_CONNECTION_ID=""
6+
# Azure AI Search (optional, used by AzureAISearchContextProvider samples)
7+
AZURE_SEARCH_ENDPOINT=""
8+
AZURE_SEARCH_API_KEY=""
9+
AZURE_SEARCH_INDEX_NAME=""
10+
AZURE_SEARCH_SEMANTIC_CONFIG=""
11+
AZURE_SEARCH_KNOWLEDGE_BASE_NAME=""
12+
# Note: For agentic mode Knowledge Bases, also set AZURE_OPENAI_ENDPOINT below
13+
# (different from AZURE_AI_PROJECT_ENDPOINT - Knowledge Base needs OpenAI endpoint for model calls)
614
# OpenAI
715
OPENAI_API_KEY=""
816
OPENAI_CHAT_MODEL_ID=""

python/packages/aisearch/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

python/packages/aisearch/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Get Started with Microsoft Agent Framework Azure AI Search
2+
3+
Please install this package via pip:
4+
5+
```bash
6+
pip install agent-framework-aisearch --pre
7+
```
8+
9+
## Azure AI Search Integration
10+
11+
The Azure AI Search integration provides context providers for RAG (Retrieval Augmented Generation) capabilities with two modes:
12+
13+
- **Semantic Mode**: Fast hybrid search (vector + keyword) with semantic ranking
14+
- **Agentic Mode**: Multi-hop reasoning using Knowledge Bases for complex queries
15+
16+
### Basic Usage Example
17+
18+
See the [Azure AI Search context provider examples](https://github.com/microsoft/agent-framework/tree/main/python/samples/getting_started/agents/azure_ai/) which demonstrate:
19+
20+
- Semantic search with hybrid (vector + keyword) queries
21+
- Agentic mode with Knowledge Bases for complex multi-hop reasoning
22+
- Environment variable configuration with Settings class
23+
- API key and managed identity authentication
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) Microsoft. All rights reserved.
2+
3+
import importlib.metadata
4+
5+
from ._search_provider import AzureAISearchContextProvider, AzureAISearchSettings
6+
7+
try:
8+
__version__ = importlib.metadata.version(__name__)
9+
except importlib.metadata.PackageNotFoundError:
10+
__version__ = "0.0.0" # Fallback for development mode
11+
12+
__all__ = [
13+
"AzureAISearchContextProvider",
14+
"AzureAISearchSettings",
15+
"__version__",
16+
]

python/packages/aisearch/agent_framework_aisearch/_search_provider.py

Lines changed: 914 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[project]
2+
name = "agent-framework-aisearch"
3+
description = "Azure AI Search integration for Microsoft Agent Framework."
4+
authors = [{ name = "Microsoft", email = "af-support@microsoft.com"}]
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
version = "1.0.0b251118"
8+
license-files = ["LICENSE"]
9+
urls.homepage = "https://aka.ms/agent-framework"
10+
urls.source = "https://github.com/microsoft/agent-framework/tree/main/python"
11+
urls.release_notes = "https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true"
12+
urls.issues = "https://github.com/microsoft/agent-framework/issues"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Development Status :: 4 - Beta",
16+
"Intended Audience :: Developers",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"Programming Language :: Python :: 3.13",
22+
"Programming Language :: Python :: 3.14",
23+
"Typing :: Typed",
24+
]
25+
dependencies = [
26+
"agent-framework-core",
27+
"azure-search-documents==11.7.0b2",
28+
]
29+
30+
[tool.uv]
31+
prerelease = "if-necessary-or-explicit"
32+
environments = [
33+
"sys_platform == 'darwin'",
34+
"sys_platform == 'linux'",
35+
"sys_platform == 'win32'"
36+
]
37+
38+
[tool.uv-dynamic-versioning]
39+
fallback-version = "0.0.0"
40+
41+
[tool.pytest.ini_options]
42+
testpaths = 'tests'
43+
addopts = "-ra -q -r fEX"
44+
asyncio_mode = "auto"
45+
asyncio_default_fixture_loop_scope = "function"
46+
filterwarnings = [
47+
"ignore:Support for class-based `config` is deprecated:DeprecationWarning:pydantic.*"
48+
]
49+
timeout = 120
50+
51+
[tool.ruff]
52+
extend = "../../pyproject.toml"
53+
exclude = ["examples"]
54+
55+
[tool.coverage.run]
56+
omit = [
57+
"**/__init__.py"
58+
]
59+
60+
[tool.pyright]
61+
extends = "../../pyproject.toml"
62+
exclude = ['tests']
63+
64+
[tool.mypy]
65+
plugins = ['pydantic.mypy']
66+
strict = true
67+
python_version = "3.10"
68+
ignore_missing_imports = true
69+
disallow_untyped_defs = true
70+
no_implicit_optional = true
71+
check_untyped_defs = true
72+
warn_return_any = true
73+
show_error_codes = true
74+
warn_unused_ignores = false
75+
disallow_incomplete_defs = true
76+
disallow_untyped_decorators = true
77+
78+
[tool.bandit]
79+
targets = ["agent_framework_aisearch"]
80+
exclude_dirs = ["tests"]
81+
82+
[tool.poe]
83+
executor.type = "uv"
84+
include = "../../shared_tasks.toml"
85+
[tool.poe.tasks]
86+
mypy = "mypy --config-file $POE_ROOT/pyproject.toml agent_framework_aisearch"
87+
test = "pytest --cov=agent_framework_aisearch --cov-report=term-missing:skip-covered tests"
88+
89+
[build-system]
90+
requires = ["flit-core >= 3.11,<4.0"]
91+
build-backend = "flit_core.buildapi"

0 commit comments

Comments
 (0)