MCPcopy
hub / github.com/Azure-Samples/azure-search-openai-demo

github.com/Azure-Samples/azure-search-openai-demo @main sqlite

repository ↗ · DeepWiki ↗
1,431 symbols 5,575 edges 164 files 251 documented · 18%
README

RAG chat app with Azure OpenAI and Azure AI Search (Python)

This solution creates a ChatGPT-like frontend experience over your own documents using RAG (Retrieval Augmented Generation). It uses Azure OpenAI Service to access GPT models, and Azure AI Search for data indexing and retrieval.

This solution's backend is written in Python. There are also JavaScript, .NET, and Java samples based on this one. Learn more about developing AI apps using Azure AI Services.

Open in GitHub Codespaces Open in Dev Containers Open in VS Code for the Web

Important Security Notice

This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features. See our productionizing guide for tips, and consult the Azure OpenAI Landing Zone reference architecture for more best practices.

Table of Contents

Chat screen

📺 Watch a video overview of the app.

This sample demonstrates a few approaches for creating ChatGPT-like experiences over your own data using the Retrieval Augmented Generation pattern. It uses Azure OpenAI Service to access a GPT model (gpt-5.4-mini), and Azure AI Search for data indexing and retrieval.

The repo includes sample data so it's ready to try end to end. In this sample application we use a fictitious company called Zava, and the experience allows its employees to ask questions about the benefits, internal policies, as well as job descriptions and roles.

Features

  • Chat (multi-turn) interface
  • Renders citations and thought process for each answer
  • Includes settings directly in the UI to tweak the behavior and experiment with options
  • Integrates Azure AI Search for indexing and retrieval of documents, with support for many document formats as well as cloud data ingestion
  • Optional usage of multimodal models to reason over image-heavy documents
  • Optional addition of speech input/output for accessibility
  • Optional automation of user login and data access via Microsoft Entra
  • Performance tracing and monitoring with Application Insights

Architecture Diagram

RAG Architecture

Azure account requirements

IMPORTANT: In order to deploy and run this example, you'll need:

Cost estimation

Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. However, you can try the Azure pricing calculator for the resources below.

  • Azure Container Apps: Default host for app deployment as of 10/28/2024. See more details in the ACA deployment guide. Consumption plan with 1 CPU core, 2 GB RAM, minimum of 0 replicas. Pricing with Pay-as-You-Go. Pricing
  • Azure Container Registry: Basic tier. Pricing
  • Azure App Service: Only provisioned if you deploy to Azure App Service following the App Service deployment guide. Basic Tier with 1 CPU core, 1.75 GB RAM. Pricing per hour. Pricing
  • Azure OpenAI: Standard tier, GPT and Ada models. Pricing per 1K tokens used, and at least 1K tokens are used per question. Pricing
  • Azure AI Document Intelligence: SO (Standard) tier using pre-built layout. Pricing per document page, sample documents have 261 pages total. Pricing
  • Azure AI Search: Basic tier, 1 replica, free level of semantic search. Pricing per hour. Pricing
  • Azure Blob Storage: Standard tier with ZRS (Zone-redundant storage). Pricing per storage and read operations. Pricing
  • Azure Cosmos DB: Only provisioned if you enabled chat history with Cosmos DB. Serverless tier. Pricing per request unit and storage. Pricing
  • Azure AI Vision: Only provisioned if you enabled multimodal approach. Pricing per 1K transactions. Pricing
  • Azure AI Content Understanding: Only provisioned if you enabled media description. Pricing per 1K images. Pricing
  • Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. Pricing

To reduce costs, you can switch to free SKUs for various services, but those SKUs have limitations. See this guide on deploying with minimal costs for more details.

⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use, either by deleting the resource group in the Portal or running azd down.

Getting Started

You have a few options for setting up this project. The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up locally if desired.

GitHub Codespaces

You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:

Open in GitHub Codespaces

Once the codespace opens (this may take several minutes), open a terminal window.

VS Code Dev Containers

A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:

  1. Start Docker Desktop (install it if not already installed)
  2. Open the project: Open in Dev Containers

  3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.

Local environment

  1. Install the required tools:

    • Azure Developer CLI
    • Python 3.10, 3.11, 3.12, 3.13, or 3.14
    • Important: Python and the pip package manager must be in the path in Windows for the setup scripts to work.
    • Important: Ensure you can run python --version from console. On Ubuntu, you might need to run sudo apt install python-is-python3 to link python to python3.
    • Node.js 20+
    • Git
    • Powershell 7+ (pwsh) - For Windows users only.
    • Important: Ensure you can run pwsh.exe from a PowerShell terminal. If this fails, you likely need to upgrade PowerShell.
  2. Create a new folder and switch to it in the terminal.

  3. Run this command to download the project code:

    shell azd init -t azure-search-openai-demo

    Note that this command will initialize a git repository, so you do not need to clone this repository.

Deploying

The steps below will provision Azure resources and deploy the application code to Azure Container Apps. To deploy to Azure App Service instead, follow the app service deployment guide.

  1. Login to your Azure account:

    shell azd auth login

    For GitHub Codespaces users, if the previous command fails, try:

shell azd auth login --use-device-code

  1. Create a new azd environment:

    shell azd env new

    Enter a name that will be used for the resource group. This will create a new folder in the .azure folder, and set it as the active environment for any calls to azd going forward. 1. (Optional) This is the point where you can customize the deployment by setting environment variables, in order to use existing resources, enable optional features (such as auth or vision), or deploy low-cost options, or deploy with the Azure free trial. 1. Run azd up - This will provision Azure resources and deploy this sample to those resources, including building the search index based on the files found in the ./data folder. - Important: Beware that the resources created by this command will incur immediate costs, primarily from the AI Search resource. These resources may accrue costs even if you interrupt the command before it is fully executed. You can run azd down or delete the resources manually to avoid unnecessary spending. - You will be prompted to select two locations, one for the majority of resources and one for the OpenAI resource, which is currently a short list. That location list is based on the OpenAI model availability table and may become outdated as availability changes. 1. After the application has been successfully deployed you will see a URL printed to the console. Click that URL to interact with the application in your browser. It will look like the following:

'Output from running azd up'

NOTE: It may take 5-10 minutes after you see 'SUCCESS' for the application to be fully deployed. If you see a "Python Developer" welcome screen or an error page, then wait a bit and refresh the page.

Deploying again

If you've only changed the backend/frontend code in the app folder, then you d

Extension points exported contracts — how you extend this code

IHistoryProvider (Interface)
(no doc) [3 implementers]
app/frontend/src/components/HistoryProviders/IProvider.ts
AppServicesToken (Interface)
(no doc)
app/frontend/src/authConfig.ts
AuthSetup (Interface)
(no doc)
app/frontend/src/authConfig.ts
MarkdownViewerProps (Interface)
(no doc)
app/frontend/src/components/MarkdownViewer/MarkdownViewer.tsx
IHelpCalloutProps (Interface)
(no doc)
app/frontend/src/components/HelpCallout/HelpCallout.tsx

Core symbols most depended-on inside this repo

get
called by 287
tests/mocks.py
split_pages
called by 29
app/backend/prepdocslib/textsplitter.py
filename
called by 20
app/backend/prepdocslib/listfilestrategy.py
create_index
called by 20
app/backend/prepdocslib/searchmanager.py
json
called by 20
tests/mocks.py
close
called by 18
app/backend/prepdocslib/listfilestrategy.py
run
called by 18
scripts/manageacl.py
read
called by 18
tests/mocks.py

Shape

Function 843
Method 375
Class 156
Interface 33
Route 21
Enum 3

Languages

Python87%
TypeScript13%

Modules by API surface

tests/test_function_apps.py80 symbols
tests/mocks.py76 symbols
tests/conftest.py73 symbols
tests/test_app.py58 symbols
tests/test_pdfparser.py46 symbols
tests/test_searchmanager.py43 symbols
app/backend/approaches/approach.py41 symbols
tests/test_blob_manager.py40 symbols
tests/test_prepdocslib_textsplitter.py37 symbols
tests/test_chatapproach.py35 symbols
tests/test_cosmosdb.py32 symbols
app/backend/app.py32 symbols

Dependencies from manifests, versioned

@azure/msal-browser4.16.0 · 1×
@azure/msal-react3.0.16 · 1×
@fluentui/react-components9.73.3 · 1×
@fluentui/react-icons2.0.319 · 1×
@fluentui/react-table9.19.14 · 1×
@react-spring/web10.0.3 · 1×
@types/dom-speech-recognition0.0.7 · 1×
@types/dompurify3.2.0 · 1×
@types/node26.0.1 · 1×
@types/react19.2.13 · 1×
@types/react-dom19.2.3 · 1×
@types/react-syntax-highlighter15.5.13 · 1×

For agents

$ claude mcp add azure-search-openai-demo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact