Skip to content

Commit a74df4e

Browse files
authored
Removing unneeded key for free search service (#1620)
* Removing unneeded key for free search service * fix tests
1 parent 3822c52 commit a74df4e

File tree

15 files changed

+24
-300
lines changed

15 files changed

+24
-300
lines changed

app/backend/app.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
from pathlib import Path
88
from typing import Any, AsyncGenerator, Dict, Union, cast
99

10-
from azure.core.credentials import AzureKeyCredential
11-
from azure.core.credentials_async import AsyncTokenCredential
1210
from azure.core.exceptions import ResourceNotFoundError
1311
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
14-
from azure.keyvault.secrets.aio import SecretClient
1512
from azure.monitor.opentelemetry import configure_azure_monitor
1613
from azure.search.documents.aio import SearchClient
1714
from azure.search.documents.indexes.aio import SearchIndexClient
@@ -305,8 +302,6 @@ async def setup_clients():
305302
AZURE_USERSTORAGE_CONTAINER = os.environ.get("AZURE_USERSTORAGE_CONTAINER")
306303
AZURE_SEARCH_SERVICE = os.environ["AZURE_SEARCH_SERVICE"]
307304
AZURE_SEARCH_INDEX = os.environ["AZURE_SEARCH_INDEX"]
308-
AZURE_SEARCH_SECRET_NAME = os.getenv("AZURE_SEARCH_SECRET_NAME")
309-
AZURE_KEY_VAULT_NAME = os.getenv("AZURE_KEY_VAULT_NAME")
310305
# Shared by all OpenAI deployments
311306
OPENAI_HOST = os.getenv("OPENAI_HOST", "azure")
312307
OPENAI_CHATGPT_MODEL = os.environ["AZURE_OPENAI_CHATGPT_MODEL"]
@@ -351,24 +346,11 @@ async def setup_clients():
351346
# If you encounter a blocking error during a DefaultAzureCredential resolution, you can exclude the problematic credential by using a parameter (ex. exclude_shared_token_cache_credential=True)
352347
azure_credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True)
353348

354-
# Fetch any necessary secrets from Key Vault
355-
search_key = None
356-
if AZURE_KEY_VAULT_NAME:
357-
async with SecretClient(
358-
vault_url=f"https://{AZURE_KEY_VAULT_NAME}.vault.azure.net", credential=azure_credential
359-
) as key_vault_client:
360-
search_key = (
361-
AZURE_SEARCH_SECRET_NAME and (await key_vault_client.get_secret(AZURE_SEARCH_SECRET_NAME)).value # type: ignore[attr-defined]
362-
)
363-
364349
# Set up clients for AI Search and Storage
365-
search_credential: Union[AsyncTokenCredential, AzureKeyCredential] = (
366-
AzureKeyCredential(search_key) if search_key else azure_credential
367-
)
368350
search_client = SearchClient(
369351
endpoint=f"https://{AZURE_SEARCH_SERVICE}.search.windows.net",
370352
index_name=AZURE_SEARCH_INDEX,
371-
credential=search_credential,
353+
credential=azure_credential,
372354
)
373355

374356
blob_container_client = ContainerClient(
@@ -380,7 +362,7 @@ async def setup_clients():
380362
if AZURE_USE_AUTHENTICATION:
381363
search_index_client = SearchIndexClient(
382364
endpoint=f"https://{AZURE_SEARCH_SERVICE}.search.windows.net",
383-
credential=search_credential,
365+
credential=azure_credential,
384366
)
385367
search_index = await search_index_client.get_index(AZURE_SEARCH_INDEX)
386368
await search_index_client.close()
@@ -418,10 +400,7 @@ async def setup_clients():
418400
search_images=USE_GPT4V,
419401
)
420402
search_info = await setup_search_info(
421-
search_service=AZURE_SEARCH_SERVICE,
422-
index_name=AZURE_SEARCH_INDEX,
423-
azure_credential=azure_credential,
424-
search_key=clean_key_if_exists(search_key),
403+
search_service=AZURE_SEARCH_SERVICE, index_name=AZURE_SEARCH_INDEX, azure_credential=azure_credential
425404
)
426405
text_embeddings_service = setup_embeddings_service(
427406
azure_credential=azure_credential,

app/backend/prepdocs.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from azure.core.credentials import AzureKeyCredential
77
from azure.core.credentials_async import AsyncTokenCredential
88
from azure.identity.aio import AzureDeveloperCliCredential, get_bearer_token_provider
9-
from azure.keyvault.secrets.aio import SecretClient
109

1110
from prepdocslib.blobmanager import BlobManager
1211
from prepdocslib.embeddings import (
@@ -43,19 +42,8 @@ def clean_key_if_exists(key: Union[str, None]) -> Union[str, None]:
4342

4443

4544
async def setup_search_info(
46-
search_service: str,
47-
index_name: str,
48-
azure_credential: AsyncTokenCredential,
49-
search_key: Union[str, None] = None,
50-
key_vault_name: Union[str, None] = None,
51-
search_secret_name: Union[str, None] = None,
45+
search_service: str, index_name: str, azure_credential: AsyncTokenCredential, search_key: Union[str, None] = None
5246
) -> SearchInfo:
53-
if key_vault_name and search_secret_name:
54-
async with SecretClient(
55-
vault_url=f"https://{key_vault_name}.vault.azure.net", credential=azure_credential
56-
) as key_vault_client:
57-
search_key = (await key_vault_client.get_secret(search_secret_name)).value # type: ignore[attr-defined]
58-
5947
search_creds: Union[AsyncTokenCredential, AzureKeyCredential] = (
6048
azure_credential if search_key is None else AzureKeyCredential(search_key)
6149
)
@@ -291,11 +279,6 @@ async def main(strategy: Strategy, setup_index: bool = True):
291279
required=False,
292280
help="Optional. Use this Azure AI Search account key instead of the current user identity to login (use az login to set current user for Azure)",
293281
)
294-
parser.add_argument(
295-
"--searchsecretname",
296-
required=False,
297-
help="Required if searchkey is not provided and search service is free sku. Fetch the Azure AI Vision key from this keyvault instead of the instead of the current user identity to login (use az login to set current user for Azure)",
298-
)
299282
parser.add_argument(
300283
"--searchanalyzername",
301284
required=False,
@@ -373,11 +356,6 @@ async def main(strategy: Strategy, setup_index: bool = True):
373356
required=False,
374357
help="Optional, required if --searchimages is specified. Endpoint of Azure AI Vision service to use when embedding images.",
375358
)
376-
parser.add_argument(
377-
"--keyvaultname",
378-
required=False,
379-
help="Required only if any keys must be fetched from the key vault.",
380-
)
381359
parser.add_argument(
382360
"--useintvectorization",
383361
required=False,
@@ -417,8 +395,6 @@ async def main(strategy: Strategy, setup_index: bool = True):
417395
index_name=args.index,
418396
azure_credential=azd_credential,
419397
search_key=clean_key_if_exists(args.searchkey),
420-
key_vault_name=args.keyvaultname,
421-
search_secret_name=args.searchsecretname,
422398
)
423399
)
424400
blob_manager = setup_blob_manager(

app/backend/requirements.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ opentelemetry-instrumentation-requests
1717
opentelemetry-instrumentation-aiohttp-client
1818
opentelemetry-instrumentation-openai
1919
msal
20-
azure-keyvault-secrets
2120
cryptography
2221
python-jose[cryptography]
2322
types-python-jose

app/backend/requirements.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ azure-core==1.30.1
3131
# azure-ai-documentintelligence
3232
# azure-core-tracing-opentelemetry
3333
# azure-identity
34-
# azure-keyvault-secrets
3534
# azure-monitor-opentelemetry
3635
# azure-monitor-opentelemetry-exporter
3736
# azure-search-documents
@@ -45,8 +44,6 @@ azure-identity==1.15.0
4544
# via
4645
# -r requirements.in
4746
# msgraph-sdk
48-
azure-keyvault-secrets==4.8.0
49-
# via -r requirements.in
5047
azure-monitor-opentelemetry==1.3.0
5148
# via -r requirements.in
5249
azure-monitor-opentelemetry-exporter==1.0.0b23
@@ -136,7 +133,6 @@ importlib-metadata==6.11.0
136133
isodate==0.6.1
137134
# via
138135
# azure-ai-documentintelligence
139-
# azure-keyvault-secrets
140136
# azure-search-documents
141137
# azure-storage-blob
142138
# azure-storage-file-datalake
@@ -410,7 +406,6 @@ typing-extensions==4.10.0
410406
# via
411407
# azure-ai-documentintelligence
412408
# azure-core
413-
# azure-keyvault-secrets
414409
# azure-storage-blob
415410
# azure-storage-file-datalake
416411
# openai

docs/deploy_lowcost.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This AI RAG chat application is designed to be easily deployed using the Azure Developer CLI, which provisions the infrastructure according to the Bicep files in the `infra` folder. Those files describe each of the Azure resources needed, and configures their SKU (pricing tier) and other parameters. Many Azure services offer a free tier, but the infrastructure files in this project do *not* default to the free tier as there are often limitations in that tier.
44

5-
However, if your goal is to minimize costs while prototyping your application, follow the steps below _before_ running `azd up`. Once you've gone through these steps, return to the [deployment steps](../README.md#deploying).
5+
However, if your goal is to minimize costs while prototyping your application, follow the steps below *before* running `azd up`. Once you've gone through these steps, return to the [deployment steps](../README.md#deploying).
66

77
[📺 Live stream: Deploying from a free account](https://www.youtube.com/watch?v=nlIyos0RXHw)
88

@@ -21,15 +21,15 @@ However, if your goal is to minimize costs while prototyping your application, f
2121
Enter a name that will be used for the resource group.
2222
This will create a new folder in the `.azure` folder, and set it as the active environment for any calls to `azd` going forward.
2323

24-
2. Use the free tier of App Service:
24+
1. Use the free tier of App Service:
2525

2626
```shell
2727
azd env set AZURE_APP_SERVICE_SKU F1
2828
```
2929

3030
Limitation: You are only allowed a certain number of free App Service instances per region. If you have exceeded your limit in a region, you will get an error during the provisioning stage. If that happens, you can run `azd down`, then `azd env new` to create a new environment with a new region.
3131

32-
3. Use the free tier of Azure AI Search:
32+
1. Use the free tier of Azure AI Search:
3333

3434
```shell
3535
azd env set AZURE_SEARCH_SERVICE_SKU free
@@ -41,11 +41,8 @@ However, if your goal is to minimize costs while prototyping your application, f
4141
reuse your [existing search service](../README.md#existing-azure-ai-search-resource).
4242
2. The free tier does not support semantic ranker, so the app UI will no longer display
4343
the option to use the semantic ranker. Note that will generally result in [decreased search relevance](https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/azure-ai-search-outperforming-vector-search-with-hybrid/ba-p/3929167).
44-
3. The free tier does not support Managed Identity (keyless API access),
45-
so the Bicep will use Azure Key Vault to securely store the key instead.
46-
47-
4. Use the free tier of Azure Document Intelligence (used in analyzing files):
4844

45+
1. Use the free tier of Azure Document Intelligence (used in analyzing files):
4946

5047
```shell
5148
azd env set AZURE_DOCUMENTINTELLIGENCE_SKU F0
@@ -74,7 +71,7 @@ However, if your goal is to minimize costs while prototyping your application, f
7471
azd env set USE_LOCAL_HTML_PARSER true
7572
```
7673
77-
5. Turn off Azure Monitor (Application Insights):
74+
1. Turn off Azure Monitor (Application Insights):
7875
7976
```shell
8077
azd env set AZURE_USE_APPLICATION_INSIGHTS false
@@ -83,7 +80,7 @@ However, if your goal is to minimize costs while prototyping your application, f
8380
Application Insights is quite inexpensive already, so turning this off may not be worth the costs saved,
8481
but it is an option for those who want to minimize costs.
8582
86-
6. Use OpenAI.com instead of Azure OpenAI: This is only a necessary step for Azure free/student accounts, as they do not currently have access to Azure OpenAI.
83+
1. Use OpenAI.com instead of Azure OpenAI: This is only a necessary step for Azure free/student accounts, as they do not currently have access to Azure OpenAI.
8784
8885
```shell
8986
azd env set OPENAI_HOST openai
@@ -94,7 +91,7 @@ However, if your goal is to minimize costs while prototyping your application, f
9491
Both Azure OpenAI and openai.com OpenAI accounts will incur costs, based on tokens used,
9592
but the costs are fairly low for the amount of sample data (less than $10).
9693
97-
6. Disable vector search:
94+
1. Disable vector search:
9895
9996
```shell
10097
azd env set USE_VECTORS false
@@ -106,7 +103,7 @@ However, if your goal is to minimize costs while prototyping your application, f
106103
so the benefits of vector search would typically outweigh the costs, but it is possible to disable vector support.
107104
If you do so, the application will fall back to a keyword search, which is less accurate.
108105
109-
7. Once you've made the desired customizations, follow the steps in the README [to run `azd up`](../README.md#deploying-from-scratch). We recommend using "eastus" as the region, for availability reasons.
106+
1. Once you've made the desired customizations, follow the steps in the README [to run `azd up`](../README.md#deploying-from-scratch). We recommend using "eastus" as the region, for availability reasons.
110107

111108
## Reducing costs locally
112109

infra/core/security/keyvault-access.bicep

Lines changed: 0 additions & 22 deletions
This file was deleted.

infra/core/security/keyvault-secret.bicep

Lines changed: 0 additions & 31 deletions
This file was deleted.

infra/core/security/keyvault.bicep

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)