From 53efac63eaa65d725c4b94d42ada06c098a579d9 Mon Sep 17 00:00:00 2001 From: kylebunting Date: Thu, 19 Sep 2024 15:29:09 -0600 Subject: [PATCH] Grammar and spelling fixes --- .../0302.md | 58 +++++++++---------- .../0303.md | 44 +++++++------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/docs/03_implement_vector_search_in_cosmos_db_nosql/0302.md b/docs/03_implement_vector_search_in_cosmos_db_nosql/0302.md index 227827e59..2bfbbd70a 100644 --- a/docs/03_implement_vector_search_in_cosmos_db_nosql/0302.md +++ b/docs/03_implement_vector_search_in_cosmos_db_nosql/0302.md @@ -9,13 +9,13 @@ parent: 'Exercise 03: Implement contextual grounding' ## Introduction -Vectors, also known as embeddings or vector embeddings, are mathematical representations of data in a high-dimensional space. In this space, each dimension corresponds to a feature of the data, and tens of thousands of dimensions might be used to represent sophisticated data. A vector's position in this space represents its characteristics. Words, phrases, or entire documents, and images, audio, and other types of data can all be vectorized. An embedding is a special format of data representation that can be easily utilized by machine learning models and algorithms. The embedding is an information dense representation of the semantic meaning of a piece of text. Each embedding is a vector of floating point numbers, such that the distance between two embeddings in the vector space is correlated with semantic similarity between two inputs in the original format. Azure OpenAI provides several models for creating vector embeddings, and for this exercise, you will use the `text-embedding-ada-002` model. +Vectors, also known as embeddings or vector embeddings, are mathematical representations of data in a high-dimensional space. Each dimension corresponds to a feature of the data in this space, and tens of thousands of dimensions might be used to represent sophisticated data. A vector's position in this space represents its characteristics. Words, phrases, or entire documents, as well as images, audio, and other types of data, can all be vectorized. An embedding is a data representation format that machine learning models and algorithms can efficiently utilize. The embedding is an information-dense representation of the semantic meaning of a piece of text. Each embedding is a vector of floating point numbers. Hence, the distance between two embeddings in the vector space correlates with the semantic similarity between two inputs in the original format. Azure OpenAI provides several models for creating vector embeddings, and for this exercise, you will use the `text-embedding-ada-002` model. -To store the generated embeddings, you will use a vector database. Vector databases are designed to store and manage vector embeddings. The vector database you will use is Azure Cosmos DB for NoSQL. It allows you to store vectors alongside traditional schema-free data within your documents, streamlining data management and significantly enhancing the efficiency of vector operations. Keeping all relevant data in a single logical unit simplifies your data architecture, making it easy to understand and manage. +You will use a vector database to store the generated embeddings. Vector databases are designed to store and manage vector embeddings. The vector database you will use is Azure Cosmos DB for NoSQL. It allows you to store vectors alongside traditional schema-free data within your documents, streamlining data management and significantly enhancing the efficiency of vector operations. Keeping all relevant data in a single logical unit simplifies your data architecture, making it easy to understand and manage. ## Description -In the prior task, you configured Azure Cosmos DB for NoSQL as an integrated vector database. In this task, you will use an Azure Function, Azure OpenAI, and the Azure Cosmos DB change feed to generate vector embeddings for property maintenance requests and save those into the `MaintenanceRequests` container in Cosmos DB. +You configured Azure Cosmos DB for NoSQL as an integrated vector database in the prior task. In this task, you will use an Azure Function, Azure OpenAI, and the Azure Cosmos DB change feed to generate vector embeddings for property maintenance requests and save those into the `MaintenanceRequests` container in Cosmos DB. You will conclude by uploading data supplied by the Contoso Suites staff into the `MaintenanceRequests` container you created in Cosmos DB and allowing the deployed function app to generate vectors for each record. The JSON data files provided by Contoso Suites contain maintenance requests for several hotels on their resorts. They offer an example of the types of data the company believes can benefit from the similarity search capabilities provided by Vector Search in Cosmos DB for NoSQL, so they would like you to incorporate this data into the proof of concept. @@ -23,13 +23,13 @@ The key tasks are as follows: 1. Review the Azure Function code in the `CosmosChangeFeedVectorization.cs` file in the `src\ContosoSuitesVectorizationFunction` folder. The function: 1. Is triggered whenever a document is inserted or updated in the `MaintenanceRequests` container using the Azure Cosmos DB change feed. - 2. Combines the content in the `hotel` and `details` fields of a maintenance request and vectorizes it using a `text-embedding-ada-002` model in Azure OpenAI. + 2. Combines the contents of a maintenance request's `hotel` and `details` fields and vectorizes the resulting text using a `text-embedding-ada-002` model in Azure OpenAI. 3. Writes generated vectors into the `request_embeddings` fields of the document and updates it in the `MaintenanceRequests` container. 4. Marks the document as "Vectorized." -2. Create a `local.settings.json` file in the `src\ContosoSuitesVectorizationFunction` folder and populate it with the settings needed by the function to run the function locally. Hint, the required values can be identified using the calls to `Environment.GetEnvironmentVariable` in the `CosmosChangeFeedVectorization.cs` file, as well as providing the Cosmos DB connection string required by the input and output bindings of the function. +2. Create a `local.settings.json` file in the `src\ContosoSuitesVectorizationFunction` folder and populate it with the settings the function needs to run the function locally. Hint: the required values can be identified using the calls to `Environment.GetEnvironmentVariable` in the `CosmosChangeFeedVectorization.cs` file, as well as providing the Cosmos DB connection string required by the input and output bindings of the function. 3. Test the function locally and evaluate the inputs and outputs of the function. - 1. Use breakpoints in the function's `Run` method to examine the input collection and processing that occurs as a new record is added. - 2. After starting a local debug session, insert the following document into the `MaintenanceRequests` container and observe the results of the function execution as your breakpoints are hit. + 1. Use breakpoints in the function's `Run` method to examine the input collection and processing as a new record is added. + 2. After starting a local debug session, insert the following document into the `MaintenanceRequests` container and observe the function execution results as your breakpoints are hit. ```json { @@ -42,9 +42,9 @@ The key tasks are as follows: } ``` - 3. Once the function execution completes, examine the document in Cosmos DB and inspect the vector embeddings inserted into `request_vector` field of the document. + 3. Once the function execution is complete, examine the document in Cosmos DB and inspect the vector embeddings inserted into the `request_vector` field of the document. 4. Use VS Code to deploy the function to the Azure Function App in your resource group and add the required app configuration settings. -5. Verify the deployed function is working correctly by inserting the following record into the `MaintenanceRequests` container in Cosmos DB. Use the Log Stream for the Function App to observe the output. +5. Verify that the deployed function is working correctly by inserting the following record into the `MaintenanceRequests` container in Cosmos DB. Then, use the Log Stream for the Function App to observe the output. ```json { @@ -58,7 +58,7 @@ The key tasks are as follows: ``` 6. Populate the `MaintenanceRequests` container with data from the `PropertyMaintenance.json` file in the [src\data folder](https://github.com/microsoft/TechExcel-Integrating-Azure-PaaS-and-AI-Services-for-AI-Design-Wins/tree/main/src/data) of the repository. -7. Observe the files being processed in the Log Stream and review documents in the Cosmos DB Data Explorer to confirm the function is correctly populating the `request_vector` field for newly added documents. +7. Observe the files being processed in the Log Stream and review documents in the Cosmos DB Data Explorer to confirm the function correctly populated the `request_vector` field for newly added documents. 8. Execute a query to find documents similar to "air conditioning malfunction" using the `VectorDistance()` function via Cosmos DB Data Explorer. You can find the vector embeddings for "air conditioning malfunction" in the `Query_Vector.txt` file in the [src\data folder](https://github.com/microsoft/TechExcel-Integrating-Azure-PaaS-and-AI-Services-for-AI-Design-Wins/tree/main/src/data). ## Success Criteria @@ -87,7 +87,7 @@ You may get the following error when trying to deploy the Azure Function: ![An error message that no project root could be found.](../../media/Solution/0302-azure-function-no-root.png) -If you get this error message, you will need to set the default Azure Functions project in the workspace folder. Close and re-open Visual Studio Code and you should see a warning message that you have multiple function projects in the same workspace folder. +If you get this error message, you must set the default Azure Functions project in the workspace folder. Close and re-open Visual Studio Code, and you should see a warning message that you have multiple function projects in the same workspace folder. ![A warning message that there exist multiple function projects in the same workspace folder.](../../media/Solution/0302-azure-function-set-default.png) @@ -95,11 +95,11 @@ After selecting the **Set Default** button, you will receive a prompt to choose ![Choose the VectorizationFunction folder as the default project subpath.](../../media/Solution/0302-azure-function-set-default-2.png) -You may then receive a warning message asking if you wish to initialize this function for optimal use with Visual Studio Code. Select **Yes** to do this. +You may receive a warning message asking if you wish to initialize this function for optimal use with Visual Studio Code. Select **Yes** to do this. ![Initialize the project for optimal use with Visual Studio Code.](../../media/Solution/0302-azure-function-initialize.png) -You will then receive a warning modal that this operation will overwrite your task.json. Select **Overwrite** to complete this task. +You will receive a warning modal that this operation will overwrite your task.json. Select **Overwrite** to complete this task. ![Overwrite the func: host start task in your tasks.json file.](../../media/Solution/0302-azure-function-overwrite.png) @@ -113,9 +113,9 @@ You will then receive a warning modal that this operation will overwrite your ta - The `DatabaseName` and `ContainerName` constants defined on lines 16 and 17 refer to the Azure Cosmos DB database created by the Bicep script and the container you created in task 1 of this exercise, respectively. If those values differ in your environment, the values assigned to the constants must be updated to reflect what is in your environment. - Locate the `Run` function starting on line 42 and examine the code contained within it. - The code on line 49 reduces the list of documents sent to the function to only those that do not have a `Type` of "Vectorized". This prevents the updates pushed by the function back to the `MaintenanceRequests` container from being revectorized by the function. - - If there are no documents that require vectorization, the function will exit without making any changes to the input documents. - - The `foreach` loop starting on line 52 iterates through each document in the change feed that requires vectorization. The `hotel` and `details` fields are combined and the text is sent to Azure OpenAI to create vector embeddings using the deployment for the `text-embedding-ada-002` model. The returned vector embeddings are saved into the `RequestVector` field of the document. - - The document's `Type` field is set to "Vectorized". + - If no documents require vectorization, the function will exit without making any changes to the input documents. + - The `foreach` loop starting on line 52 iterates through each document in the change feed that requires vectorization. The `hotel` and `details` fields are combined, and the text is sent to Azure OpenAI to create vector embeddings using the deployment for the `text-embedding-ada-002` model. The returned vector embeddings are saved into the `RequestVector` field of the document. + - The document's `Type` field is "Vectorized." - On line 74, the list of input documents is returned, which uses the Cosmos DB output binding to write the documents updated with vector embeddings back into the `MaintenanceRequests` container in Cosmos DB. - To create a `local.settings.json` file, navigate to the `src\ContosoSuitesVectorizationFunction` directory, create a new file named `local.settings.json`, and add the following content, replacing the bracketed tokens with values from your Azure OpenAI and Azure Cosmos DB services. @@ -147,10 +147,10 @@ You will then receive a warning modal that this operation will overwrite your ta ![The Azure Cosmos DB account Keys page is displayed, with the PRIMARY CONNECTION STRING copy button highlighted.](../../media/Solution/0302-azure-cosmos-db-keys.png) - - The `EmbeddingDeploymentName` value is preset, based on the deployment created by the Bicep script for the `text-embedding-ada-002` model. If that value differs in your environment, you will need to update this settings accordingly. + - The `EmbeddingDeploymentName` value is preset, based on the deployment created by the Bicep script for the `text-embedding-ada-002` model. If that value differs in your environment, you must update this setting accordingly. - To test the function locally: - - Open a new terminal windows in Visual Studio Code and change the path to the `src\ContosoSuitesVectorizationFunction` folder. + - Open a new terminal window in Visual Studio Code and change the path to the `src\ContosoSuitesVectorizationFunction` folder. - Open the `CosmosChangeFeedVectorization.cs` file in the `src\ContosoSuitesVectorizationFunction` folder. - Set a breakpoint on line 50 so you can examine the values of the `documentsToVectorize`, `task.RequestVector`, and `input` as you step through the function. - Select **F5** on your keyboard to start a debug session in Visual Studio Code. In the terminal window created, wait until the function has started. @@ -184,24 +184,24 @@ You will then receive a warning modal that this operation will overwrite your ta dotnet publish ``` - - In the explorer pane in Visual Studio Code, navigate to the `src\ContosoSuitesVectorizationFunction\bin\Release\net8.0` folder, then right-click on the `publish` folder and in the context menu, select **Deploy to Function App**. + - In the explorer pane in Visual Studio Code, navigate to the `src\ContosoSuitesVectorizationFunction\bin\Release\net8.0` folder, then right-click on the `publish` folder, and in the context menu, select **Deploy to Function App**. - In the **Select Function App** command pallet dialog that appears at the top of Visual Studio Code: - Select the subscription you are using for this exercise. - Choose the function app in your resource group. - Select **Deploy** in the Visual Studio Code dialog asking about deploying and overwriting previous deployments. - Use the **Output** window at the bottom of Visual Studio Code to monitor the deployment. - - When the deployment completes, you will get a notification in the bottom right-hand corner of Visual Studio Code. In this notification window, select **Upload settings**. This will upload the values from the `local.settings.json` file into environment variables in your function app. + - When the deployment is complete, you will get a notification in the bottom right-hand corner of Visual Studio Code. In this notification window, select **Upload settings**. This will upload the values from the `local.settings.json` file into environment variables in your function app. ![The Upload settings button is highlighted on the deployment completed notification dialog.](../../media/Solution/0302-azure-function-deployment-upload-settings.png) - Confirm the settings were uploaded correctly by navigating to the **Settings** menu of your function app in the [Azure portal](https://portal.azure.com/) and selecting **Environment variables**. You should see the `AzureOpenAIEndpoint`, `AzureOpenAIKey`, `CosmosDBConnectionString`, and `EmbeddingDeploymentName` settings, along with other settings added by the Bicep script and deployment process. {: .note } - > If you do not see these settings, you can add them yourself using the **+ Add** button on the App settings tab. + > If you do not see these settings, add them using the App settings tab's **+ Add** button. - To verify the function app was deployed successfully and is working correctly: - - Open the Log Stream for the Function App by select **Log Stream** under **Monitoring** in the left-hand menu of the Function App page in the [Azure portal](https://portal.azure.com/). - - Open a new browser window or tab and navigate to the `MaintenanceRequests` container in your Cosmos DB account, and select `Items`. + - Open the Log Stream for the Function App by selecting **Log Stream** under **Monitoring** in the left-hand menu of the Function App page in the [Azure portal](https://portal.azure.com/). +  - Open a new browser window or tab, navigate to the `MaintenanceRequests` container in your Cosmos DB account, and select `Items`. - Insert the following record into the `MaintenanceRequests` container in Cosmos DB. ```json @@ -215,10 +215,10 @@ You will then receive a warning modal that this operation will overwrite your ta } ``` - - Return to the Function Apps **Log Stream** browser window and observe the logs to ensure you see the function execute and see that it generated vector embeddings for the maintenance request. - - Return to the Cosmos DB `MaintenanceRequests` browser window and select the request item that was just inserted to make sure it refreshes and contains a `request_vector` value. + - Return to the Function Apps **Log Stream** browser window and observe the logs to ensure you see the function execute and verify that it generated vector embeddings for the maintenance request. + - Return to the Cosmos DB `MaintenanceRequests` browser window and select the request item that was just inserted to ensure it refreshes and contains a `request_vector` value. -- To populate the `MaintenanceRequests` container with data from the `PropertyMaintenance.json` file provided by Contoso Suites, use the Data Explorer. +- Use the Data Explorer to populate the `MaintenanceRequests` container with data from the `PropertyMaintenance.json` file provided by Contoso Suites. - In the [Azure portal](https://portal.azure.com), navigate to your Cosmos DB resource and select **Data Explorer** in the left-hand menu. - In the Data Explorer, expand the **ContosoSuites** database and the **MaintenanceRequests** container, then select **Items**. @@ -237,12 +237,12 @@ You will then receive a warning modal that this operation will overwrite your ta The upload status should indicate 48 documents created. - - Return to the Function Apps **Log Stream** browser window you opened in the previous step and observe the logs as the maintenance request are bulk uploaded and processed. + - Return to the Function Apps **Log Stream** browser window you opened in the previous step and observe the logs as the maintenance requests are uploaded and processed in bulk. - Return to the Cosmos DB `MaintenanceRequests` browser window, close the upload dialog, and select the refresh icon on the MaintenanceRequests>Items tab in the Data Explorer. ![The refresh button is highlighted on the Maintenance->Items tab in Data Explorer.](../../media/Solution/0302-azure-cosmos-db-maintenance-requests-items-refresh.png) - - Select a few random request items to ensure they contain a `request_vector` value and have a `type` of "Vectorized". + - Select a few random request items to ensure they contain a `request_vector` value and have a `type` of "Vectorized." - To execute a query using the `VectorDistance()` function for "air conditioning malfunction": - In the [Azure portal](https://portal.azure.com), navigate to your Cosmos DB resource and select **Data Explorer** in the left-hand menu. @@ -259,7 +259,7 @@ You will then receive a warning modal that this operation will overwrite your ta ``` - Replace the `` token in the query with the vectorized representation of "air conditioning malfunction," which you can find in the `Query_Vector.txt` file in the [src\data folder](https://github.com/microsoft/TechExcel-Integrating-Azure-PaaS-and-AI-Services-for-AI-Design-Wins/tree/main/src/data). Copy the entire contents of the file, and paste it into the query in place of ``. - - Select **Execute Query** on the toolbar and observe the output in the **Results** panel. You should see list of results similar to the following (abbreviated for brevity): + - Select **Execute Query** on the toolbar and observe the output in the **Results** panel. You should see a list of results similar to the following (abbreviated for brevity): ```json { diff --git a/docs/03_implement_vector_search_in_cosmos_db_nosql/0303.md b/docs/03_implement_vector_search_in_cosmos_db_nosql/0303.md index 8ebcf8cb5..3360680b0 100644 --- a/docs/03_implement_vector_search_in_cosmos_db_nosql/0303.md +++ b/docs/03_implement_vector_search_in_cosmos_db_nosql/0303.md @@ -9,17 +9,17 @@ parent: 'Exercise 03: Implement contextual grounding' ## Introduction -Implementing vector search capabilities in the Contoso Suites UI will allow customer service representatives to use natural language queries to be used to find maintenance requests. This functionality relies on the ability of vector search to find items based on data characteristics instead of exact matches on a specific property field. In the prior task, you vectorized maintenance request content that combined the name of the hotel with the details of the request, which will allow searching for requests at a specific hotel or across various properties. +Implementing vector search capabilities in the Contoso Suites UI will allow customer service representatives to use natural language queries to find maintenance requests. This functionality relies on vector search's ability to find items based on data characteristics instead of exact matches on a specific property field. In the prior task, you vectorized maintenance request content that combined the hotel's name with the request details, allowing searching for requests at a specific hotel or across various properties. ## Description -In the previous task, you added vector embeddings to property maintenance request data stored in Azure Cosmos DB for NoSQL and then performed a vector search using query embeddings stored in a file. To perform vector searches, it is necessary to create embeddings for incoming query text, so in this task, you will integrate vector search capabilities into the Contoso Suites Customer Information System (CIS) application, leveraging a vectorization API endpoint in the Contoso Suites Web API to create embeddings for the query being performed. The API will be used to vectorize incoming questions from the UI, so they can be used in queries executing the `VectorDistance()` function. +In the previous task, you added vector embeddings to property maintenance request data stored in Azure Cosmos DB for NoSQL and then performed a vector search using query embeddings stored in a file. It is necessary to create embeddings for incoming query text to perform vector searches, so in this task, you will integrate vector search capabilities into the Contoso Suites Customer Information System (CIS) application, leveraging a vectorization API endpoint in the Contoso Suites Web API to create embeddings for the query being performed. The API will vectorize incoming questions from the UI, which can be used in queries executing the `VectorDistance()` function. The key tasks are as follows: -1. Add a new .NET user secret called `CosmosDB:ConnectionString`. The value of this should be your Cosmos DB connection string. Add another user secret called `AzureOpenAI:EmbeddingDeploymentName`, which should take on a value of `text-embedding-ada-002`. +1. Add a new .NET user secret called `CosmosDB:ConnectionString`. This value should be your Cosmos DB connection string. Add another user secret called `AzureOpenAI:EmbeddingDeploymentName`, which should take on a value of `text-embedding-ada-002`. 2. Generate query text embeddings using the `/Vectorize` endpoint of the ContosoSuitesWebAPI. -3. Provide a method named `ExecuteVectorSearch` in the `VectorizationService` for executing a vector search query against Azure Cosmos DB. The method should accept vectorized query text (named `queryVector`), the maximum number of results to return (named `max_results`), and the minimum similarity score (named `minimum_similarity_score`) and execute a query using the `VectorDistance()` function. It should return a list of `VectorSearchResult` objects. The count should limit the number of results returned. The query executed in Cosmos DB should use the following pattern: +3. Provide a method named `ExecuteVectorSearch` in the `VectorizationService` for executing a vector search query against Azure Cosmos DB. The method should accept vectorized query text (called `queryVector`), the maximum number of results to return (named `max_results`), and the minimum similarity score (named `minimum_similarity_score`) and execute a query using the `VectorDistance()` function. It should return a list of `VectorSearchResult` objects. The count should limit the number of results returned. The query executed in Cosmos DB should use the following pattern: ```csharp var query = $"SELECT c.hotel_id AS HotelId, c.hotel AS Hotel, c.details AS Details, c.source AS Source, VectorDistance(c.request_vector, [{string.Join(",", queryVector)}]) AS SimilarityScore FROM c"; @@ -29,10 +29,10 @@ The key tasks are as follows: 4. Update the `/VectorSearch` route handler in the `Program.cs` file to call the `ExecuteVectorSearch` method on the `VectorizationService` and return the results. 5. Implement vector search capabilities to the UI and submit the following queries for maintenance requests: - - Set the search query to "Show me rooms where the air conditioning unit is malfunctioning" and enter 10 as the max result count and select a minimum similarity score of 0.80. - - Execute the same query a second time, this time setting the minimum similarity score to 0.82 and observe how that setting can be used to reduce the number of irrelevant results. - - Search for "Rooms at the Oceanview Inn where there are air conditioning issues" and enter 5 as the maximum number of results to return and set the minimum similarity score slider to 0.85. - - Find for any fire safety requests using the search query, "Are there any requests pertaining to fire and safety equipment at any hotels?" Set the max results to 10. + - Set the search query to "Show me rooms where the air conditioning unit is malfunctioning," enter ten as the max result count and select a minimum similarity score of 0.80. + - Execute the same query a second time, this time setting the minimum similarity score to 0.82, and observe how that setting can be used to reduce the number of irrelevant results. + - Search for "Rooms at the Oceanview Inn where there are air conditioning issues, " enter five as the maximum number of results to return and set the minimum similarity score slider to 0.85. + - Finally, find fire safety requests using the search query, "Are there any requests about fire and safety equipment at any hotels?" Set the max results to 10. ## Success Criteria @@ -40,11 +40,11 @@ The key tasks are as follows: - You have updated the `VectorizationService` and its interface to include an `ExecuteVectorSearch(float[] queryVector, int count = 0)` method that returns `List>`. - You have added a `/VectorSearch` endpoint to the API. - You have tested the `/VectorSearch` endpoint using the Swagger UI by passing in vector embeddings generated by the `/Vectorize` endpoint. -- You have successfully added the ability to perform vector searches to the UI and submitted queries.. +- You have successfully added the ability to perform vector searches to the UI and submitted queries. ## Tips -- If the ContosoSuitesWebAPI .NET application build is failing when you try to run `dotnet run` and you receive an error that the build cannot load the required packages from NuGet, you may be missing a link to the Microsoft NuGet repository. Run the command `dotnet nuget list source` and see if you have an entry enabled for nuget.org. If not, you can add it with the following command: `dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org`. If you have one but it is currently disabled, you can enable it with the command `dotnet nuget enable source nuget.org`. +- If the ContosoSuitesWebAPI .NET application build is failing when you try to run `dotnet run` and you receive an error that the build cannot load the required packages from NuGet, you may be missing a link to the Microsoft NuGet repository. Run the command `dotnet nuget list source` and see if you have an entry enabled for nuget.org. If not, add it with the following command: `dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org`. If you have one but it is currently disabled, you can enable it with the command `dotnet nuget enable source nuget.org`. ## Learning Resources @@ -81,7 +81,7 @@ The key tasks are as follows: {: .note } > If you are using a GitHub Codespaces instance, open the website in a browser and navigate to the **/swagger** URL. - - On the Swagger UI page, expand the `/Vectorize` endpoint block. + - Expand the `/Vectorize` endpoint block on the Swagger UI page. ![The Swagger UI page is displayed with the expand button for the Vectorize endpoint highlighted.](../../media/Solution/0303-web-api-swagger-ui.png) @@ -94,7 +94,7 @@ The key tasks are as follows: ![In the Vectorize block, the text block is highlighted with the query text above entered and the execute button is highlighted.](../../media/Solution/0303-web-api-swagger-vectorize-execute.png) - Observe the **Response body** returned. The response contains an array of floating point values representing the query text. This array contains 1536 dimensions. - - Copy the entire response body, include the opening and closing square brackets. + - Copy the entire response body, including the opening and closing square brackets. ![The Response body block for the vectorization request is highlighted.](../../media/Solution/0303-web-api-swagger-vectorize-response-body.png) @@ -110,7 +110,7 @@ The key tasks are as follows: - Replace the `` token in the query with the vector output you copied from the API response body. - Select **Execute Query** on the toolbar and observe the output in the **Results** panel. - - In Visual Studio Code, stop the API project by selecting the teminal window where it is runnig and pressing CTRL+C. + - In Visual Studio Code, stop the API project by selecting the terminal window where it is running and pressing CTRL+C. - To provide a method in the `VectorizationService` and an API endpoint for executing a vector search query against Azure Cosmos DB: - In Visual Studio Code, open the `IVectorizationService.cs` file in the `src\ContosoSuitesWebAPI` folder and complete `Exercise 3 Task 3 TODO #1` by uncommenting the interface definition for the `ExecuteVectorSearch` method. @@ -124,7 +124,7 @@ The key tasks are as follows: return results; ``` - - Return to the the terminal prompt and enter the following command again to start the API locally: + - Return to the terminal prompt and enter the following command again to start the API locally: ```bash dotnet run @@ -132,7 +132,7 @@ The key tasks are as follows: - Once the API has started, test the `/VectorSearch` endpoint by opening a web browser and navigating to the [Swagger UI page for the API](http://localhost:5292/swagger/). - On the Swagger UI page, use the `/Vectorize` endpoint to generate embeddings for the query text "rooms where the air conditioning is not working", as you did previously. - - Copy the entire response body, include the opening and closing square brackets. + - Copy the entire response body, including the opening and closing square brackets. - Expand the `/VectorSearch` endpoint block and select **Try it out**. - Enter "5" into the `max_results` parameter box. - Enter "0.5" into the `minimum_similarity_score` parameter box. @@ -184,10 +184,10 @@ The key tasks are as follows: - Leave the Web API running for the next step. -- To add vector search capabilities to the UI, open the file `src\ContosoSuitesDashboard\pages\3_Vector_Search.py`. The code will run as-is, but will not have knowledge of how to vectorize query text or perform vector searches. The support vector search capabilities, make the following changes to the Python script. +- To add vector search capabilities to the UI, open the file `src\ContosoSuitesDashboard\pages\3_Vector_Search.py`. The code will run as-is, but will not have knowledge of how to vectorize query text or perform vector searches. To support vector search capabilities, make the following changes to the Python script. - In the `if query:` block of the Submit button code in the `main()` function: - Vectorize the search query text by completing `Exercise 3 Task 3 TODO #4`. Send the search query text to the `handle_query_vectorization()` method and set the results to a variable. - - Perform a vector search by completing `Exercise 3 Task 3 TODO #5`. Pass the vectorized search query, along with the desired number of results to the `handle_vector_search()` function. + - Perform a vector search by completing `Exercise 3 Task 3 TODO #5`. Pass the vectorized search query, along with the desired number of results, to the `handle_vector_search()` function. - Display the results in a table by completing `Exercise 3 Task 3 TODO #6`. Use the `st.table()` method and provide the JSON value from the search results. - The completed code for the `if st.button("Submit")` block should look like the following: @@ -210,7 +210,7 @@ The key tasks are as follows: ``` {: .note } - > Python code is sensitive to indentation and formatting, so pay close attention to indentation if you are copying and pasting the above code into the `3_Vector_Search.py` file. + > Python code is sensitive to indentation and formatting, so pay close attention to indentation if copying and pasting the above code into the `3_Vector_Search.py` file. - Test your completed code by opening a new terminal window in Visual Studio Code, navigating to the `src\ContosoSuitesDashboard` folder, and running the following command to start the Streamlit dashboard: @@ -219,9 +219,9 @@ The key tasks are as follows: ``` - Navigate to the **Vector Search** page using the left-hand menu in the browser windows that opens, and then submit the following queries for maintenance requests and observe the results: - - Set the search query to "Show me rooms where the air conditioning unit is malfunctioning" and enter 10 as the max result count and select a minimum similarity score of 0.80. - - Execute the same query a second time, this time setting the minimum similarity score to 0.82 and observe how that setting can be used to reduce the number of irrelevant results. - - Search for "Rooms at the Oceanview Inn where there are air conditioning issues" and enter 5 as the maximum number of results to return and set the minimum similarity score slider to 0.85. - - Find for any fire safety requests using the search query, "Are there any requests pertaining to fire and safety equipment at any hotels?" Set the max results to 10. +  - Set the search query to "Show me rooms where the air conditioning unit is malfunctioning," enter ten as the max result count and select a minimum similarity score of 0.80. +  - Execute the same query a second time, this time setting the minimum similarity score to 0.82, and observe how that setting can be used to reduce the number of irrelevant results. +  - Search for "Rooms at the Oceanview Inn where there are air conditioning issues, " enter five as the maximum number of results to return and set the minimum similarity score slider to 0.85. +  - Find fire safety requests using the search query, "Are there any requests about fire and safety equipment at any hotels?" Set the max results to 10.