Deploy and test ProductsEmbedder
Connect a Blob upload to the Python Function and verify that a fresh manual is indexed.
Requires
- Products is running and you have signed in and verified an upload. The lab has the Functions subnet, Blob Storage, Key Vault, App Configuration, and PostgreSQL with the Flyway schema.
- Your lab region offers Flex Consumption and the embedding model, and your subscription has embedding quota. Check all three in the model step.
- Git and the packaging tools are available. From
ai200-lab, load the lab settings and use the Azure CLI sign-in with permission to create resources and assign roles in that subscription.
Deploy the Function that turns a new manual into vectors. It reads the private blob, calls an embedding model, and stores text and vectors in the database you already checked.
Clone ProductsEmbedder
From ai200-lab, clone the Function app if you haven't already. Open function_app.py and find the Blob trigger and the path it watches.
git clone https://github.com/tuba-labs/ai200-workshop1-products-embedder.git
Deploy an embedding model
The Function stores each embedding as a vector of 1,536 numbers in PostgreSQL. az cognitiveservices model list checks which models and deployment types your region offers. The query selects text-embedding-3-small version 1 and looks for GlobalStandard.
az cognitiveservices model list --subscription "$SUBSCRIPTION" --location "$LOCATION" --query "[?model.name=='text-embedding-3-small' && model.version=='1'].{Model:model.name,Version:model.version,Deployment:model.skus[?name=='GlobalStandard'].name | [0]}" --output table
Expected output At least one row with text-embedding-3-small under Model, 1 under Version, and GlobalStandard under Deployment.
For the first use of Azure AI services in your subscription, register Microsoft.CognitiveServices before checking quota. --wait returns when registration finishes.
az provider register --subscription "$SUBSCRIPTION" --namespace Microsoft.CognitiveServices --wait
az cognitiveservices usage list reads regional quota and usage. The query selects the Global Standard quota for this model. The Bicep template requests 30 capacity units.
az cognitiveservices usage list --subscription "$SUBSCRIPTION" --location "$LOCATION" --query "[?name.value=='OpenAI.GlobalStandard.text-embedding-3-small'].{Quota:name.value,Used:currentValue,Limit:limit}" --output table
Expected output A quota row with Limit - Used of at least 30. For example, Used = 10 and Limit = 50 leaves 40 units available. Azure OpenAI quota
az functionapp list-flexconsumption-locations lists regions that offer the plan that will host the Function. The query selects your lab region.
az functionapp list-flexconsumption-locations --subscription "$SUBSCRIPTION" --query "[?name=='$LOCATION'].name" --output tsv
Expected output Your lab region code, for example swedencentral.
When all three checks pass, save models.bicep in ai200-lab. stage=embedding tells the template to deploy the model account and embedding model. --mode Incremental applies the resource definitions in the template and keeps other resources in the group. ARM deployment modes
az deployment group create --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name embedding-model --mode Incremental --template-file models.bicep --parameters "location=$LOCATION" "name=$STEM-ai" stage=embedding --query properties.provisioningState --output tsv
Continue when the deployment prints Succeeded.
Create the Function App and give it access
Flex Consumption uses the Microsoft.App resource provider to connect to the Functions subnet. Register the provider once for your lab subscription before deploying the app. --wait returns when registration finishes. Flex Consumption subnet requirements
az provider register --subscription "$SUBSCRIPTION" --namespace Microsoft.App --wait
Save a fresh copy of embedder.bicep in ai200-lab. It creates a Python Flex Consumption Function App, joins the Functions subnet, and configures Application Insights. It also assigns these Azure RBAC roles. Azure built-in roles catalog
- On the lab storage account, the Function identity gets
Storage Blob Data Ownerto use host and deployment blobs,Storage Queue Data Contributorto use host queues, andStorage Account Contributorfor storage account operations. - On Application Insights, the Function identity gets
Monitoring Metrics Publisherto send telemetry.
az deployment group create applies the Function template to your lab group. Pass the same location and stem you used for Products so the template can find the shared resources.
az deployment group create --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name embedder --template-file embedder.bicep --parameters "location=$LOCATION" "stem=$STEM" --query properties.provisioningState --output tsv
When the deployment prints Succeeded, assign three Azure RBAC roles to the Function identity so it can connect to PostgreSQL and embed manuals. Azure built-in roles catalog
| Role | Access granted in this lab |
|---|---|
App Configuration Data Reader | Read database and embedding settings from the lab App Configuration store. |
Key Vault Secrets User | Read the PostgreSQL password from the lab vault. |
Cognitive Services OpenAI User | Call the embedding model on the lab's model account. |
az identity show reads the Function identity's principal ID. The role assignment commands use it as the recipient and grant each role at the named resource scope.
$SCOPE = "/subscriptions/$SUBSCRIPTION/resourceGroups/$GROUP/providers"
$PRINCIPAL_ID = az identity show --subscription $SUBSCRIPTION --resource-group $GROUP --name "$STEM-embedder" --query principalId --output tsv
echo "SCOPE=$SCOPE"
echo "PRINCIPAL_ID=$PRINCIPAL_ID"
SCOPE="/subscriptions/$SUBSCRIPTION/resourceGroups/$GROUP/providers"
PRINCIPAL_ID=$(az identity show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-embedder" --query principalId --output tsv)
echo "SCOPE=$SCOPE"
echo "PRINCIPAL_ID=$PRINCIPAL_ID"
az role assignment create --subscription "$SUBSCRIPTION" --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal --role 'App Configuration Data Reader' --scope "$SCOPE/Microsoft.AppConfiguration/configurationStores/$STEM-cfg" --output none
az role assignment create --subscription "$SUBSCRIPTION" --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal --role 'Key Vault Secrets User' --scope "$SCOPE/Microsoft.KeyVault/vaults/$STEM-kv" --output none
az role assignment create --subscription "$SUBSCRIPTION" --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal --role 'Cognitive Services OpenAI User' --scope "$SCOPE/Microsoft.CognitiveServices/accounts/$STEM-ai" --output none
Read the endpoint from the embedding-model deployment outputs. The az appconfig kv set commands store it with the deployment name, vector dimension, and target chunk size under the workshop label.
$MODEL_ENDPOINT = az deployment group show --subscription $SUBSCRIPTION --resource-group $GROUP --name embedding-model --query properties.outputs.endpoint.value --output tsv
echo "MODEL_ENDPOINT=$MODEL_ENDPOINT"
MODEL_ENDPOINT=$(az deployment group show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name embedding-model --query properties.outputs.endpoint.value --output tsv)
echo "MODEL_ENDPOINT=$MODEL_ENDPOINT"
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:model-endpoint --value "$MODEL_ENDPOINT" --yes --output none
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:embedding-deployment --value embedding --yes --output none
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:embedding-dimensions --value 1536 --yes --output none
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:chunk-size --value 900 --yes --output none
Publish the Function code
Create a ZIP from the Embedder application you cloned. Include host.json at the root so Azure can find the Function.
$EMBEDDER_ZIP = Join-Path ([IO.Path]::GetTempPath()) ('embedder-{0}.zip' -f [Guid]::NewGuid())
echo "EMBEDDER_ZIP=$EMBEDDER_ZIP"
$RAG_FILES = Get-ChildItem -LiteralPath ./ai200-workshop1-products-embedder/rag_core -File -Filter '*.py' |
ForEach-Object { "rag_core/$($_.Name)" }
echo "RAG_FILES=$($RAG_FILES -join ', ')"
tar.exe -a -cf "$EMBEDDER_ZIP" -C ./ai200-workshop1-products-embedder host.json function_app.py requirements.txt constraints.txt @RAG_FILES
EMBEDDER_ZIP_DIR=$(mktemp -d)
echo "EMBEDDER_ZIP_DIR=$EMBEDDER_ZIP_DIR"
EMBEDDER_ZIP="$EMBEDDER_ZIP_DIR/embedder.zip"
echo "EMBEDDER_ZIP=$EMBEDDER_ZIP"
(cd ./ai200-workshop1-products-embedder && zip "$EMBEDDER_ZIP" host.json function_app.py requirements.txt constraints.txt rag_core/*.py)
When the ZIP is ready, upload it with az functionapp deployment source config-zip. --src selects the ZIP, and --build-remote true has Azure install the Python dependencies and build the package.
az functionapp deployment source config-zip --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-embedder" --src "$EMBEDDER_ZIP" --build-remote true --output none
After uploading, remove the temporary package.
Remove-Item -LiteralPath "$EMBEDDER_ZIP"
rm -- "$EMBEDDER_ZIP"
rmdir -- "$EMBEDDER_ZIP_DIR"
az functionapp function list lists the functions the host discovered. Look for IndexManual.
az functionapp function list --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-embedder" --query '[].name' -o table
Route new manual uploads to the Function
Read the lab storage account's resource ID. Continue when the output ends with /storageAccounts/ followed by your storage account name.
$STORAGE_ID = az storage account show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "${STEM}st" --query id --output tsv
echo "STORAGE_ID=$STORAGE_ID"
STORAGE_ID=$(az storage account show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "${STEM}st" --query id --output tsv)
echo "STORAGE_ID=$STORAGE_ID"
Create the system topic. --source points to the storage account, --topic-type selects storage events, and --identity systemassigned gives the topic its own identity. The command prints the topic name. Azure CLI may also print a deprecation notice for the identity option. System topic CLI reference
az eventgrid system-topic create --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-events" --location "$LOCATION" --source "$STORAGE_ID" --topic-type Microsoft.Storage.StorageAccounts --identity systemassigned --query name --output tsv
Read the topic identity's principal ID. Continue when it prints a GUID. This identifies the recipient of the role assignment.
$EVENT_IDENTITY = az eventgrid system-topic show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-events" --query identity.principalId --output tsv
echo "EVENT_IDENTITY=$EVENT_IDENTITY"
EVENT_IDENTITY=$(az eventgrid system-topic show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-events" --query identity.principalId --output tsv)
echo "EVENT_IDENTITY=$EVENT_IDENTITY"
Grant the topic identity Storage Blob Data Contributor on the lab storage account so Event Grid can save undelivered events. The role covers blobs across the account. Check that the printed scope matches $STORAGE_ID. The subscription below selects event-deadletters as the destination container. Event Grid managed identity guide · Azure built-in roles catalog
az role assignment create --subscription "$SUBSCRIPTION" --assignee-object-id "$EVENT_IDENTITY" --assignee-principal-type ServicePrincipal --role 'Storage Blob Data Contributor' --scope "$STORAGE_ID" --query scope --output tsv
Azure role assignments can take up to 10 minutes to take effect. Microsoft Learn
Subscribe the Function to new manuals
Read the system topic's resource ID. The output should end with /systemTopics/ and your topic name.
$TOPIC_ID = az eventgrid system-topic show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-events" --query id --output tsv
echo "TOPIC_ID=$TOPIC_ID"
TOPIC_ID=$(az eventgrid system-topic show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-events" --query id --output tsv)
echo "TOPIC_ID=$TOPIC_ID"
Read the Function App's hostname from properties.defaultHostName. Expect a hostname such as raglab2026-embedder.azurewebsites.net.
$FUNCTION_HOST = az resource show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --resource-type Microsoft.Web/sites --name "$STEM-embedder" --query properties.defaultHostName --output tsv
echo "FUNCTION_HOST=$FUNCTION_HOST"
FUNCTION_HOST=$(az resource show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --resource-type Microsoft.Web/sites --name "$STEM-embedder" --query properties.defaultHostName --output tsv)
echo "FUNCTION_HOST=$FUNCTION_HOST"
Read the blobs_extension system key for the Function's Blob webhook. Continue when the printed BLOB_KEY length is greater than zero.
set +x turns off shell tracing while you handle the key.
$BLOB_KEY = az functionapp keys list --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-embedder" --query systemKeys.blobs_extension --output tsv
echo "BLOB_KEY length=$($BLOB_KEY.Length)"
set +x
BLOB_KEY=$(az functionapp keys list --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-embedder" --query systemKeys.blobs_extension --output tsv)
echo "BLOB_KEY length=${#BLOB_KEY}"
Build the JSON request in a temporary file using STORAGE_ID from the topic setup. The request sends new .txt manuals to the Function's Blob webhook. After up to ten delivery attempts or 24 hours, Event Grid uses the topic identity to put undelivered events in event-deadletters. The block prints the temporary file path.
$EVENT_BODY = (New-TemporaryFile).FullName
@"
{
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://$FUNCTION_HOST/runtime/webhooks/blobs?functionName=Host.Functions.IndexManual&code=$([Uri]::EscapeDataString($BLOB_KEY))"
}
},
"filter": {
"includedEventTypes": ["Microsoft.Storage.BlobCreated"],
"subjectBeginsWith": "/blobServices/default/containers/manuals/blobs/products/",
"subjectEndsWith": ".txt"
},
"eventDeliverySchema": "EventGridSchema",
"retryPolicy": { "maxDeliveryAttempts": 10, "eventTimeToLiveInMinutes": 1440 },
"deadLetterWithResourceIdentity": {
"identity": { "type": "SystemAssigned" },
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": { "resourceId": "$STORAGE_ID", "blobContainerName": "event-deadletters" }
}
}
}
}
"@ | Set-Content -LiteralPath $EVENT_BODY -Encoding Ascii
echo "EVENT_BODY=$EVENT_BODY"
EVENT_BODY=$(mktemp)
cat > "$EVENT_BODY" <<EVENT_JSON
{
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "https://$FUNCTION_HOST/runtime/webhooks/blobs?functionName=Host.Functions.IndexManual&code=$(printf '%s' "$BLOB_KEY" | jq -sRr @uri)"
}
},
"filter": {
"includedEventTypes": ["Microsoft.Storage.BlobCreated"],
"subjectBeginsWith": "/blobServices/default/containers/manuals/blobs/products/",
"subjectEndsWith": ".txt"
},
"eventDeliverySchema": "EventGridSchema",
"retryPolicy": { "maxDeliveryAttempts": 10, "eventTimeToLiveInMinutes": 1440 },
"deadLetterWithResourceIdentity": {
"identity": { "type": "SystemAssigned" },
"deadLetterDestination": {
"endpointType": "StorageBlob",
"properties": { "resourceId": "$STORAGE_ID", "blobContainerName": "event-deadletters" }
}
}
}
}
EVENT_JSON
echo "EVENT_BODY=$EVENT_BODY"
az rest --method put creates or updates manual-created on your topic. --body @file loads the request from the file, keeping the webhook key out of the command line. A result of Creating means Azure is still provisioning the subscription.
az rest --subscription "$SUBSCRIPTION" --method put --url "https://management.azure.com$TOPIC_ID/eventSubscriptions/manual-created?api-version=2022-06-15" --body "@$EVENT_BODY" --query properties.provisioningState --output tsv
After the request returns, remove the temporary file and clear the key from your shell.
Remove-Item -LiteralPath $EVENT_BODY
Remove-Variable BLOB_KEY
rm -- "$EVENT_BODY"
unset BLOB_KEY
az eventgrid system-topic event-subscription show reads the subscription state. Wait for Succeeded before uploading.
az eventgrid system-topic event-subscription show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --system-topic-name "$STEM-events" --name manual-created --query provisioningState -o tsv
Test indexing with a fresh manual
After the event subscription reports Succeeded, upload cedar-desk-fan.txt as Cedar Desk Fan in Products. Watch for ready under Manual processing. Open /api/products on the same site to find Cedar's manualId.
Find the indexing result
Open Application Insights in the Azure portal and select <stem>-insights in your lab resource group. Under Monitoring, select Logs. Switch to KQL mode, paste the query below, and select Run.
Find the entry for this manual ID and check that it reports chunks= with a positive count. The Function commits the chunks and the ready status together, so the Products screen also verifies the database write.
// Application Insights Logs. Replace the optional manual filter with the ID
// displayed by Products; do not put passwords or manual text in log queries.
traces
| where timestamp > ago(1h)
| where message contains "manual=" or severityLevel >= 2
| project timestamp, severityLevel, message, operation_Id
| order by timestamp desc
Source: function-logs.kql
ready and the Function trace reports its chunk count. Leave this manual in place for the worker test. Continue to Deploy and test ProductsChat.Chunking and retry safety
chunks.py splits at text boundaries with bounded character counts/overlap. models.py requests 1536-value embeddings. embedding.py locks per manual, checks IDs/checksum, persists processing, then commits chunks + ready atomically.
A ready manual skips indexing. Duplicate Blob receipts may be suppressed before code runs; the database guard also prevents duplicates. Failed attempts persist errors and retry. Delivery is at-least-once; manuals are immutable.