Python samples for Azure AI Search

Learn about the Python code samples that demonstrate the functionality and workflow of an Azure AI Search solution. These samples use the Azure AI Search client library for the Azure SDK for Python, which you can explore through the following links.

Target Link
Package download
API reference azure-search-documents
API test cases
Source code

SDK samples

Code samples from the Azure SDK development team demonstrate API usage. You can find these samples in azure-sdk-for-python/tree/main/sdk/search/azure-search-documents/samples on GitHub.

Samples Description
Authenticate Demonstrates how to configure a client and authenticate to the service.
Index Create-Read-Update-Delete operations Demonstrates how to create, update, get, list, and delete search indexes.
Indexer Create-Read-Update-Delete operations Demonstrates how to create, update, get, list, reset, and delete indexers.
Search indexer data sources Demonstrates how to create, update, get, list, and delete indexer data sources, required for indexer-based indexing of supported Azure data sources.
Synonyms Demonstrates how to create, update, get, list, and delete synonym maps.
Load documents Demonstrates how to upload or merge documents into an index in a data import operation.
Simple query Demonstrates how to set up a basic query.
Filter query Demonstrates setting up a filter expression.
Facet query Demonstrates working with facets.
Semantic ranking sample Shows you how to configure semantic ranking in an index and invoke semantic queries.
Vector search Demonstrates how to get embeddings from a description field and then send vector queries against the data.

Doc samples

Code samples from the Azure AI Search team demonstrate features and workflows. Many of these samples are referenced in tutorials, quickstarts, and how-to articles. You can find these samples in Azure-Samples/azure-search-python-samples on GitHub.

Samples Article
quickstart Source code for the Python portion of Quickstart: Full text search using the Azure SDKs. This article covers the basic workflow for creating, loading, and querying a search index using sample data.
quickstart-semantic-search Source code for the Python portion of Quickstart: Semantic ranking using the Azure SDKs. It shows the index schema and query request for invoking semantic ranking.
search-website-functions-v4 Source code for Tutorial: Add search to web apps. Demonstrates an end-to-end search app that includes a rich client plus components for hosting the app and handling search requests.
tutorial-ai-enrichment Source code for Tutorial: Use Python and AI to generate searchable content from Azure blobs. This article shows how to create a blob indexer with a cognitive skillset, where the skillset creates and transforms raw content to make it searchable or consumable.


A demo repo provides proof-of-concept source code for examples or scenarios shown in demonstrations. Demo solutions aren't designed for adaptation by customers.

Repository Description
azure-search-vector-python-sample.ipynb Uses the library in the Azure SDK for Python to create, load, and query a vector store.
azure-search-integrated-vectorization-sample.ipynb Extends the vector store workflow to include integrated data chunking and embedding.
azure-search-vector-image-index-creation-python-sample.ipynb Demonstrates image embedding.
azure-search-vector-image-python-sample.ipynb Demonstrates image retrieval.
azure-search-vector-python-huggingface-model-sample.ipynb Hugging Face integration.
azure-search-vector-python-langchain-sample.ipynb LangChain integration.
azure-search-vector-python-llamaindex-sample.ipynb Llamaindex integration.
azure-search-openai-demo ChatGPT + Enterprise data with Azure OpenAI Python code showing how to use Azure AI Search with the large language models in Azure OpenAI. For background, see this Tech Community blog post: Revolutionize your Enterprise Data with ChatGPT.

Other samples

The following samples are also published by the Azure AI Search team, but aren't referenced in documentation. Associated readme files provide usage instructions.

Repository Description
azure-search-backup-and-restore.ipynb Uses the library in the Azure SDK for Python to make a local copy of the retrievable fields of a search index, and then push those fields to a new search index.


Try the Samples browser to search for Microsoft code samples in GitHub, filtered by product, service, and language.