You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This tutorial provides a comprehensive guide to building a Retrieval Augmented Generation (RAG) solution using Azure AI Content Understanding. It explains the essential components required to design and implement a robust RAG system, highlights best practices for optimizing relevance and accuracy, and outlines the integration points with other Azure services. By the end of this tutorial, you will have a clear understanding of how to leverage Content Understanding to process multimodal data, enhance retrieval precision, and enable generative AI models to deliver contextually rich and accurate responses.
17
17
18
-
Sample code can be found in this [Python notebook]((https://github.com/Azure-Samples/azure-ai-search-with-content-understanding-python#samples)), but we recommend using this walkthrough for context, insights, and for exploring alternative approaches.
19
-
20
18
## Exercises Covered in This Tutorial
21
19
22
20
1.**Creating Analyzers:** Learn how to create reusable analyzers to extract structured content from multimodal data using content extraction.
@@ -38,12 +36,18 @@ To get started, you need **An active Azure subscription**. If you don't have an
38
36
39
37
:::image type="content" source="../media/overview/azure-multi-service-resource.png" alt-text="Screenshot of the multi-service resource page in the Azure portal.":::
40
38
41
-
* In this tutorial, we use the cURL command line tool. If it isn't installed, you can download a version for your dev environment:
39
+
-**Azure AI Search Resource:** Set up an [Azure AI Search resource](https://github.com/tonyeiyalla/azure-ai-search-with-content-understanding-python/blob/tonye-cu-rag/docs/create_azure_ai_service.md) to enable indexing and retrieval of multimodal data.
40
+
-**Azure OpenAI Resource:** Deploy an [Azure OpenAI resource](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) with a chat model to enable conversational interactions.
41
+
-**Embedding Model Deployment:** Ensure you have an embedding model deployed to generate vector representations for semantic search.
42
+
-**API Version:** This tutorial uses the latest preview [API version](https://review.learn.microsoft.com/en-us/rest/api/contentunderstanding/operation-groups?view=rest-contentunderstanding-2024-12-01-preview&preserve-view=true): `2024-12-01-preview`.
43
+
-**Python Environment:** Install [Python 3.11](https://www.python.org/downloads/) to execute the provided code samples and scripts.
44
+
- This tutorial follows this sample code can be found in this [Python notebook]((https://github.com/Azure-Samples/azure-ai-search-with-content-understanding-python#samples)). Follow this [README]() to create essential resources, grant resources the right Access control(IAM) roles and install all packages needed for this tutorial.
42
45
43
-
*[Windows](https://curl.haxx.se/windows/)
44
-
*[Mac or Linux](https://learn2torials.com/thread/how-to-install-curl-on-mac-or-linux-(ubuntu)-or-windows)
46
+
- Additionally, this tutorial utilizes the cURL command-line tool for API interactions. If it is not already installed, you can download it for your development environment:
47
+
-[Windows](https://curl.haxx.se/windows/)
48
+
-[Mac or Linux](https://learn2torials.com/thread/how-to-install-curl-on-mac-or-linux-(ubuntu)-or-windows)
45
49
46
-
* The multimodal data used in this tutorial includes sample documents, including documents, images, audio and video designed to guide you through the process of building a robust RAG solution with Azure AI Content Understanding.
50
+
* The [multimodal data]() used in this tutorial includes sample documents, including documents, images, audio and video designed to guide you through the process of building a robust RAG solution with Azure AI Content Understanding.
47
51
48
52
## Extracting Data with Content Understanding: Key Concepts
49
53
Building a robust multimodal RAG solution begins with extracting and structuring data from diverse content types. Azure AI Content Understanding provides three key components to facilitate this process: **content extraction**, **field extraction**, and **analyzers**. Together, these components form the foundation for creating a unified, reusable, and enhanced data pipeline for RAG workflows.
@@ -197,39 +201,118 @@ First, create a JSON file named `request_body.json` with the following content:
197
201
198
202
---
199
203
204
+
Load all environment variables and libraries from Langchain
200
205
201
-
Before running the following `cURL` commands, make the following changes to the HTTP request:
202
-
203
-
1. Replace `{endpoint}` and `{key}` with the endpoint and key values from your Azure portal Azure AI Services instance.
204
-
1. Replace `{analyzerId}` with the name of the new analyzer and create, such as `myInvoice`.
from langchain_openai import AzureOpenAIEmbeddings
232
+
from langchain.schema import StrOutputParser
233
+
from langchain.schema.runnable import RunnablePassthrough
234
+
from langchain.text_splitter import MarkdownHeaderTextSplitter
235
+
from langchain.vectorstores.azuresearch import AzureSearch
236
+
from langchain_core.prompts import ChatPromptTemplate
237
+
from langchain.schema import Document
238
+
import requests
239
+
import json
240
+
import sys
241
+
import uuid
242
+
from pathlib import Path
243
+
from dotenv import find_dotenv, load_dotenv
244
+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
245
+
246
+
# Add the parent directory to the path to use shared modules
247
+
parent_dir = Path(Path.cwd()).parent
248
+
sys.path.append(str(parent_dir))
207
249
208
-
```bash
209
-
curl -i -X PUT "{endpoint}/contentunderstanding/analyzers/{analyzerId}?api-version=2024-12-01-preview" \
210
-
-H "Ocp-Apim-Subscription-Key: {key}" \
211
-
-H "Content-Type: application/json" \
212
-
-d @request_body.json
213
250
```
251
+
---
214
252
215
-
### PUT Response
216
-
217
-
The 201 (`Created`) response includes an `Operation-Location` header containing a URL that you can use to track the status of this asynchronous creation operation.
253
+
Create analyzers using the schema definition from above
x_ms_useragent="azure-ai-content-understanding-python/content_extraction", # This header is used for sample usage telemetry, please comment out this line if you want to opt out.
291
+
)
223
292
224
-
Upon completion, performing an HTTP GET on the URL returns `"status": "succeeded"`.
293
+
# Iterate through each config and create an analyzer
294
+
for analyzer in analyzer_configs:
295
+
analyzer_id = analyzer["id"]
296
+
template_path = analyzer["template_path"]
297
+
298
+
try:
299
+
300
+
# Create the analyzer using the content understanding client
result = content_understanding_client.poll_result(response)
306
+
print(f"Successfully created analyzer: {analyzer_id}")
307
+
308
+
exceptExceptionas e:
309
+
print(f"Failed to create analyzer: {analyzer_id}")
310
+
print(f"Error: {e}")
225
311
226
-
```bash
227
-
curl -i -X GET "{endpoint}/contentunderstanding/analyzers/{analyzerId}/operations/{operationId}?api-version=2024-12-01-preview" \
228
-
-H "Ocp-Apim-Subscription-Key: {key}"
229
312
```
230
-
231
313
---
232
314
315
+
233
316
## Perform Content and Field Analysis
234
317
**Content extraction** is the first step in the RAG implementation process. It transforms raw multimodal data—such as documents, images, audio, and video—into structured, searchable formats. This foundational step ensures that the content is organized and ready for indexing and retrieval. Content extraction provides the baseline for indexing and retrieval but may not fully address domain-specific needs or provide deeper contextual insights.
235
318
[Learn more]() about content extraction capabilities for each modality.
0 commit comments