Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 30, 2025

This PR adds comprehensive support for parsing and generating T-SQL VECTOR index statements in SqlScriptDOM with separate, dedicated classes for vector index options.

Syntax Support

The implementation supports the full vector index syntax specification:

CREATE VECTOR INDEX index_name
ON object ( vector_column )  
[ WITH (
    [,] METRIC = { 'COSINE' | 'DOT' | 'EUCLIDEAN' }
    [ [,] TYPE = 'DISKANN' ]
    [ [,] MAXDOP = max_degree_of_parallelism ]
) ]
[ ON { filegroup_name | "default" } ]

Architecture

Dedicated Index Option Classes:

  • VectorMetricIndexOption class handles METRIC options with MetricType property
  • VectorTypeIndexOption class handles TYPE options with VectorType property
  • Maintains separate IndexOptionKind.VectorMetric and IndexOptionKind.VectorType for clear distinction

Parser Support:

  • Added createVectorIndexStatement grammar rule following JSON index pattern
  • Separate vectorMetricOption and vectorTypeOption rules for each option type
  • Leverages existing infrastructure for robust index parsing

Script Generation:

  • Dedicated script generators for each option type support round-trip parsing and generation
  • Separate VectorMetricIndexOption and VectorTypeIndexOption visitors
  • Proper keyword generation for VECTOR, METRIC, TYPE, and metric values

Test Coverage:

  • Comprehensive test suite with 12 test cases covering all syntax variations
  • Tests include basic vector indexes, metric options, type options, MAXDOP, filegroups, and quoted identifiers
  • Error test cases cover common syntax errors and invalid option values

The implementation adds 315 lines of code with no deletions, following established patterns for maintainability and using separate classes for each vector index option type.

Fixes #149.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

… generators

Co-authored-by: llali <17187348+llali@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for Vector index Add support for Vector index syntax in T-SQL parser Jul 30, 2025
Copilot AI requested a review from llali July 30, 2025 17:48
Copilot finished work on behalf of llali July 30, 2025 17:48
internal const string Json = "JSON";
internal const string JsonArray = "JSON_ARRAY";
internal const string JsonObject = "JSON_OBJECT";
internal const string Vector = "VECTOR";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class already has a Vector filed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 97a1590. Removed the duplicate Vector constant at line 517, keeping the existing one at line 1073.

<Member Name="Expression" Type="ScalarExpression" Summary="Can be an integer in the range 0 - 10080."/>
<Member Name="TimeUnit" Type="CompressionDelayTimeUnit" GenerateUpdatePositionInfoCall="false" Summary="The optional unit of measure for the compression delay (it can be MINUTE or MINUTES)."/>
</Class>
<Class Name="VectorMetricIndexOption" Base="IndexOption" Summary="Represents the vector metric index option.">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create one VectorIndexOption class that includes both MetricType and VectorType

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 97a1590. Consolidated VectorMetricIndexOption and VectorTypeIndexOption into a single VectorIndexOption class that includes both MetricType and VectorType properties, along with updated grammar and script generator.

Co-authored-by: llali <17187348+llali@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr2.org
    • Triggering command: /usr/lib/dotnet/dotnet /usr/lib/dotnet/sdk/8.0.118/MSBuild.dll /nologo /nodemode:1 /nodeReuse:true /low:false (dns block)
    • Triggering command: /usr/lib/dotnet/dotnet /usr/lib/dotnet/sdk/8.0.118/MSBuild.dll /nologo /nodemode:1 /nodeReuse:false /low:false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add support for Vector index syntax in T-SQL parser Add support for Vector index syntax in T-SQL parser with consolidated index option architecture Jul 31, 2025
Copilot AI requested a review from llali July 31, 2025 00:05
Copilot finished work on behalf of llali July 31, 2025 00:05
<Member Name="Expression" Type="ScalarExpression" Summary="Can be an integer in the range 0 - 10080."/>
<Member Name="TimeUnit" Type="CompressionDelayTimeUnit" GenerateUpdatePositionInfoCall="false" Summary="The optional unit of measure for the compression delay (it can be MINUTE or MINUTES)."/>
</Class>
<Class Name="VectorIndexOption" Base="IndexOption" Summary="Represents the vector index option that includes both metric type and vector type.">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a mistake. you were right about creating two Index Options one for MetricType and one for VectorType. please revert back to your original change with two IndexOption types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to original design in 0c53470. The implementation now uses two separate classes:

  • VectorMetricIndexOption for METRIC options
  • VectorTypeIndexOption for TYPE options

All functionality is preserved while following the original architecture.

…ectorTypeIndexOption classes

Co-authored-by: llali <17187348+llali@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 1, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr2.org
    • Triggering command: dotnet build -v q --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add support for Vector index syntax in T-SQL parser with consolidated index option architecture Add support for Vector index syntax in T-SQL parser with separate index option classes Aug 1, 2025
Copilot AI requested a review from llali August 1, 2025 17:03
ON MySchema.MyTable (VectorColumn) WITH (METRIC = 'euclidean');

CREATE VECTOR INDEX [IX Vector Index]
ON [dbo].[Documents] ([Vector Data]) WITH (METRIC = 'cosine');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change option values like cosine dot to uppercase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated all vector index option values to uppercase in the baseline file. Changed 'cosine' → 'COSINE', 'dot' → 'DOT', 'euclidean' → 'EUCLIDEAN', and 'DiskANN' → 'DISKANN' as requested. Commit df44c72.

Co-authored-by: llali <17187348+llali@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 1, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr2.org
    • Triggering command: dotnet build -c Release --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from llali August 1, 2025 22:25
Copy link
Contributor

@zijchen zijchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some error test cases to ParserErrorsTests

Co-authored-by: zijchen <13544267+zijchen@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 1, 2025

Add some error test cases to ParserErrorsTests

Added comprehensive error test cases for vector index syntax in e0432d2. The new VectorIndexNegativeTests method includes 22 test cases covering common syntax errors such as missing keywords, invalid option values, duplicate options, empty values, and malformed WITH clauses.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr2.org
    • Triggering command: dotnet build -c Debug --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from zijchen August 1, 2025 22:57
public void VectorIndexNegativeTests()
{
// Missing VECTOR keyword
ParserTestUtils.ErrorTest170("CREATE INDEX IX_Test ON dbo.Documents (VectorData)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this valid syntax for normal index creation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the CI tests are failing because of this, you can just remove this test case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right! The statement CREATE INDEX IX_Test ON dbo.Documents (VectorData) is valid syntax for creating a regular index, not an error case. Removed this invalid test case in 849df29.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right! I've already removed that test case in commit 849df29. The CREATE INDEX IX_Test ON dbo.Documents (VectorData) statement is indeed valid syntax for creating a regular index and shouldn't be in the vector index error tests.

…tax is valid for regular indexes

Co-authored-by: zijchen <13544267+zijchen@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 4, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr2.org
    • Triggering command: dotnet build -v q --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@llali llali marked this pull request as ready for review August 4, 2025 21:03
@llali llali merged commit 4476447 into main Aug 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Vector index

3 participants