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
Change log https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/search/azure-search-documents/CHANGELOG.md

SDK samples

azure-sdk-for-python/tree/main/sdk/search/azure-search-documents/samples on GitHub provides code samples from the Azure SDK development team, demonstrating API usage.

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
Tutorial-RAG Source code for the Python portion of How to build a RAG solution using Azure AI Search.
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-RAG Source code for the Python portion of Quickstart: Generative search (RAG) with grounding data from Azure AI Search.
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 ranker.
bulk-insert Source code for the Python example of how to use the push APIs to upload and index documents.
azure-function-search Source code for the Python example of an Azure function that sends queries to a search service. You can substitute this Python version of the api code used in the Add search to web sites C# sample.

Demos

azure-search-vector-samples on GitHub provides a comprehensive collection of samples for vector search scenarios, organized by scenario or technology.

azure-search-openai-demo is a ChatGPT-like experience over 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. |

aisearch-openai-rag-audio is "voice to RAG". This sample demonstrates a simple architecture for voice-based generative AI applications that enables Azure AI Search RAG on top of the real-time audio API with full-duplex audio streaming from client devices, while securely handling access to both model and retrieval system. Backend code is written in Python. Frontend code is JavaScript. Watch this video for an introduction. |

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.