Lab 11: Implement RAG solutions: VECTOR_SEARCH T-SQL update required

Open Beginner friendly
#13 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
sql

Research direction

Start with the lab section “Retrieve data using vector search and format it as JSON context,” specifically Step 1 and its code window. Update the example to use the supplied VECTOR_SEARCH query without TOP_N, then verify the T-SQL remains valid and produces JSON context as described.

Written by the indexing model from the issue text.

Description

Section: Retrieve data using vector search and format it as JSON context

Step: 1

The code in this window needs to be updated. TOP_N function is not longer supported. It shoudl look something like this:

-- Convert a question to an embedding and find the closest matching reviews

DECLARE @userQuestion NVARCHAR(1000) =
N'What mountain bike can handle really technical rocky trails?';

DECLARE @questionVector VECTOR(1536);

-- Generate embedding for the question
SELECT @questionVector =
AI_GENERATE_EMBEDDINGS(
@userQuestion
USE MODEL my_embedding_model
);

-- Find the top 5 most relevant reviews using ANN vector search
SELECT TOP (5)
p.Name AS ProductName,
p.ListPrice,
pc.Name AS Category,
r.Rating,
r.ReviewTitle,
r.ReviewText,
vs.distance AS Distance
FROM VECTOR_SEARCH(
TABLE = dbo.ProductReview,
COLUMN = ReviewVector,
SIMILAR_TO = @questionVector,
METRIC = 'cosine'
) AS vs
INNER JOIN dbo.ProductReview AS r
ON r.ProductReviewID = vs.ProductReviewID
INNER JOIN SalesLT.Product AS p
ON r.ProductID = p.ProductID
INNER JOIN SalesLT.ProductCategory AS pc
ON p.ProductCategoryID = pc.ProductCategoryID
ORDER BY vs.distance
FOR JSON PATH;
GO

Dominant language
TSQL
Stars
23
Forks
34
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MicrosoftLearning/mslearn-sql-developer

All issues in MicrosoftLearning/mslearn-sql-developer

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.