Integrate Azure AI Search with Python
Python skill for Azure AI Search - vector, hybrid, semantic search, AI-enriched indexers, and agentic retrieval.
Why it matters
Leverage Azure AI Search's powerful full-text, vector, and hybrid search capabilities within your Python applications. This asset provides the SDK and examples to build intelligent search experiences, enrich data, and manage search indexes.
Outcomes
What it gets done
Implement full-text, vector, and hybrid search queries.
Manage Azure AI Search indexes, data sources, and skillsets.
Integrate AI enrichment capabilities like entity recognition.
Build autocomplete and suggestion features for search interfaces.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-azure-search-documents-py | bash Overview
Azure AI Search SDK for Python
Python skill for Azure AI Search, covering vector-enabled index creation, batched document operations, keyword/vector/semantic/hybrid search, AI-enrichment skillsets, and LLM-powered agentic retrieval over knowledge bases. Use when building full-text, vector, semantic, hybrid, or agentic-retrieval search in a Python application on Azure AI Search.
What it does
This skill builds full-text, vector, and hybrid search applications with AI enrichment using azure-search-documents (Python), authenticated via AzureKeyCredential or DefaultAzureCredential (preferred). It distinguishes four client types: SearchClient (query and document CRUD), SearchIndexClient (index management, synonym maps, knowledge sources/bases), SearchIndexerClient (indexers, data sources, skillsets), and KnowledgeBaseRetrievalClient (agentic, LLM-powered Q&A retrieval). Index creation defines fields (SimpleField, SearchableField, a vector SearchField with a declared dimension count and profile name) plus a VectorSearch configuration wiring an HNSW algorithm to a named profile - extended in a more advanced pattern with an AzureOpenAIVectorizer (resource URL, deployment, and model name) so the service can generate embeddings automatically, and a SemanticSearch configuration prioritizing specific fields for semantic ranking. Document operations cover upload_documents/merge_documents/merge_or_upload_documents/delete_documents directly via SearchClient, or SearchIndexingBufferedSender as a context manager that handles batching and retries automatically for bulk uploads. Search patterns cover basic keyword search with field selection; vector search via VectorizedQuery (a query embedding, k-nearest-neighbors count, and target vector field); hybrid search combining search_text with vector_queries in one call; semantic ranking (query_type=SEMANTIC with a named semantic configuration, surfacing @search.captions); OData filters and faceted counts (top=0 to fetch only facets, no documents); and autocomplete/suggest against a suggester defined at index-creation time (suggesters cannot be added later). An AI-enrichment indexer pipeline is shown end to end: creating a blob data source connection, a skillset with an EntityRecognitionSkill mapping document content to extracted organization entities, and an indexer tying the data source, target index, and skillset together. Agentic retrieval introduces Knowledge Sources (pointing to a search index) and Knowledge Bases (wrapping sources plus an LLM for query planning and answer synthesis), with two output modes - EXTRACTIVE_DATA (raw chunks) or ANSWER_SYNTHESIS (LLM-generated answers). An async variant (azure.search.documents.aio) mirrors the sync API with async with/async for. A field-type reference table maps EDM types (Edm.String, Edm.Int32/Int64, Edm.Double, Edm.Boolean, Edm.DateTimeOffset, Collection(Edm.Single) for vectors, Collection(Edm.String)) to their Python equivalents. Error handling distinguishes ResourceNotFoundError from a general HttpResponseError. Best practices: use hybrid search for best relevance, enable semantic ranking for natural-language queries, index in batches of 100-1000 documents (or use the buffered sender), configure vector dimensions to match the embedding model, use HNSW for large-scale vector search, create suggesters at index-creation time, always define a semantic configuration for agentic-retrieval indexes, and close clients via context managers.
When to use - and when NOT to
Use this skill when building search functionality in Python on Azure AI Search - full-text, vector/embedding, semantic, or hybrid search, AI-enriched content extraction via skillsets, or LLM-powered agentic retrieval over a knowledge base. It is not a deep dive into indexer/skillset orchestration beyond the entity-recognition example shown, nor a full agentic-retrieval implementation guide - both point to companion reference files for detailed patterns.
Inputs and outputs
Input is documents (with optional precomputed embeddings) to index, or search queries (keyword text, vector embeddings, filters, or natural-language questions for agentic retrieval). Output is ranked search results with scores, facet counts, autocomplete/suggestion candidates, semantic captions, or for agentic retrieval, either raw extracted chunks or synthesized LLM answers.
Integrations
Built on Azure AI Search via azure-search-documents, authenticated with Azure Identity's DefaultAzureCredential, with optional AzureOpenAIVectorizer integration for automatic embedding generation and KnowledgeBaseRetrievalClient for LLM-powered agentic retrieval.
pip install azure-search-documents
Who it's for
Python developers building search experiences - full-text, vector, semantic, hybrid, AI-enriched, or agentic retrieval - on Azure AI Search, from basic keyword queries to LLM-synthesized answers over a knowledge base.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.