Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
from azure.search.documents.models import QueryType
results = client.search(
search_text="what is azure search",
query_type=QueryType.SEMANTIC,
semantic_configuration_name="my-semantic-config",
select=["id", "title", "content"],
top=10
)
for result in results:
print(f"{result['title']}")
if result.get("@search.captions"):
print(f" Caption: {result['@search.captions'][0].text}")
results = client.search(
search_text="*",
facets=["category,count:10", "rating"],
top=0# Only get facets, no documents
)
for facet_name, facet_values in results.get_facets().items():
print(f"{facet_name}:")
for facet in facet_values:
print(f" {facet['value']}: {facet['count']}")
Write clean, idiomatic Python code for Azure AI Search using azure-search-documents.
Installation
pip install azure-search-documents azure-identity
Environment Variables
AZURE_SEARCH_ENDPOINT=https://<search-service>.search.windows.net
AZURE_SEARCH_INDEX_NAME=<index-name>
# For API key auth (not recommended for production)
AZURE_SEARCH_API_KEY=<api-key>
Authentication
DefaultAzureCredential (preferred):
from azure.identity import DefaultAzureCredential
from azure.search.documents import SearchClient
credential = DefaultAzureCredential()
client = SearchClient(endpoint, index_name, credential)
API Key:
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient
client = SearchClient(endpoint, index_name, AzureKeyCredential(api_key))
For LLM-powered Q&A with answer synthesis, see references/agentic-retrieval.md.
Key concepts:
Knowledge Source: Points to a search index
Knowledge Base: Wraps knowledge sources + LLM for query planning and synthesis
Output modes: EXTRACTIVE_DATA (raw chunks) or ANSWER_SYNTHESIS (LLM-generated answers)
Async Pattern
from azure.search.documents.aio import SearchClient
asyncwith SearchClient(endpoint, index_name, credential) as client:
results = await client.search(search_text="query")
asyncfor result in results:
print(result["title"])
Best Practices
Use environment variables for endpoints, keys, and deployment names
Prefer DefaultAzureCredential over API keys for production
Use SearchIndexingBufferedSender for batch uploads (handles batching/retries)
Always define semantic configuration for agentic retrieval indexes
Use create_or_update_index for idempotent index creation
Close clients with context managers or explicit close()
Field Types Reference
EDM Type
Python
Notes
Edm.String
str
Searchable text
Edm.Int32
int
Integer
Edm.Int64
int
Long integer
Edm.Double
float
Floating point
Edm.Boolean
bool
True/False
Edm.DateTimeOffset
datetime
ISO 8601
Collection(Edm.Single)
List[float]
Vector embeddings
Collection(Edm.String)
List[str]
String arrays
Error Handling
from azure.core.exceptions import (
HttpResponseError,
ResourceNotFoundError,
ResourceExistsError
)
try:
result = search_client.get_document(key="123")
except ResourceNotFoundError:
print("Document not found")
except HttpResponseError as e:
print(f"Search error: {e.message}")
When to Use
This skill is applicable to execute the workflow or actions described in the overview.