Deploy and test ProductsChat
Deploy the queue worker and ask it a question about an already indexed manual.
Requires
- Products is running in AKS and accessible over HTTPS. The worker uses that cluster's
bootstrapConfigMap, the lab's container registry, PostgreSQL, Key Vault, App Configuration, and the chat request and reply queues. - The Embedder test left Cedar Desk Fan
readyin Products, and its embedding model is still deployed. Check region availability and quota for the chat model in the model step. - The software checks have passed and Docker is running in Linux container mode. In
ai200-lab, load the lab settings and keep./kubeconfigavailable. Azure CLI must be signed in to the lab subscription with permission to create resources and assign roles.
Products sends a request through Service Bus. The worker embeds the question, finds matching passages in PostgreSQL, calls the chat model and sends a reply that Products saves for the browser.
Clone ProductsChat
From ai200-lab, clone the worker if you haven't already. Open worker.py and find where it receives a request and sends its reply.
git clone https://github.com/tuba-labs/ai-200-products-chat.git
Deploy the chat model
az cognitiveservices model list shows the available versions of gpt-5-mini. Look for 2025-08-07. az cognitiveservices usage list reads regional quota and usage. Check for at least 60 free units of Global Standard chat quota.
az cognitiveservices model list --subscription "$SUBSCRIPTION" --location "$LOCATION" --query "[?model.name=='gpt-5-mini'].{Model:model.name,Version:model.version}" --output table
az cognitiveservices usage list --subscription "$SUBSCRIPTION" --location "$LOCATION" --output table
Use the models.bicep file from the Embedder chapter. stage=chat selects the chat deployment on the existing model account. --mode Incremental keeps the embedding deployment because this stage omits it from the template. The worker uses it to embed questions in the same way as the manuals. Download models.bicep
az deployment group create --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name chat-model --mode Incremental --template-file models.bicep --parameters "location=$LOCATION" "name=$STEM-ai" stage=chat --query properties.provisioningState --output tsv
Give the worker its own identity
az identity create gives ProductsChat its own managed identity and returns the principal ID used for role assignments. Read the AKS issuer URL from the compute deployment outputs to use in the federated credential. The worker uses the queues created for Products.
$SCOPE = "/subscriptions/$SUBSCRIPTION/resourceGroups/$GROUP/providers"
$PRINCIPAL_ID = az identity create --subscription $SUBSCRIPTION --resource-group $GROUP --name "$STEM-chat" --location $LOCATION --query principalId --output tsv
$ISSUER = az deployment group show --subscription $SUBSCRIPTION --resource-group $GROUP --name compute --query properties.outputs.issuer.value --output tsv
echo "SCOPE=$SCOPE"
echo "PRINCIPAL_ID=$PRINCIPAL_ID"
echo "ISSUER=$ISSUER"
SCOPE="/subscriptions/$SUBSCRIPTION/resourceGroups/$GROUP/providers"
PRINCIPAL_ID=$(az identity create --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-chat" --location "$LOCATION" --query principalId --output tsv)
ISSUER=$(az deployment group show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name compute --query properties.outputs.issuer.value --output tsv)
echo "SCOPE=$SCOPE"
echo "PRINCIPAL_ID=$PRINCIPAL_ID"
echo "ISSUER=$ISSUER"
Create a federated credential so the chat service account in the products namespace can authenticate as the worker identity. Assign these roles to that identity. Azure built-in roles catalog
| Role | Access granted in this lab |
|---|---|
App Configuration Data Reader | Read connection, model, and retrieval 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 and chat models on the lab's model account. |
Azure Service Bus Data Receiver | Receive and acknowledge questions on chat-requests. |
Azure Service Bus Data Sender | Send answers to chat-replies. |
az identity federated-credential create --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --identity-name "$STEM-chat" --name workshop --issuer "$ISSUER" --subject system:serviceaccount:products:chat --audiences api://AzureADTokenExchange --output none
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
az role assignment create --subscription "$SUBSCRIPTION" --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal --role 'Azure Service Bus Data Receiver' --scope "$SCOPE/Microsoft.ServiceBus/namespaces/$STEM-bus/queues/chat-requests" --output none
az role assignment create --subscription "$SUBSCRIPTION" --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal --role 'Azure Service Bus Data Sender' --scope "$SCOPE/Microsoft.ServiceBus/namespaces/$STEM-bus/queues/chat-replies" --output none
Configure retrieval
az appconfig kv set stores the chat deployment name, the maximum number of retrieved passages, and the minimum similarity. The worker loads these workshop settings at startup.
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:chat-deployment --value chat --yes --output none
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:retrieval-count --value 3 --yes --output none
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --label workshop --key rag:min-similarity --value 0.35 --yes --output none
Build and push the worker image
Read the registry hostname from the same Azure Container Registry used by Products. Check that ACR_HOST shows a hostname such as raglab2026acr.azurecr.io.
$ACR_HOST = az acr show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "${STEM}acr" --query loginServer --output tsv
echo "ACR_HOST=$ACR_HOST"
ACR_HOST=$(az acr show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "${STEM}acr" --query loginServer --output tsv)
echo "ACR_HOST=$ACR_HOST"
Use the abbreviated Git commit ID of your ProductsChat checkout as IMAGE_TAG. The printed tag identifies the commit you built from.
$IMAGE_TAG = git -C ai-200-products-chat rev-parse --short=12 HEAD
echo "IMAGE_TAG=$IMAGE_TAG"
IMAGE_TAG=$(git -C ai-200-products-chat rev-parse --short=12 HEAD)
echo "IMAGE_TAG=$IMAGE_TAG"
Sign Docker in to the registry. Continue when Azure CLI prints Login Succeeded.
az acr login --subscription "$SUBSCRIPTION" --name "${STEM}acr"
Build a Linux AMD64 image for the AKS node. --tag gives the image its registry hostname, repository name, and commit tag.
docker build --platform linux/amd64 --tag "$ACR_HOST/products-chat:$IMAGE_TAG" ./ai-200-products-chat
Once the build succeeds, push the tagged image to the registry. Docker prints its digest when the push succeeds. AKS already has permission to pull from this registry.
docker push "$ACR_HOST/products-chat:$IMAGE_TAG"
Deploy one worker
Save chat.yaml in ai200-lab. The Deployment keeps one worker running and reads the settings from the existing bootstrap ConfigMap.
az identity show reads the chat identity's client ID for the service account annotation. Check that CHAT_CLIENT_ID shows a GUID.
$CHAT_CLIENT_ID = az identity show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-chat" --query clientId --output tsv
echo "CHAT_CLIENT_ID=$CHAT_CLIENT_ID"
CHAT_CLIENT_ID=$(az identity show --subscription "$SUBSCRIPTION" --resource-group "$GROUP" --name "$STEM-chat" --query clientId --output tsv)
echo "CHAT_CLIENT_ID=$CHAT_CLIENT_ID"
Check that CHAT_CLIENT_ID, ACR_HOST, and IMAGE_TAG have the printed values, then apply the downloaded template.
sed \
-e "s|\${ACR_HOST}|$ACR_HOST|g" \
-e "s|\${CHAT_CLIENT_ID}|$CHAT_CLIENT_ID|g" \
-e "s|\${IMAGE_TAG}|$IMAGE_TAG|g" \
'./chat.yaml' |
kubectl --kubeconfig ./kubeconfig apply -f -
(Get-Content -LiteralPath './chat.yaml' -Raw).
Replace('${ACR_HOST}', $ACR_HOST).
Replace('${CHAT_CLIENT_ID}', $CHAT_CLIENT_ID).
Replace('${IMAGE_TAG}', $IMAGE_TAG) |
kubectl --kubeconfig ./kubeconfig apply -f -
Template chat.yaml
Wait for Kubernetes to report that the Deployment has successfully rolled out.
kubectl --kubeconfig ./kubeconfig -n products rollout status deployment/products-chat --timeout=300s
Read the worker's startup logs.
kubectl --kubeconfig ./kubeconfig -n products logs deployment/products-chat --tail=20
worker.py receives Service Bus requests serially, with prefetch zero. It stays at one replica throughout this workshop.
Test the worker with the indexed manual
Use the same Products site and sign-in as the upload test. Select Chat about products in the site header, or run this command from the lab folder and open the URL it prints.
echo "https://$(kubectl --kubeconfig ./kubeconfig -n products get service products -o 'jsonpath={.status.loadBalancer.ingress[0].ip}')/chat"
In Ask a question, select Cedar Desk Fan from Product. Enter How do I enable the shutoff timer? in Question, then click Queue question.
Wait for the Answer. Look for the two-second button hold and the 45-minute timer in the cited passage. Copy the request ID beneath the answer.
Find that request ID in the worker logs. The completed entry includes a correlation ID and a source count.
kubectl --kubeconfig ./kubeconfig -n products logs deployment/products-chat --tail=30
Ask a question the manual cannot answer
With Cedar selected, ask for the fan's warranty duration. The manual contains no warranty duration. Check that the answer says there is insufficient information.
How retrieval and prompting work
chat.py embeds the question, filters ready chunks by optional product ID, ranks cosine distance with <=>, and supplies the best passages to the chat model. No useful evidence means an insufficient-information answer.
Manuals are untrusted reference data, separated from application instructions. The model receives context, not secrets or tools; citations let you inspect support.
Try changing the retrieval count
Change the retrieval count in App Configuration from three passages to one. Check that Azure CLI prints 1.
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --key rag:retrieval-count --label workshop --value 1 --yes --query value --output tsv
Restart the worker to load the new setting and wait for the rollout to finish.
kubectl --kubeconfig ./kubeconfig -n products rollout restart deployment/products-chat
kubectl --kubeconfig ./kubeconfig -n products rollout status deployment/products-chat --timeout=300s
Check that the startup logs show retrieval_count=1. Ask a new question. The answer should cite at most one source.
kubectl --kubeconfig ./kubeconfig -n products logs deployment/products-chat --tail=20
Restore three passages
Set rag:retrieval-count back to three in App Configuration.
az appconfig kv set --subscription "$SUBSCRIPTION" --name "$STEM-cfg" --auth-mode login --key rag:retrieval-count --label workshop --value 3 --yes --query value --output tsv
When Azure CLI prints 3, restart the worker and wait for the rollout to finish.
kubectl --kubeconfig ./kubeconfig -n products rollout restart deployment/products-chat
kubectl --kubeconfig ./kubeconfig -n products rollout status deployment/products-chat --timeout=300s
Request/reply and retry guarantees
Products commits question + outbox, returns HTTP 202, and sends to chat-requests. The worker validates stored request/correlation IDs, caches the result before sending to chat-replies, then acknowledges. Products persists the correlated reply before acknowledging it; the browser polls by request ID.
A receive locks work; Complete acknowledges, Abandon retries. Initial lock: one minute; automatic renewal: up to ten minutes; application deadline: eight minutes. Persistent failure/timeouts end browser polling. Repeated failures reach the dead-letter queue.
Advisory locks, cached results and guarded updates prevent duplicate displayed answers. A crash before caching can repeat a paid model call; delivery is not exactly-once. Contracts: chat-request.schema.json, chat-reply.schema.json.