Skip to content

Commit bc6b46c

Browse files
zijchenllali
authored andcommitted
Merged PR 1758352: Add ScriptDom support for VECTOR_SEARCH function
# Pull Request Template for ScriptDom ## Description Added parser and script generator support for VECTOR_SEARCH Before submitting your pull request, please ensure you have completed the following: ## Code Change - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code ## Testing - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature ## Documentation - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file ## Additional Information Please provide any additional information that might be helpful for the reviewers Add ScriptDom support for VECTOR_SEARCH function ---- #### AI description (iteration 1) #### PR Classification This pull request introduces a new feature by adding native ScriptDom support for the VECTOR_SEARCH function. #### PR Summary The changes implement parsing, AST definition, and script generation for VECTOR_SEARCH, along with a comprehensive suite of tests to validate error handling and syntax compliance. - **`SqlScriptDom/ScriptDom/SqlServer/ScriptGenerator/SqlScriptGeneratorVisitor.VectorSearchTableReference.cs`**: New file added to generate script output for the VECTOR_SEARCH function. - **`SqlScriptDom/Parser/TSql/TSql170.g` & `SqlDom/Parser/TSql/Ast.xml`**: Extended grammar rules and AST definitions to support VECTOR_SEARCH. - **`SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs`**: Added new constants (e.g., COSINE, DOT, EUCLIDEAN, METRIC, TOP_N, VECTOR_SEARCH) required for vector search processing. - **`Test/SqlDom/ParserErrorsTests.cs` and related vector test scripts**: Introduced extensive tests covering syntax errors and parameter validations for VECTOR_SEARCH. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4440435
1 parent e8e9082 commit bc6b46c

8 files changed

Lines changed: 289 additions & 0 deletions

File tree

SqlScriptDom/Parser/TSql/Ast.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,4 +4752,12 @@
47524752
<Member Name="ModelName" Type="SchemaObjectName" Summary="Model name used in USE MODEL clause." />
47534753
<Member Name="OptionalParameters" Type="ScalarExpression" Summary="Optional PARAMETERS clause, must evaluate to JSON." />
47544754
</Class>
4755+
<Class Name="VectorSearchTableReference" Base="TableReferenceWithAlias" Summary="Represents the VECTOR_SEARCH table-valued function call.">
4756+
<InheritedClass Name="TableReferenceWithAlias" />
4757+
<Member Name="Table" Type="TableReferenceWithAlias" Summary="Table on which perform the search." />
4758+
<Member Name="Column" Type="ColumnReferenceExpression" Summary="The vector column in which search is performed." />
4759+
<Member Name="SimilarTo" Type="ScalarExpression" Summary="The vector used for search." />
4760+
<Member Name="Metric" Type="StringLiteral" Summary="The distance metric to use for the search." />
4761+
<Member Name="TopN" Type="IntegerLiteral" Summary="The maximum number of similar vectors that must be returned." />
4762+
</Class>
47554763
</Types>

SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ internal static class CodeGenerationSupporter
249249
internal const string CopyCommand = "COPY";
250250
internal const string CopyOnly = "COPY_ONLY";
251251
internal const string Correlated = "CORRELATED";
252+
internal const string Cosine = "COSINE";
252253
internal const string Count = "COUNT";
253254
internal const string CountBig = "COUNT_BIG";
254255
internal const string Counter = "COUNTER";
@@ -325,6 +326,7 @@ internal static class CodeGenerationSupporter
325326
internal const string Document = "DOCUMENT";
326327
internal const string DollarSign = "$";
327328
internal const string DollarPartition = "$PARTITION";
329+
internal const string Dot = "DOT";
328330
internal const string Drop = "DROP";
329331
internal const string DropExisting = "DROP_EXISTING";
330332
internal const string DTSBuffers = "DTS_BUFFERS";
@@ -364,6 +366,7 @@ internal static class CodeGenerationSupporter
364366
internal const string ErrorFileCredential = "ERRORFILE_CREDENTIAL";
365367
internal const string EscapeChar = "ESCAPECHAR";
366368
internal const string EstimateOnly = "ESTIMATEONLY";
369+
internal const string Euclidean = "EUCLIDEAN";
367370
internal const string Event = "EVENT";
368371
internal const string EventRetentionMode = "EVENT_RETENTION_MODE";
369372
internal const string Exclamation = "!";
@@ -625,6 +628,7 @@ internal static class CodeGenerationSupporter
625628
internal const string Message = "MESSAGE";
626629
internal const string MessageForwarding = "MESSAGE_FORWARDING";
627630
internal const string MessageForwardSize = "MESSAGE_FORWARD_SIZE";
631+
internal const string Metric = "METRIC";
628632
internal const string MigrationState = "MIGRATION_STATE";
629633
internal const string Metric = "METRIC";
630634
internal const string Min = "MIN";
@@ -930,6 +934,7 @@ internal static class CodeGenerationSupporter
930934
internal const string ShrinkDb = "SHRINKDB";
931935
internal const string Sid = "SID";
932936
internal const string Signature = "SIGNATURE";
937+
internal const string SimilarTo = "SIMILAR_TO";
933938
internal const string Simple = "SIMPLE";
934939
internal const string SingleBlob = "SINGLE_BLOB";
935940
internal const string SingleClob = "SINGLE_CLOB";
@@ -1039,6 +1044,7 @@ internal static class CodeGenerationSupporter
10391044
internal const string Timer = "TIMER";
10401045
internal const string TimeStamp = "TIMESTAMP";
10411046
internal const string TinyInt = "TINYINT";
1047+
internal const string TopN = "TOP_N";
10421048
internal const string TornPageDetection = "TORN_PAGE_DETECTION";
10431049
internal const string TrackCausality = "TRACK_CAUSALITY";
10441050
internal const string TrackColumnsUpdated = "TRACK_COLUMNS_UPDATED";
@@ -1091,6 +1097,7 @@ internal static class CodeGenerationSupporter
10911097
internal const string Varp = "VARP";
10921098
internal const string VDevNo = "VDEVNO";
10931099
internal const string Vector = "Vector";
1100+
internal const string VectorSearch = "VECTOR_SEARCH";
10941101
internal const string Verbose = "VERBOSE";
10951102
internal const string VerboseLogging = "VerboseLogging";
10961103
internal const string VerifyOnly = "VERIFYONLY";

SqlScriptDom/Parser/TSql/TSql170.g

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19148,6 +19148,8 @@ selectTableReferenceElementWithoutJoinParenthesis[SubDmlFlags subDmlFlags] retur
1914819148
| vResult=subDmlTableReference[subDmlFlags]
1914919149
| {NextTokenMatches(CodeGenerationSupporter.Predict)}?
1915019150
vResult=predictTableReference[subDmlFlags]
19151+
| {NextTokenMatches(CodeGenerationSupporter.VectorSearch)}?
19152+
vResult=vectorSearchTableReference
1915119153
| vResult=schemaObjectOrFunctionTableReference
1915219154
;
1915319155

@@ -19243,6 +19245,47 @@ aiGenerateFixedChunksTableReference [ScalarExpression vSource, Identifier vChunk
1924319245
)?
1924419246
;
1924519247

19248+
vectorSearchTableReference returns [VectorSearchTableReference vResult = FragmentFactory.CreateFragment<VectorSearchTableReference>()]
19249+
{
19250+
TableReferenceWithAlias vTable;
19251+
ColumnReferenceExpression vColumn;
19252+
ScalarExpression vSimilarTo;
19253+
StringLiteral vMetric;
19254+
IntegerLiteral vTopN;
19255+
}
19256+
:
19257+
tVectorSearch:Identifier LeftParenthesis
19258+
{
19259+
Match(tVectorSearch, CodeGenerationSupporter.VectorSearch);
19260+
UpdateTokenInfo(vResult, tVectorSearch);
19261+
}
19262+
Table EqualsSign vTable = mergeTarget[false]
19263+
{
19264+
vResult.Table = vTable;
19265+
}
19266+
Comma Column EqualsSign vColumn = fixedColumn
19267+
{
19268+
vResult.Column = vColumn;
19269+
}
19270+
Comma tSimilarTo:Identifier EqualsSign vSimilarTo = expression
19271+
{
19272+
Match(tSimilarTo, CodeGenerationSupporter.SimilarTo);
19273+
vResult.SimilarTo = vSimilarTo;
19274+
}
19275+
Comma tMetric:Identifier EqualsSign vMetric = stringLiteral
19276+
{
19277+
Match(tMetric, CodeGenerationSupporter.Metric);
19278+
MatchString(vMetric, CodeGenerationSupporter.Cosine, CodeGenerationSupporter.Dot, CodeGenerationSupporter.Euclidean);
19279+
vResult.Metric = vMetric;
19280+
}
19281+
Comma tTopN:Identifier EqualsSign vTopN = integer
19282+
{
19283+
Match(tTopN, CodeGenerationSupporter.TopN);
19284+
vResult.TopN = vTopN;
19285+
}
19286+
RightParenthesis simpleTableReferenceAliasOpt[vResult]
19287+
;
19288+
1924619289
predictTableReference[SubDmlFlags subDmlFlags] returns [PredictTableReference vResult]
1924719290
:
1924819291
{NextTokenMatches(CodeGenerationSupporter.Predict)}?
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//------------------------------------------------------------------------------
2+
// <copyright file="SqlScriptGeneratorVisitor.VectorSearchTableReference.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
//------------------------------------------------------------------------------
6+
7+
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
8+
{
9+
partial class SqlScriptGeneratorVisitor
10+
{
11+
/// <summary>
12+
/// Script generator visitor for VECTOR_SEARCH function: https://learn.microsoft.com/sql/t-sql/functions/vector-search-transact-sql
13+
/// Syntax:
14+
/// VECTOR_SEARCH(
15+
/// TABLE = object[AS source_table_alias],
16+
/// COLUMN = vector_column,
17+
/// SIMILAR_TO = query_vector,
18+
/// METRIC = { 'cosine' | 'dot' | 'euclidean' },
19+
/// TOP_N = k
20+
/// ) [AS result_table_alias]
21+
/// </summary>
22+
public override void ExplicitVisit(VectorSearchTableReference node)
23+
{
24+
AlignmentPoint start = new AlignmentPoint();
25+
MarkAndPushAlignmentPoint(start);
26+
27+
GenerateIdentifier(CodeGenerationSupporter.VectorSearch);
28+
GenerateSymbol(TSqlTokenType.LeftParenthesis);
29+
30+
NewLineAndIndent();
31+
GenerateNameEqualsValue(TSqlTokenType.Table, node.Table);
32+
GenerateSymbol(TSqlTokenType.Comma);
33+
34+
NewLineAndIndent();
35+
GenerateNameEqualsValue(TSqlTokenType.Column, node.Column);
36+
GenerateSymbol(TSqlTokenType.Comma);
37+
38+
NewLineAndIndent();
39+
GenerateNameEqualsValue(CodeGenerationSupporter.SimilarTo, node.SimilarTo);
40+
GenerateSymbol(TSqlTokenType.Comma);
41+
42+
NewLineAndIndent();
43+
GenerateNameEqualsValue(CodeGenerationSupporter.Metric, node.Metric);
44+
GenerateSymbol(TSqlTokenType.Comma);
45+
46+
NewLineAndIndent();
47+
GenerateNameEqualsValue(CodeGenerationSupporter.TopN, node.TopN);
48+
49+
NewLine();
50+
GenerateSymbol(TSqlTokenType.RightParenthesis);
51+
GenerateSpaceAndAlias(node.Alias);
52+
53+
PopAlignmentPoint();
54+
}
55+
}
56+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
DECLARE @qv AS VECTOR (1536) = AI_GENERATE_EMBEDDINGS(N'Pink Floyd music style' USE MODEL Ada2Embeddings);
2+
3+
SELECT t.id,
4+
s.distance,
5+
t.title
6+
FROM VECTOR_SEARCH(
7+
TABLE = [dbo].[wikipedia_articles_embeddings] AS t,
8+
COLUMN = [content_vector],
9+
SIMILAR_TO = @qv,
10+
METRIC = 'cosine',
11+
TOP_N = 10
12+
) AS s
13+
ORDER BY s.distance;
14+
15+
SELECT *
16+
FROM VECTOR_SEARCH(
17+
TABLE = wikipedia_articles_embeddings,
18+
COLUMN = dbo.wikipedia_articles_embeddings.content_vector,
19+
SIMILAR_TO = @qv,
20+
METRIC = 'dot',
21+
TOP_N = 10
22+
)
23+
ORDER BY distance;

Test/SqlDom/Only170SyntaxTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public partial class SqlDomTests
2121
new ParserTest170("CreateExternalModelStatementTests170.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 4, nErrors140: 4, nErrors150: 4, nErrors160: 4),
2222
new ParserTest170("AlterExternalModelStatementTests170.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 5, nErrors140: 5, nErrors150: 5, nErrors160: 5),
2323
new ParserTest170("DropExternalModelStatementTests170.sql", nErrors80: 1, nErrors90: 1, nErrors100: 1, nErrors110: 1, nErrors120: 1, nErrors130: 1, nErrors140: 1, nErrors150: 1, nErrors160: 1),
24+
new ParserTest170("VectorFunctionTests170.sql", nErrors80: 1, nErrors90: 1, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 2, nErrors140: 2, nErrors150: 2, nErrors160: 2),
2425
};
2526

2627
private static readonly ParserTest[] SqlAzure170_TestInfos =

Test/SqlDom/ParserErrorsTests.cs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7357,5 +7357,131 @@ public void DropExternalModelNegativeTest()
73577357
"DROP EXTERNAL MODEL abc WITH (LOCATION = 'www.somemodellocation.235');",
73587358
new ParserErrorInfo(29, "SQL46010", "("));
73597359
}
7360+
7361+
[TestMethod]
7362+
[Priority(0)]
7363+
[SqlStudioTestCategory(Category.UnitTest)]
7364+
public void VectorSearchErrorTest170()
7365+
{
7366+
// Missing required parameters: TABLE
7367+
ParserTestUtils.ErrorTest170(
7368+
"SELECT * FROM VECTOR_SEARCH()",
7369+
new ParserErrorInfo(28, "SQL46010", ")"));
7370+
7371+
// Missing required parameters: COLUMN
7372+
ParserTestUtils.ErrorTest170(
7373+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1)",
7374+
new ParserErrorInfo(40, "SQL46010", ")"));
7375+
7376+
// Missing required parameters: SIMILAR_TO
7377+
ParserTestUtils.ErrorTest170(
7378+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1)",
7379+
new ParserErrorInfo(55, "SQL46010", ")"));
7380+
7381+
// Missing required parameters: METRIC
7382+
ParserTestUtils.ErrorTest170(
7383+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector)",
7384+
new ParserErrorInfo(82, "SQL46010", ")"));
7385+
7386+
// Missing required parameters: TOP_N
7387+
ParserTestUtils.ErrorTest170(
7388+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot')",
7389+
new ParserErrorInfo(98, "SQL46010", ")"));
7390+
7391+
// Invalid order: COLUMN before TABLE
7392+
ParserTestUtils.ErrorTest170(
7393+
"SELECT * FROM VECTOR_SEARCH(COLUMN = col1, TABLE = tbl1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7394+
new ParserErrorInfo(28, "SQL46010", "COLUMN"));
7395+
7396+
// Invalid order: SIMILAR_TO before COLUMN
7397+
ParserTestUtils.ErrorTest170(
7398+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, SIMILAR_TO = query_vector, COLUMN = col1, METRIC = 'dot', TOP_N = 5)",
7399+
new ParserErrorInfo(42, "SQL46010", "SIMILAR_TO"));
7400+
7401+
// Invalid order: METRIC before SIMILAR_TO
7402+
ParserTestUtils.ErrorTest170(
7403+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, METRIC = 'dot', SIMILAR_TO = query_vector, TOP_N = 5)",
7404+
new ParserErrorInfo(57, "SQL46005", "SIMILAR_TO", "METRIC"));
7405+
7406+
// Invalid value: TABLE = 'tbl1' (should be identifier, not string)
7407+
ParserTestUtils.ErrorTest170(
7408+
"SELECT * FROM VECTOR_SEARCH(TABLE = 'tbl1', COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7409+
new ParserErrorInfo(36, "SQL46010", "'tbl1'"));
7410+
7411+
// Invalid value: TABLE = 123 (should be identifier, not integer)
7412+
ParserTestUtils.ErrorTest170(
7413+
"SELECT * FROM VECTOR_SEARCH(TABLE = 123, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7414+
new ParserErrorInfo(36, "SQL46010", "123"));
7415+
7416+
// Invalid value: COLUMN = 'col1' (should be identifier, not string)
7417+
ParserTestUtils.ErrorTest170(
7418+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = 'col1', SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7419+
new ParserErrorInfo(51, "SQL46010", "'col1'"));
7420+
7421+
// Invalid value: COLUMN = 123 (should be identifier, not integer)
7422+
ParserTestUtils.ErrorTest170(
7423+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = 123, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7424+
new ParserErrorInfo(51, "SQL46010", "123"));
7425+
7426+
// Invalid value: METRIC = dot (should be string literal)
7427+
ParserTestUtils.ErrorTest170(
7428+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = dot, TOP_N = 5)",
7429+
new ParserErrorInfo(93, "SQL46010", "dot"));
7430+
7431+
// Invalid value: METRIC = 'invalid_value' (should be either 'cosine', 'dot', or 'euclidean')
7432+
ParserTestUtils.ErrorTest170(
7433+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'invalid_value', TOP_N = 5)",
7434+
new ParserErrorInfo(93, "SQL46010", "'invalid_value'"));
7435+
7436+
// Invalid value: TOP_N = '5' (should be integer, not string)
7437+
ParserTestUtils.ErrorTest170(
7438+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = '5')",
7439+
new ParserErrorInfo(108, "SQL46010", "'5'"));
7440+
7441+
// Invalid value: TOP_N = -5 (should be positive integer)
7442+
ParserTestUtils.ErrorTest170(
7443+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = -5)",
7444+
new ParserErrorInfo(108, "SQL46010", "-"));
7445+
7446+
// Missing value after equals for TABLE
7447+
ParserTestUtils.ErrorTest170(
7448+
"SELECT * FROM VECTOR_SEARCH(TABLE = , COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7449+
new ParserErrorInfo(36, "SQL46010", ","));
7450+
7451+
// Missing value after equals for COLUMN
7452+
ParserTestUtils.ErrorTest170(
7453+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = , SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5)",
7454+
new ParserErrorInfo(51, "SQL46010", ","));
7455+
7456+
// Missing value after equals for SIMILAR_TO
7457+
ParserTestUtils.ErrorTest170(
7458+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = , METRIC = 'dot', TOP_N = 5)",
7459+
new ParserErrorInfo(70, "SQL46010", ","));
7460+
7461+
// Missing value after equals for METRIC
7462+
ParserTestUtils.ErrorTest170(
7463+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = , TOP_N = 5)",
7464+
new ParserErrorInfo(93, "SQL46010", ","));
7465+
7466+
// Missing value after equals for TOP_N
7467+
ParserTestUtils.ErrorTest170(
7468+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = )",
7469+
new ParserErrorInfo(108, "SQL46010", ")"));
7470+
7471+
// Extra parameter
7472+
ParserTestUtils.ErrorTest170(
7473+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5, EXTRA_PARAM = 'value')",
7474+
new ParserErrorInfo(109, "SQL46010", ","));
7475+
7476+
// Extra comma at end
7477+
ParserTestUtils.ErrorTest170(
7478+
"SELECT * FROM VECTOR_SEARCH(TABLE = tbl1, COLUMN = col1, SIMILAR_TO = query_vector, METRIC = 'dot', TOP_N = 5,)",
7479+
new ParserErrorInfo(109, "SQL46010", ","));
7480+
7481+
// Function call with constant input, not keyword params
7482+
ParserTestUtils.ErrorTest170(
7483+
"SELECT * FROM VECTOR_SEARCH('tbl1', 'col1', 'query_vector', 'dot', 5)",
7484+
new ParserErrorInfo(28, "SQL46010", "'tbl1'"));
7485+
}
73607486
}
73617487
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
DECLARE @qv VECTOR(1536) = AI_GENERATE_EMBEDDINGS(N'Pink Floyd music style' USE MODEL Ada2Embeddings);
2+
3+
SELECT
4+
t.id, s.distance, t.title
5+
FROM
6+
VECTOR_SEARCH(
7+
TABLE = [dbo].[wikipedia_articles_embeddings] as t,
8+
COLUMN = [content_vector],
9+
SIMILAR_TO = @qv,
10+
METRIC = 'cosine',
11+
TOP_N = 10
12+
) AS s
13+
ORDER BY s.distance
14+
15+
SELECT
16+
*
17+
FROM
18+
VECTOR_SEARCH(
19+
TABLE = wikipedia_articles_embeddings,
20+
COLUMN = dbo.wikipedia_articles_embeddings.content_vector,
21+
SIMILAR_TO = @qv,
22+
METRIC = 'dot',
23+
TOP_N = 10
24+
)
25+
ORDER BY distance

0 commit comments

Comments
 (0)