|
187 | 187 | "\n", |
188 | 188 | "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", |
189 | 189 | "\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." |
191 | 191 | ] |
192 | 192 | }, |
193 | 193 | { |
|
314 | 314 | "\n", |
315 | 315 | "# Create a data source \n", |
316 | 316 | "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", |
318 | 318 | "data_source_connection = SearchIndexerDataSourceConnection(\n", |
319 | 319 | " name=\"py-rag-tutorial-ds\",\n", |
320 | 320 | " type=\"azureblob\",\n", |
|
557 | 557 | "\n", |
558 | 558 | "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", |
559 | 559 | "\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." |
561 | 561 | ] |
562 | 562 | }, |
563 | 563 | { |
|
570 | 570 | "from azure.search.documents import SearchClient\n", |
571 | 571 | "from openai import AzureOpenAI\n", |
572 | 572 | "\n", |
| 573 | + "# Set up the Azure OpenAI client\n", |
573 | 574 | "token_provider = get_bearer_token_provider(credential, \"https://cognitiveservices.azure.com/.default\")\n", |
574 | 575 | "openai_client = AzureOpenAI(\n", |
575 | 576 | " api_version=\"2024-06-01\",\n", |
|
579 | 580 | "\n", |
580 | 581 | "deployment_name = \"gpt-4o\"\n", |
581 | 582 | "\n", |
| 583 | + "# Set up the Azure Azure AI Search client\n", |
582 | 584 | "search_client = SearchClient(\n", |
583 | 585 | " endpoint=AZURE_SEARCH_SERVICE,\n", |
584 | 586 | " index_name=index_name,\n", |
|
605 | 607 | "metadata": {}, |
606 | 608 | "outputs": [], |
607 | 609 | "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", |
610 | 613 | "query=\"What's the NASA earth book about?\"\n", |
611 | 614 | "vector_query = VectorizableTextQuery(text=query, k_nearest_neighbors=50, fields=\"text_vector\")\n", |
612 | 615 | "\n", |
613 | 616 | "# Set up the search results and the chat thread.\n", |
614 | 617 | "# 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", |
615 | 619 | "search_results = search_client.search(\n", |
616 | 620 | " search_text=query,\n", |
617 | 621 | " vector_queries= [vector_query],\n", |
618 | 622 | " select=[\"title\", \"chunk\", \"locations\"],\n", |
619 | 623 | " top=5,\n", |
620 | 624 | ")\n", |
621 | 625 | "\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", |
623 | 629 | "sources_formatted = \"=================\\n\".join([f'TITLE: {document[\"title\"]}, CONTENT: {document[\"chunk\"]}, LOCATIONS: {document[\"locations\"]}' for document in search_results])\n" |
624 | 630 | ] |
625 | 631 | }, |
|
709 | 715 | " SearchField(name=\"locations\", type=SearchFieldDataType.Collection(SearchFieldDataType.String), filterable=True),\n", |
710 | 716 | " SearchField(name=\"chunk_id\", type=SearchFieldDataType.String, key=True, sortable=True, filterable=True, facetable=True, analyzer_name=\"keyword\"), \n", |
711 | 717 | " 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", |
713 | 719 | " ] \n", |
714 | 720 | " \n", |
715 | 721 | "# Existing vector search configuration \n", |
|
730 | 736 | " kind=\"azureOpenAI\", \n", |
731 | 737 | " parameters=AzureOpenAIVectorizerParameters( \n", |
732 | 738 | " 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", |
735 | 741 | " ),\n", |
736 | 742 | " ), \n", |
737 | 743 | " ], \n", |
|
799 | 805 | " azure_ad_token_provider=token_provider\n", |
800 | 806 | " )\n", |
801 | 807 | "\n", |
802 | | - "deployment_name = \"gpt-35-turbo\"\n", |
| 808 | + "deployment_name = \"gpt-4o\"\n", |
803 | 809 | "\n", |
804 | 810 | "search_client = SearchClient(\n", |
805 | 811 | " endpoint=AZURE_SEARCH_SERVICE,\n", |
|
821 | 827 | "\"\"\"\n", |
822 | 828 | "\n", |
823 | 829 | "# 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", |
826 | 832 | "\n", |
827 | 833 | "# Add query_type semantic and semantic_configuration_name\n", |
828 | 834 | "# Add scoring_profile and scoring_parameters\n", |
|
0 commit comments