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.
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.
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.

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 generate embeddings, create and load an index, and run several vector queries. For more vector search Python demos, see cognitive-search-vector-pr/demo-python.
ChatGPT + Enterprise data with Azure OpenAI and Cognitive Search 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.

Tip

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