-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathai-search-api-policy.xml
More file actions
92 lines (88 loc) · 5.2 KB
/
ai-search-api-policy.xml
File metadata and controls
92 lines (88 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<policies>
<inbound>
<base />
<!-- AAD Authorization -->
<!-- Enabled if entra-validate named value is set to true -->
<include-fragment fragment-id="aad-auth" />
<set-header name="api-key" exists-action="delete" />
<!-- Setting cache keys -->
<set-variable name="deployment-id" value="@((string)context.Request.MatchedParameters["index-name"])" />
<set-variable name="routesCacheKey" value="@((string)context.Variables["deployment-id"] + "Routes" + context.Deployment.Region + context.Api.Revision)" />
<set-variable name="oaClustersCacheKey" value="@("aiSearchInstance" + context.Deployment.Region + context.Api.Revision)" />
<cache-lookup-value key="@((string)context.Variables.GetValueOrDefault<string>("oaClustersCacheKey", "ALL-SEARCH"))" variable-name="oaClusters" />
<!-- If we can't find the configuration cached, it will be loaded -->
<choose>
<when condition="@(context.Variables.ContainsKey("oaClusters") == false)">
<set-variable name="oaClusters" value="@{
// route is an Azure AI Search endpoint
JArray routes = new JArray();
// cluster is a group of routes that are capable of serving a specific index name
JArray clusters = new JArray();
// Update the below if condition when using multiple APIM gateway regions/SHGW to get different configurations for each region
if(context.Deployment.Region == "West Europe" || true)
{
// Adding all Azure AI Search endpoints routes (which are set as APIM Backend)
routes.Add(new JObject()
{
{ "name", "Contoso Insurance KB" },
{ "location", "Switzerland North" },
{ "backend-id", "ai-search-swn" },
{ "priority", 1},
{ "isThrottling", false },
{ "retryAfter", DateTime.MinValue }
});
routes.Add(new JObject()
{
{ "name", "Northwind Outdoor KB" },
{ "location", "Sweden Central" },
{ "backend-id", "ai-search-sec" },
{ "priority", 1},
{ "isThrottling", false },
{ "retryAfter", DateTime.MinValue }
});
// For each index, create a cluster with the routes that can serve it
clusters.Add(new JObject()
{
{ "deploymentName", "gptkbindex" },
{ "routes", new JArray(routes[0]) }
});
clusters.Add(new JObject()
{
{ "deploymentName", "product-info" },
{ "routes", new JArray(routes[1]) }
});
}
else
{
//No clusters found for selected region, either return error (default behavior) or set default cluster in the else section
}
return clusters;
}" />
<!-- Add cluster configurations to cache -->
<cache-store-value key="@((string)context.Variables.GetValueOrDefault<string>("oaClustersCacheKey", "ALL-SEARCH"))" value="@((JArray)context.Variables["oaClusters"])" duration="86400" />
</when>
</choose>
<include-fragment fragment-id="validate-routes" />
<authentication-managed-identity resource="https://search.azure.com" output-token-variable-name="msi-access-token" client-id="{{uami-client-id}}" ignore-error="false" />
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (string)context.Variables["msi-access-token"])</value>
</set-header>
</inbound>
<backend>
<include-fragment fragment-id="backend-routing" />
</backend>
<outbound>
<base />
<set-variable name="idPrefix" value="search" />
<set-variable name="targetService" value="AI-Search" />
<set-variable name="model" value="@((string)context.Variables.GetValueOrDefault<string>("deployment-id", "AI-SEARCH-INDEX"))" />
<set-variable name="deploymentName" value="@((string)context.Variables.GetValueOrDefault<string>("deployment-id", "AI-SEARCH-SERVICE"))" />
<include-fragment fragment-id="ai-usage" />
</outbound>
<on-error>
<base />
<set-variable name="service-name" value="Azure AI Search" />
<set-variable name="target-deployment" value="@((string)context.Request.MatchedParameters["index-name"])" />
<include-fragment fragment-id="throttling-events" />
</on-error>
</policies>