|
31 | 31 | " - Deploy a chat model (GPT-3.5-Turbo, GPT-4, or equivalent LLM).\n", |
32 | 32 | " - Deploy an embedding model (text-embedding-ada-002, text-embedding-3-large, text-embedding-3-small)\n", |
33 | 33 | "\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", |
34 | 36 | "- [Azure AI Search](https://learn.microsoft.com/azure/search/search-create-service-portal)\n", |
35 | 37 | "\n", |
36 | 38 | " - Basic tier or higher is recommended.\n", |
|
83 | 85 | "metadata": {}, |
84 | 86 | "outputs": [], |
85 | 87 | "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", |
89 | 88 | "from azure.core.credentials import AzureKeyCredential\n", |
| 89 | + "from azure.search.documents.indexes import SearchIndexClient\n", |
90 | 90 | "from azure.search.documents.indexes.models import (\n", |
91 | 91 | " SearchField,\n", |
92 | 92 | " SearchFieldDataType,\n", |
93 | 93 | " VectorSearch,\n", |
94 | 94 | " HnswAlgorithmConfiguration,\n", |
95 | 95 | " VectorSearchProfile,\n", |
96 | 96 | " AzureOpenAIVectorizer,\n", |
97 | | - " AzureOpenAIParameters,\n", |
| 97 | + " AzureOpenAIVectorizerParameters,\n", |
98 | 98 | " SearchIndex\n", |
99 | 99 | ")\n", |
100 | 100 | "\n", |
|
121 | 121 | " VectorSearchProfile( \n", |
122 | 122 | " name=\"myHnswProfile\", \n", |
123 | 123 | " algorithm_configuration_name=\"myHnsw\", \n", |
124 | | - " vectorizer=\"myOpenAI\", \n", |
| 124 | + " vectorizer_name=\"myOpenAI\", \n", |
125 | 125 | " )\n", |
126 | 126 | " ], \n", |
127 | 127 | " vectorizers=[ \n", |
128 | 128 | " AzureOpenAIVectorizer( \n", |
129 | | - " name=\"myOpenAI\", \n", |
| 129 | + " vectorizer_name=\"myOpenAI\", \n", |
130 | 130 | " 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", |
135 | 136 | " ),\n", |
136 | 137 | " ), \n", |
137 | | - " ], \n", |
| 138 | + " ], \n", |
138 | 139 | ") \n", |
139 | 140 | " \n", |
140 | 141 | "# Create the search index\n", |
|
258 | 259 | " source_context=\"/document/pages/*\", \n", |
259 | 260 | " mappings=[ \n", |
260 | 261 | " 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", |
262 | 264 | " InputFieldMappingEntry(name=\"title\", source=\"/document/metadata_storage_name\"), \n", |
263 | 265 | " ], \n", |
264 | 266 | " ), \n", |
|
319 | 321 | " parameters=indexer_parameters\n", |
320 | 322 | ") \n", |
321 | 323 | "\n", |
| 324 | + "# Create and run the indexer \n", |
322 | 325 | "indexer_client = SearchIndexerClient(endpoint=AZURE_SEARCH_SERVICE, credential=AZURE_SEARCH_CREDENTIAL) \n", |
323 | 326 | "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", |
327 | 328 | "print(f' {indexer_name} is created and running. Give the indexer a few minutes before running a query.') " |
328 | 329 | ] |
329 | 330 | }, |
|
343 | 344 | "from azure.search.documents import SearchClient\n", |
344 | 345 | "from azure.search.documents.models import VectorizableTextQuery\n", |
345 | 346 | "\n", |
346 | | - "# Hybrid Search\n", |
| 347 | + "# Vector Search using text-to-vector conversion of the querystring\n", |
347 | 348 | "query = \"how much of earth is covered by water\" \n", |
348 | 349 | "\n", |
349 | 350 | "search_client = SearchClient(endpoint=AZURE_SEARCH_SERVICE, credential=AZURE_SEARCH_CREDENTIAL, index_name=index_name)\n", |
|
358 | 359 | " \n", |
359 | 360 | "for result in results: \n", |
360 | 361 | " 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']}\")" |
363 | 365 | ] |
364 | 366 | }, |
365 | 367 | { |
|
397 | 399 | "\n", |
398 | 400 | "# Provide instructions to the model\n", |
399 | 401 | "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", |
401 | 403 | "Answer the query using only the sources provided below.\n", |
402 | 404 | "Use bullets if the answer has multiple points.\n", |
403 | 405 | "If the answer is longer than 3 sentences, provide a summary.\n", |
|
0 commit comments