Skip to content

Commit c5a06e9

Browse files
committed
More comments, explanations and updates to RAG tutorial
1 parent cdef476 commit c5a06e9

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Tutorial-RAG/Tutorial-rag.ipynb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"\n",
188188
"Provide the endpoints you collected in a previous step. You can leave the API keys empty if you enabled role-based authentication. Otherwise, if you can't use roles, provide API keys for each resource.\n",
189189
"\n",
190-
"The Azure AI multiservce key must be provided even if you're using roles. The key isn't used on the connection, but it's currently used for billing purposes."
190+
"The Azure AI multiservice account is used for skills processing. The multiservice account key must be provided, even if you're using role-based access control. The key isn't used on the connection, but it's currently used for billing purposes."
191191
]
192192
},
193193
{
@@ -314,7 +314,7 @@
314314
"\n",
315315
"# Create a data source \n",
316316
"indexer_client = SearchIndexerClient(endpoint=AZURE_SEARCH_SERVICE, credential=credential)\n",
317-
"container = SearchIndexerDataContainer(name=\"nasatext\")\n",
317+
"container = SearchIndexerDataContainer(name=\"nasa-ebooks-pdfs-all\")\n",
318318
"data_source_connection = SearchIndexerDataSourceConnection(\n",
319319
" name=\"py-rag-tutorial-ds\",\n",
320320
" type=\"azureblob\",\n",
@@ -557,7 +557,7 @@
557557
"\n",
558558
"This script sends a query, the query response, and a prompt to an LLM for chat completion. This time, the response is created using generative AI.\n",
559559
"\n",
560-
"For more information about this step, its behaviors, and changing the settings, revisit [Search and generate answers](https://learn.microsoft.com/azure/search/tutorial-rag-build-solution-query) in the tutorial."
560+
"We broke this task out into three separate tasks: set up the clients, set up the search query, call the LLM and get the response. For more information about this step, its behaviors, and changing the settings, revisit [Search and generate answers](https://learn.microsoft.com/azure/search/tutorial-rag-build-solution-query) in the tutorial."
561561
]
562562
},
563563
{
@@ -570,6 +570,7 @@
570570
"from azure.search.documents import SearchClient\n",
571571
"from openai import AzureOpenAI\n",
572572
"\n",
573+
"# Set up the Azure OpenAI client\n",
573574
"token_provider = get_bearer_token_provider(credential, \"https://cognitiveservices.azure.com/.default\")\n",
574575
"openai_client = AzureOpenAI(\n",
575576
" api_version=\"2024-06-01\",\n",
@@ -579,6 +580,7 @@
579580
"\n",
580581
"deployment_name = \"gpt-4o\"\n",
581582
"\n",
583+
"# Set up the Azure Azure AI Search client\n",
582584
"search_client = SearchClient(\n",
583585
" endpoint=AZURE_SEARCH_SERVICE,\n",
584586
" index_name=index_name,\n",
@@ -605,21 +607,25 @@
605607
"metadata": {},
606608
"outputs": [],
607609
"source": [
608-
"# Provide the query. Notice it's sent to both the search engine and the LLM.\n",
609-
"# The query sent to the search engine is hybrid. Keyword search on \"query\". Text-to-vector conversion for vector search.\n",
610+
"# Provide the search query. \n",
611+
"# It's hybrid: a keyword search on \"query\", with text-to-vector conversion for \"vector_query\".\n",
612+
"# The vector query finds 50 nearest neighbor matches in the search index\n",
610613
"query=\"What's the NASA earth book about?\"\n",
611614
"vector_query = VectorizableTextQuery(text=query, k_nearest_neighbors=50, fields=\"text_vector\")\n",
612615
"\n",
613616
"# Set up the search results and the chat thread.\n",
614617
"# Retrieve the selected fields from the search index related to the question.\n",
618+
"# Search results are limited to the top 5 matches. Limiting top can help you stay under LLM quotas.\n",
615619
"search_results = search_client.search(\n",
616620
" search_text=query,\n",
617621
" vector_queries= [vector_query],\n",
618622
" select=[\"title\", \"chunk\", \"locations\"],\n",
619623
" top=5,\n",
620624
")\n",
621625
"\n",
622-
"# Newlines could be in the OCR'd content. Use a unique separator to make the sources distinct\n",
626+
"# Newlines could be in the OCR'd content or in PDFs, as is the case for the sample PDFs used for this tutorial.\n",
627+
"# Use a unique separator to make the sources distinct. \n",
628+
"# We chose repeated equal signs (=) followed by a newline because it's unlikely the source documents contain this sequence.\n",
623629
"sources_formatted = \"=================\\n\".join([f'TITLE: {document[\"title\"]}, CONTENT: {document[\"chunk\"]}, LOCATIONS: {document[\"locations\"]}' for document in search_results])\n"
624630
]
625631
},
@@ -709,7 +715,7 @@
709715
" SearchField(name=\"locations\", type=SearchFieldDataType.Collection(SearchFieldDataType.String), filterable=True),\n",
710716
" SearchField(name=\"chunk_id\", type=SearchFieldDataType.String, key=True, sortable=True, filterable=True, facetable=True, analyzer_name=\"keyword\"), \n",
711717
" SearchField(name=\"chunk\", type=SearchFieldDataType.String, sortable=False, filterable=False, facetable=False), \n",
712-
" SearchField(name=\"text_vector\", type=SearchFieldDataType.Collection(SearchFieldDataType.Single), vector_search_dimensions=1536, vector_search_profile_name=\"myHnswProfile\")\n",
718+
" SearchField(name=\"text_vector\", type=SearchFieldDataType.Collection(SearchFieldDataType.Single), vector_search_dimensions=1024, vector_search_profile_name=\"myHnswProfile\")\n",
713719
" ] \n",
714720
" \n",
715721
"# Existing vector search configuration \n",
@@ -730,8 +736,8 @@
730736
" kind=\"azureOpenAI\", \n",
731737
" parameters=AzureOpenAIVectorizerParameters( \n",
732738
" resource_url=AZURE_OPENAI_ACCOUNT, \n",
733-
" deployment_name=\"text-embedding-ada-002\",\n",
734-
" model_name=\"text-embedding-ada-002\"\n",
739+
" deployment_name=\"text-embedding-3-large\",\n",
740+
" model_name=\"text-embedding-3-large\"\n",
735741
" ),\n",
736742
" ), \n",
737743
" ], \n",
@@ -799,7 +805,7 @@
799805
" azure_ad_token_provider=token_provider\n",
800806
" )\n",
801807
"\n",
802-
"deployment_name = \"gpt-35-turbo\"\n",
808+
"deployment_name = \"gpt-4o\"\n",
803809
"\n",
804810
"search_client = SearchClient(\n",
805811
" endpoint=AZURE_SEARCH_SERVICE,\n",
@@ -821,8 +827,8 @@
821827
"\"\"\"\n",
822828
"\n",
823829
"# Queries are unchanged in this update\n",
824-
"query=\"how much of earth is covered by water\"\n",
825-
"vector_query = VectorizableTextQuery(text=query, k_nearest_neighbors=1, fields=\"text_vector\", exhaustive=True)\n",
830+
"query=\"What's the NASA earth book about?\"\n",
831+
"vector_query = VectorizableTextQuery(text=query, k_nearest_neighbors=1, fields=\"text_vector\")\n",
826832
"\n",
827833
"# Add query_type semantic and semantic_configuration_name\n",
828834
"# Add scoring_profile and scoring_parameters\n",

0 commit comments

Comments
 (0)