Skill 3.2.7
Implement vector search
Key Concepts
The query text is embedded with AI_GENERATE_EMBEDDINGS(@question USE MODEL m) into a vector(n) variable. Exact search is SELECT TOP (10) ..., VECTOR_DISTANCE('cosine', Embedding, @q) AS distance FROM ... ORDER BY distance. Approximate search uses SELECT TOP (10) WITH APPROXIMATE ... FROM VECTOR_SEARCH(...) AS r ORDER BY r.distance; the ORDER BY must be on distance only and ascending, and operations such as GROUP BY or window functions go in an outer query around a subquery.
Filters such as category or tenant go in the WHERE clause; with the latest vector indexes they are applied during the search, so the query returns N matching rows when they exist. A maximum distance threshold removes weak matches. Results are joined back to the source table for display, and a stored procedure that wraps the search can be exposed through Data API builder or called by a RAG procedure.