Skip to content

Commit 19460a4

Browse files
authored
Merge pull request #120 from HeidiSteen/main
Update RAG tutorial to use latest stable Python package
2 parents cd276a4 + 7f632ff commit 19460a4

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

Tutorial-RAG/Tutorial-rag-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
python-dotenv
2+
azure-core
23
azure-search-documents==11.5.1
34
azure-storage-blob
45
azure-identity

Tutorial-RAG/Tutorial-rag.ipynb

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
" - Deploy a chat model (GPT-3.5-Turbo, GPT-4, or equivalent LLM).\n",
3232
" - Deploy an embedding model (text-embedding-ada-002, text-embedding-3-large, text-embedding-3-small)\n",
3333
"\n",
34+
"- [Azure AI Services multiservice account](https://learn.microsoft.com/azure/ai-services/multi-service-resource), in the same region as Azure AI Search. This resource is used for the Entity Recognition skill that detects locations in your content.\n",
35+
"\n",
3436
"- [Azure AI Search](https://learn.microsoft.com/azure/search/search-create-service-portal)\n",
3537
"\n",
3638
" - Basic tier or higher is recommended.\n",
@@ -83,18 +85,16 @@
8385
"metadata": {},
8486
"outputs": [],
8587
"source": [
86-
"from azure.identity import DefaultAzureCredential\n",
87-
"from azure.identity import get_bearer_token_provider\n",
88-
"from azure.search.documents.indexes import SearchIndexClient\n",
8988
"from azure.core.credentials import AzureKeyCredential\n",
89+
"from azure.search.documents.indexes import SearchIndexClient\n",
9090
"from azure.search.documents.indexes.models import (\n",
9191
" SearchField,\n",
9292
" SearchFieldDataType,\n",
9393
" VectorSearch,\n",
9494
" HnswAlgorithmConfiguration,\n",
9595
" VectorSearchProfile,\n",
9696
" AzureOpenAIVectorizer,\n",
97-
" AzureOpenAIParameters,\n",
97+
" AzureOpenAIVectorizerParameters,\n",
9898
" SearchIndex\n",
9999
")\n",
100100
"\n",
@@ -121,20 +121,21 @@
121121
" VectorSearchProfile( \n",
122122
" name=\"myHnswProfile\", \n",
123123
" algorithm_configuration_name=\"myHnsw\", \n",
124-
" vectorizer=\"myOpenAI\", \n",
124+
" vectorizer_name=\"myOpenAI\", \n",
125125
" )\n",
126126
" ], \n",
127127
" vectorizers=[ \n",
128128
" AzureOpenAIVectorizer( \n",
129-
" name=\"myOpenAI\", \n",
129+
" vectorizer_name=\"myOpenAI\", \n",
130130
" kind=\"azureOpenAI\", \n",
131-
" azure_open_ai_parameters=AzureOpenAIParameters( \n",
132-
" resource_uri=AZURE_OPENAI_ACCOUNT, \n",
133-
" deployment_id=\"text-embedding-ada-002\",\n",
134-
" model_name=\"text-embedding-ada-002\"\n",
131+
" parameters=AzureOpenAIVectorizerParameters( \n",
132+
" resource_url=AZURE_OPENAI_ACCOUNT, \n",
133+
" deployment_name=\"text-embedding-ada-002\",\n",
134+
" model_name=\"text-embedding-ada-002\",\n",
135+
" api_key=AZURE_OPENAI_KEY\n",
135136
" ),\n",
136137
" ), \n",
137-
" ], \n",
138+
" ], \n",
138139
") \n",
139140
" \n",
140141
"# Create the search index\n",
@@ -258,7 +259,8 @@
258259
" source_context=\"/document/pages/*\", \n",
259260
" mappings=[ \n",
260261
" InputFieldMappingEntry(name=\"chunk\", source=\"/document/pages/*\"), \n",
261-
" InputFieldMappingEntry(name=\"text_vector\", source=\"/document/pages/*/text_vector\"), \n",
262+
" InputFieldMappingEntry(name=\"text_vector\", source=\"/document/pages/*/text_vector\"),\n",
263+
" InputFieldMappingEntry(name=\"locations\", source=\"/document/pages/*/locations\"), \n",
262264
" InputFieldMappingEntry(name=\"title\", source=\"/document/metadata_storage_name\"), \n",
263265
" ], \n",
264266
" ), \n",
@@ -319,11 +321,10 @@
319321
" parameters=indexer_parameters\n",
320322
") \n",
321323
"\n",
324+
"# Create and run the indexer \n",
322325
"indexer_client = SearchIndexerClient(endpoint=AZURE_SEARCH_SERVICE, credential=AZURE_SEARCH_CREDENTIAL) \n",
323326
"indexer_result = indexer_client.create_or_update_indexer(indexer) \n",
324-
" \n",
325-
"# Run the indexer \n",
326-
"indexer_client.run_indexer(indexer_name) \n",
327+
"\n",
327328
"print(f' {indexer_name} is created and running. Give the indexer a few minutes before running a query.') "
328329
]
329330
},
@@ -343,7 +344,7 @@
343344
"from azure.search.documents import SearchClient\n",
344345
"from azure.search.documents.models import VectorizableTextQuery\n",
345346
"\n",
346-
"# Hybrid Search\n",
347+
"# Vector Search using text-to-vector conversion of the querystring\n",
347348
"query = \"how much of earth is covered by water\" \n",
348349
"\n",
349350
"search_client = SearchClient(endpoint=AZURE_SEARCH_SERVICE, credential=AZURE_SEARCH_CREDENTIAL, index_name=index_name)\n",
@@ -358,8 +359,9 @@
358359
" \n",
359360
"for result in results: \n",
360361
" print(f\"Score: {result['@search.score']}\")\n",
361-
" print(f\"Title: {result['title']}\") \n",
362-
" print(f\"Content: {result['chunk']}\") "
362+
" print(f\"Title: {result['title']}\")\n",
363+
" print(f\"Locations: {result['locations']}\")\n",
364+
" print(f\"Content: {result['chunk']}\")"
363365
]
364366
},
365367
{
@@ -397,7 +399,7 @@
397399
"\n",
398400
"# Provide instructions to the model\n",
399401
"GROUNDED_PROMPT=\"\"\"\n",
400-
"You are an AI assistant that helps users find the information their looking for.\n",
402+
"You are an AI assistant that helps users learn from the information found in the source material.\n",
401403
"Answer the query using only the sources provided below.\n",
402404
"Use bullets if the answer has multiple points.\n",
403405
"If the answer is longer than 3 sentences, provide a summary.\n",

0 commit comments

Comments
 (0)