From 0b7fceeb86e9358fdd550e256ca7bbf7abdf06bb Mon Sep 17 00:00:00 2001 From: Dante Date: Tue, 25 Aug 2026 20:12:41 -0500 Subject: [PATCH 1/4] Modify search query to use TOP (5) WITH APPROXIMATE --- Instructions/Labs/10-implement-intelligent-search.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Instructions/Labs/10-implement-intelligent-search.md b/Instructions/Labs/10-implement-intelligent-search.md index c000641..d5de393 100644 --- a/Instructions/Labs/10-implement-intelligent-search.md +++ b/Instructions/Labs/10-implement-intelligent-search.md @@ -464,7 +464,7 @@ Vector search finds reviews based on the semantic meaning of text, not just keyw SELECT @searchVector = AI_GENERATE_EMBEDDINGS(@searchText USE MODEL my_embedding_model); - SELECT + SELECT TOP (5) WITH APPROXIMATE p.Name AS ProductName, r.ReviewTitle, r.ReviewText, @@ -475,8 +475,7 @@ Vector search finds reviews based on the semantic meaning of text, not just keyw TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @searchVector, - METRIC = 'cosine', - TOP_N = 5 + METRIC = 'cosine' ) AS vs INNER JOIN SalesLT.Product p ON r.ProductID = p.ProductID @@ -610,7 +609,7 @@ To understand the strengths of each approach, run the same question through all SELECT @searchVector = AI_GENERATE_EMBEDDINGS(@searchText USE MODEL my_embedding_model); - SELECT + SELECT TOP (5) WITH APPROXIMATE p.Name AS ProductName, r.ReviewTitle, r.ReviewText, @@ -620,8 +619,7 @@ To understand the strengths of each approach, run the same question through all TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @searchVector, - METRIC = 'cosine', - TOP_N = 5 + METRIC = 'cosine' ) AS vs INNER JOIN SalesLT.Product p ON r.ProductID = p.ProductID @@ -710,4 +708,4 @@ If you provisioned a new resource group for this lab, you can simply delete the You successfully completed this exercise. -In this exercise, you implemented and compared three search approaches in Azure SQL Database: full-text search using a full-text index with keyword predicates and inflectional patterns, vector search using exact and approximate nearest neighbor queries with a DiskANN index, and hybrid search combining both methods with Reciprocal Rank Fusion to merge keyword and semantic results. You compared all three approaches on the same query to understand the strengths of each. \ No newline at end of file +In this exercise, you implemented and compared three search approaches in Azure SQL Database: full-text search using a full-text index with keyword predicates and inflectional patterns, vector search using exact and approximate nearest neighbor queries with a DiskANN index, and hybrid search combining both methods with Reciprocal Rank Fusion to merge keyword and semantic results. You compared all three approaches on the same query to understand the strengths of each. From 9f1d1142ad85e1abe827f8fddc89f19d9a034c15 Mon Sep 17 00:00:00 2001 From: Dante Date: Tue, 25 Aug 2026 20:14:52 -0500 Subject: [PATCH 2/4] Implement approximate selection in vector search queries --- Instructions/Labs/10-implement-intelligent-search.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Instructions/Labs/10-implement-intelligent-search.md b/Instructions/Labs/10-implement-intelligent-search.md index d5de393..a4322b6 100644 --- a/Instructions/Labs/10-implement-intelligent-search.md +++ b/Instructions/Labs/10-implement-intelligent-search.md @@ -534,15 +534,14 @@ RRF combines ranked results from different sources by using rank positions inste ReviewID, RANK() OVER (ORDER BY distance) AS vector_rank FROM ( - SELECT + SELECT TOP (50) WITH APPROXIMATE r.ReviewID, vs.distance FROM VECTOR_SEARCH( TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @searchVector, - METRIC = 'cosine', - TOP_N = 50 + METRIC = 'cosine' ) AS vs ) AS similar_reviews ), @@ -651,15 +650,14 @@ To understand the strengths of each approach, run the same question through all ReviewID, RANK() OVER (ORDER BY distance) AS vector_rank FROM ( - SELECT + SELECT TOP (50) WITH APPROXIMATE r.ReviewID, vs.distance FROM VECTOR_SEARCH( TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @searchVector, - METRIC = 'cosine', - TOP_N = 50 + METRIC = 'cosine' ) AS vs ) AS similar_reviews ), From a05807b812875a80e713ed10f4a322366b4cb400 Mon Sep 17 00:00:00 2001 From: Dante Date: Tue, 25 Aug 2026 20:19:03 -0500 Subject: [PATCH 3/4] Add ORDER BY clause for distance in search queries --- Instructions/Labs/10-implement-intelligent-search.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Instructions/Labs/10-implement-intelligent-search.md b/Instructions/Labs/10-implement-intelligent-search.md index a4322b6..9ef0f06 100644 --- a/Instructions/Labs/10-implement-intelligent-search.md +++ b/Instructions/Labs/10-implement-intelligent-search.md @@ -543,6 +543,7 @@ RRF combines ranked results from different sources by using rank positions inste SIMILAR_TO = @searchVector, METRIC = 'cosine' ) AS vs + ORDER BY vs.distance ) AS similar_reviews ), combined AS ( @@ -659,6 +660,7 @@ To understand the strengths of each approach, run the same question through all SIMILAR_TO = @searchVector, METRIC = 'cosine' ) AS vs + ORDER BY vs.distance ) AS similar_reviews ), combined AS ( From 8e9e058824777881a1e91f431c377473e5f6e16f Mon Sep 17 00:00:00 2001 From: Dante Date: Tue, 25 Aug 2026 20:31:20 -0500 Subject: [PATCH 4/4] Refactor ANN vector search queries for consistency --- .../Labs/11-implement-rag-solutions.md | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Instructions/Labs/11-implement-rag-solutions.md b/Instructions/Labs/11-implement-rag-solutions.md index 461e1e3..9a94ca8 100644 --- a/Instructions/Labs/11-implement-rag-solutions.md +++ b/Instructions/Labs/11-implement-rag-solutions.md @@ -324,7 +324,7 @@ In this section, you practice the **retrieval** step of RAG. Instead of using a SELECT @questionVector = AI_GENERATE_EMBEDDINGS(@userQuestion USE MODEL my_embedding_model); -- Find the top 5 most relevant reviews using ANN vector search - SELECT + SELECT TOP (5) WITH APPROXIMATE p.Name AS ProductName, p.ListPrice, pc.Name AS Category, @@ -336,13 +336,13 @@ In this section, you practice the **retrieval** step of RAG. Instead of using a TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @questionVector, - METRIC = 'cosine', - TOP_N = 5 + METRIC = 'cosine' ) AS vs INNER JOIN SalesLT.Product p ON r.ProductID = p.ProductID INNER JOIN SalesLT.ProductCategory pc ON p.ProductCategoryID = pc.ProductCategoryID + ORDER BY vs.distance FOR JSON PATH; GO ``` @@ -368,7 +368,7 @@ Now you combine retrieved data with a system message and user question to build -- Step 2: Retrieve relevant reviews using ANN vector search SET @context = ( - SELECT + SELECT TOP (5) WITH APPROXIMATE p.Name AS ProductName, p.ListPrice, pc.Name AS Category, @@ -379,13 +379,13 @@ Now you combine retrieved data with a system message and user question to build TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @questionVector, - METRIC = 'cosine', - TOP_N = 5 + METRIC = 'cosine' ) AS vs INNER JOIN SalesLT.Product p ON r.ProductID = p.ProductID INNER JOIN SalesLT.ProductCategory pc ON p.ProductCategoryID = pc.ProductCategoryID + ORDER BY vs.distance FOR JSON PATH ); @@ -401,7 +401,7 @@ Now you combine retrieved data with a system message and user question to build 'content': 'Product reviews: ' + ISNULL(@context, '[]') + CHAR(10) + CHAR(10) + 'Customer question: ' + @userQuestion ) ), - 'max_tokens': CAST(500 AS INT), + 'max_completion_tokens': CAST(500 AS INT), 'temperature': 0.5 ); @@ -433,7 +433,7 @@ This step is the "G" in RAG, the generation step. You send the augmented prompt -- Step 2: Retrieve relevant reviews using ANN vector search SET @context = ( - SELECT + SELECT TOP (5) WITH APPROXIMATE p.Name AS ProductName, p.ListPrice, pc.Name AS Category, @@ -444,13 +444,13 @@ This step is the "G" in RAG, the generation step. You send the augmented prompt TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @questionVector, - METRIC = 'cosine', - TOP_N = 5 + METRIC = 'cosine' ) AS vs INNER JOIN SalesLT.Product p ON r.ProductID = p.ProductID INNER JOIN SalesLT.ProductCategory pc ON p.ProductCategoryID = pc.ProductCategoryID + ORDER BY vs.distance FOR JSON PATH ); @@ -466,7 +466,7 @@ This step is the "G" in RAG, the generation step. You send the augmented prompt 'content': 'Product reviews: ' + ISNULL(@context, '[]') + CHAR(10) + CHAR(10) + 'Customer question: ' + @userQuestion ) ), - 'max_tokens': CAST(500 AS INT), + 'max_completion_tokens': CAST(500 AS INT), 'temperature': 0.5 ); @@ -523,7 +523,7 @@ Now put it all together in a reusable stored procedure that your application can -- Step 2: Retrieve relevant reviews using ANN vector search SET @context = ( - SELECT + SELECT TOP (5) WITH APPROXIMATE p.Name AS ProductName, p.ListPrice, pc.Name AS Category, @@ -534,13 +534,13 @@ Now put it all together in a reusable stored procedure that your application can TABLE = dbo.ProductReview AS r, COLUMN = ReviewVector, SIMILAR_TO = @questionVector, - METRIC = 'cosine', - TOP_N = 5 + METRIC = 'cosine' ) AS vs INNER JOIN SalesLT.Product p ON r.ProductID = p.ProductID INNER JOIN SalesLT.ProductCategory pc ON p.ProductCategoryID = pc.ProductCategoryID + ORDER BY vs.distance FOR JSON PATH ); @@ -568,7 +568,7 @@ Now put it all together in a reusable stored procedure that your application can 'content': 'Product reviews: ' + @context + CHAR(10) + CHAR(10) + 'Customer question: ' + @Question ) ), - 'max_tokens': CAST(500 AS INT), + 'max_completion_tokens': CAST(500 AS INT), 'temperature': 0.5 );