Registry / azure / azure-search-documents

azure-search-documents

JSON →
library11.6.0pypypi✓ verified 35d ago

The `azure-search-documents` library is the Microsoft Azure AI Search client library for Python. Azure AI Search (formerly known as "Azure Cognitive Search") is an AI-powered information retrieval platform that enables developers to build rich search experiences and generative AI applications that combine large language models with enterprise data. The current stable version is 11.6.0, and the library follows a regular release cadence as part of the Azure SDK for Python.

azurevector-searchai-mlllm-agents
Install & Compatibility
Where this runs
tested against v12.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.930 runs
installs and imports cleanly · install 0.0s · import 0.606s · 27.3MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 2.6s · import 0.541s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from azure.search.documents import SearchClient
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexers import SearchIndexerClient
from azure.core.credentials import AzureKeyCredential

Required for Azure Active Directory (AAD) authentication.

from azure.identity import DefaultAzureCredential

This quickstart demonstrates how to instantiate a `SearchClient` using an API key and perform a basic search query and retrieve a document. Ensure `AZURE_SEARCH_SERVICE_ENDPOINT`, `AZURE_SEARCH_INDEX_NAME`, and `AZURE_SEARCH_API_KEY` environment variables are set. Replace 'hotelName', 'id', and 'rating' with actual field names from your index schema.

import os from azure.core.credentials import AzureKeyCredential from azure.search.documents import SearchClient # Set environment variables for your Azure AI Search service endpoint, API key, and index name service_endpoint = os.environ.get("AZURE_SEARCH_SERVICE_ENDPOINT", "") index_name = os.environ.get("AZURE_SEARCH_INDEX_NAME", "") api_key = os.environ.get("AZURE_SEARCH_API_KEY", "") if not service_endpoint or not index_name or not api_key: raise ValueError("Please set AZURE_SEARCH_SERVICE_ENDPOINT, AZURE_SEARCH_INDEX_NAME, and AZURE_SEARCH_API_KEY environment variables.") # Create a SearchClient search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(api_key)) # Example: Search for documents results = search_client.search(search_text="office") print("Search Results:") for result in results: print(f"ID: {result['id']}, Name: {result['hotelName']}") # Adjust field names based on your index schema # Example: Get a single document by key document_key = "23" try: document = search_client.get_document(key=document_key) print(f"\nDetails for document '{document_key}':") print(f"Name: {document['hotelName']}") # Adjust field name based on your index schema print(f"Rating: {document['rating']}") # Adjust field name based on your index schema except Exception as e: print(f"\nError retrieving document '{document_key}': {e}")
Debug
Known footguns
breakingVersion 11 (`azure-search-documents`) is a complete redesign of the client library from previous versions (e.g., `Microsoft.Azure.Search` v10). It introduces new client classes (`SearchClient`, `SearchIndexClient`, `SearchIndexerClient`) and significant API and naming differences, consolidating functionality from four packages into one.
breakingAzure AI Search API versions are updated regularly, and older preview versions (e.g., `2023-07-01-preview` for vector search) are deprecated and no longer supported. Migrating to newer API versions may require changes to vector search configurations and other features.
gotchaAlways use a query API key for client-side applications to restrict access and operations to read-only queries. Admin keys grant full read-write access to the search service and should be protected and only used for administrative tasks.
gotchaModifying or removing an existing field in an Azure AI Search index's schema is not allowed directly. To change an index schema (e.g., changing field types, adding/removing fields, making a field filterable), you must create an entirely new index with the desired schema, re-populate it with all documents, and then update your application to point to the new index.
gotchaFiltering in Azure AI Search is case-sensitive. A filter for `Make eq 'toyota'` will not match a document where `Make` is 'Toyota' or 'TOYOTA'.
gotchaIn hybrid search, if you intend to apply a strict filter (e.g., using regular expressions in `search_text`), unexpected results might occur because vector search always returns a `k` number of matches, which are then combined. For hard filters where non-matching documents must be excluded, use the `filter` argument with OData syntax.
breakingTo connect to Azure AI Search, the service endpoint, API key, and typically the index name must be provided. These are commonly configured via environment variables (e.g., `AZURE_SEARCH_SERVICE_ENDPOINT`, `AZURE_SEARCH_API_KEY`, `AZURE_SEARCH_INDEX_NAME`) or passed as arguments to client constructors. Failure to provide this essential connection information will prevent the client from initializing or connecting to the service.
gotchaThe Azure AI Search client library requires essential configuration (service endpoint, index name, and API key) to be provided for successful initialization and operation. Failure to provide these credentials will result in client instantiation or connection errors.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
23 hits · last 30 days
bytedance
7
gptbot
4
ahrefsbot
4
amazonbot
4
claudebot
2
Resources