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 pypi.org/project/azure-search-documents/
API reference azure-search-documents
API test cases github.com/Azure/azure-sdk-for-python/tree/main/sdk/search/azure-search-documents/tests
Source code github.com/Azure/azure-sdk-for-python/tree/main/sdk/search/azure-search-documents

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.

Demos

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 azure.search.documents library in the Azure SDK for Python to create, load, and query a vector index.
azure-search-integrated-vectorization-sample.ipynb Extends the vector indexing workflow to include integrated data chunking and embedding.
azure-search-vector-image-index-creation-python-sample.ipynb Demonstrates multimodal search over text and images.
azure-search-custom-vectorization-sample.ipynb Demonstrates custom vectorization.
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 azure.search.documents 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.

Tip

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