Skip to content

Support vector datatype with SqlVector<T> #3443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ No conversions are performed; therefore. the data retrieved must already be a ch
<item><description>SqlMoney</description></item>
<item><description>SqlSingle</description></item>
<item><description>SqlString</description></item>
<item><description>SqlVectorFloat32</description></item>
<item><description>SqlVector</description></item>
<item><description>Stream</description></item>
<item><description>String</description></item>
<item><description>TextReader</description></item>
Expand Down Expand Up @@ -490,7 +490,7 @@ No conversions are performed; therefore. the data retrieved must already be a ch
<item><description>SqlMoney</description></item>
<item><description>SqlSingle</description></item>
<item><description>SqlString</description></item>
<item><description>SqlVectorFloat32</description></item>
<item><description>SqlVector</description></item>
<item><description>Stream</description></item>
<item><description>String</description></item>
<item><description>TextReader</description></item>
Expand Down Expand Up @@ -964,13 +964,13 @@ The <xref:Microsoft.Data.SqlClient.SqlDataReader.GetSchemaTable%2A> method retur
No conversions are performed; therefore, the data retrieved must already be a JSON string, or an exception is generated.
</remarks>
</GetSqlJson>
<GetSqlVectorFloat32>
<GetSqlVector>
<param name="i"></param>
<summary>
Gets the value of the specified column as a <see cref="T:Microsoft.Data.SqlTypes.SqlVectorFloat32"/>.
Gets the value of the specified column as a <see cref="T:Microsoft.Data.SqlTypes.SqlVector"/>.
</summary>
<returns>
A <see cref="T:Microsoft.Data.SqlTypes.SqlVectorFloat32"/> object representing the column at the given ordinal.
A <see cref="T:Microsoft.Data.SqlTypes.SqlVector"/> object representing the column at the given ordinal.
</returns>
<exception cref="T:System.ArgumentOutOfRangeException">
The index passed was outside the range of 0 to <see cref="P:System.Data.DataTableReader.FieldCount" /> - 1
Expand All @@ -979,12 +979,12 @@ The <xref:Microsoft.Data.SqlClient.SqlDataReader.GetSchemaTable%2A> method retur
An attempt was made to read or access columns in a closed <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" />.
</exception>
<exception cref="T:System.InvalidCastException">
The retrieved data is not compatible with the <see cref="T:Microsoft.Data.SqlTypes.SqlVectorFloat32" /> type.
The retrieved data is not compatible with the <see cref="T:Microsoft.Data.SqlTypes.SqlVector" /> type.
</exception>
<remarks>
No conversions are performed; therefore, the data retrieved must already be a vector value, or an exception is generated.
</remarks>
</GetSqlVectorFloat32>
</GetSqlVector>
<GetSqlMoney>
<param name="i">
The zero-based column ordinal.
Expand Down
49 changes: 49 additions & 0 deletions doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<docs>
<members name="SqlVector">
<SqlVector>
<summary>Represents a vector value in SQL Server.</summary>
</SqlVector>
<ctor1>
<param name="length"></param>
<summary>
Constructs a null vector of the given length. SQL Server requires vector arguments to specify their length even when null.
</summary>
<exception cref="T:System.ArgumentOutOfRangeException">
Vector length must be non-negative.
</exception>
</ctor1>
<ctor2>
<param name="memory"></param>
<summary>
Constructs a vector with the given values.
</summary>
</ctor2>
<IsNull>
<inheritdoc/>
</IsNull>
<Null>
<summary>
Represents a null instance without any attributes.
</summary>
<remarks>
This property is provided for compatibility with DataTable.
In most cases, prefer using <c>IsNull</c> to check if a SqlVector instance is a null vector.
This is equivalent to <c>null</c> value.
</remarks>
</Null>
<Length>
<summary>
Returns the number of elements in the vector.
</summary>
</Length>
<Size>
<summary>
Returns the number of bytes required to represent this vector when communicating with SQL Server.
</summary>
</Size>
<Memory>
<summary>Returns the vector values as a memory region. No copies are made.</summary>
</Memory>
</members>
</docs>
56 changes: 0 additions & 56 deletions doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/Microsoft.Data.SqlClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.Data.SqlTypes", "
ProjectSection(SolutionItems) = preProject
..\doc\snippets\Microsoft.Data.SqlTypes\SqlFileStream.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlFileStream.xml
..\doc\snippets\Microsoft.Data.SqlTypes\SqlJson.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlJson.xml
..\doc\snippets\Microsoft.Data.SqlTypes\SqlVectorFloat32.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlVectorFloat32.xml
..\doc\snippets\Microsoft.Data.SqlTypes\SqlVector.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlVector.xml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.TestUtilities", "Microsoft.Data.SqlClient\tests\tools\Microsoft.Data.SqlClient.TestUtilities\Microsoft.Data.SqlClient.TestUtilities.csproj", "{89D6D382-9B36-43C9-A912-03802FDA8E36}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,24 @@ public SqlJson(System.Text.Json.JsonDocument jsonDoc) { }
public override string ToString() { throw null; }
}

/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/SqlVectorFloat32/*' />
public sealed class SqlVectorFloat32 : System.Data.SqlTypes.INullable
{
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor1/*' />
public SqlVectorFloat32(int length) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor2/*' />
public SqlVectorFloat32(System.ReadOnlyMemory<float> values) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/IsNull/*' />
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/SqlVector/*' />
public sealed class SqlVector<T> : System.Data.SqlTypes.INullable
where T : unmanaged
{
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor1/*' />
public SqlVector(int length) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor2/*' />
public SqlVector(System.ReadOnlyMemory<T> memory) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/IsNull/*' />
public bool IsNull => throw null;
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Null/*' />
public static SqlVectorFloat32 Null => throw null;
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Length/*' />
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Null/*' />
public static SqlVector<T> Null => throw null;
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Length/*' />
public int Length { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Size/*' />
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Size/*' />
public int Size { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Values/*' />
public System.ReadOnlyMemory<float> Values { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToString/*' />
public override string ToString() { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToArray/*' />
public float[] ToArray() { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Memory/*' />
public System.ReadOnlyMemory<T> Memory { get { throw null; } }
}
}
namespace Microsoft.Data.SqlClient
Expand Down Expand Up @@ -1395,8 +1392,8 @@ public override void Close() { }
public virtual object GetSqlValue(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlValues/*'/>
public virtual int GetSqlValues(object[] values) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVectorFloat32/*'/>
public virtual Microsoft.Data.SqlTypes.SqlVectorFloat32 GetSqlVectorFloat32(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVector/*'/>
public virtual Microsoft.Data.SqlTypes.SqlVector<T> GetSqlVector<T>(int i) where T : unmanaged { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlXml/*'/>
public virtual System.Data.SqlTypes.SqlXml GetSqlXml(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSchemaTable/*'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlJson.cs">
<Link>Microsoft\Data\SqlTypes\SqlJson.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVectorFloat32.cs">
<Link>Microsoft\Data\SqlTypes\SqlVectorFloat32.cs</Link>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVector.cs">
<Link>Microsoft\Data\SqlTypes\SqlVector.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Resources\ResCategoryAttribute.cs">
<Link>Resources\ResCategoryAttribute.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,8 +1370,8 @@ public override void Close() { }
public virtual object GetSqlValue(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlValues/*'/>
public virtual int GetSqlValues(object[] values) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVectorFloat32/*'/>
public virtual Microsoft.Data.SqlTypes.SqlVectorFloat32 GetSqlVectorFloat32(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVector/*'/>
public virtual Microsoft.Data.SqlTypes.SqlVector<T> GetSqlVector<T>(int i) where T : unmanaged { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlXml/*'/>
public virtual System.Data.SqlTypes.SqlXml GetSqlXml(int i) { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSchemaTable/*'/>
Expand Down Expand Up @@ -2416,26 +2416,23 @@ public SqlJson(System.Text.Json.JsonDocument jsonDoc) { }
public override string ToString() { throw null; }
}

/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/SqlVectorFloat32/*' />
public sealed class SqlVectorFloat32 : System.Data.SqlTypes.INullable
{
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor1/*' />
public SqlVectorFloat32(int length) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor2/*' />
public SqlVectorFloat32(System.ReadOnlyMemory<float> values) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/IsNull/*' />
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/SqlVector/*' />
public sealed class SqlVector<T> : System.Data.SqlTypes.INullable
where T : unmanaged
{
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor1/*' />
public SqlVector(int length) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor2/*' />
public SqlVector(System.ReadOnlyMemory<T> memory) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/IsNull/*' />
public bool IsNull => throw null;
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Null/*' />
public static SqlVectorFloat32 Null => throw null;
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Length/*' />
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Null/*' />
public static SqlVector<T> Null => throw null;
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Length/*' />
public int Length { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Size/*' />
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Size/*' />
public int Size { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Values/*' />
public System.ReadOnlyMemory<float> Values { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToString/*' />
public override string ToString() { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToArray/*' />
public float[] ToArray() { throw null; }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Memory/*' />
public System.ReadOnlyMemory<T> Memory { get { throw null; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SqlSer.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlSer.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\IsqlVector.cs">
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ISqlVector.cs">
<Link>Microsoft\Data\SqlClient\ISqlVector.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SessionHandle.Windows.cs">
Expand Down Expand Up @@ -909,8 +909,8 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlJson.cs">
<Link>Microsoft\Data\SqlTypes\SqlJson.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVectorFloat32.cs">
<Link>Microsoft\Data\SqlTypes\SqlVectorFloat32.cs</Link>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVector.cs">
<Link>Microsoft\Data\SqlTypes\SqlVector.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Resources\ResDescriptionAttribute.cs">
<Link>Resources\ResDescriptionAttribute.cs</Link>
Expand All @@ -921,7 +921,10 @@
<Compile Include="$(CommonSourceRoot)System\IO\StreamExtensions.netfx.cs">
<Link>System\IO\StreamExtensions.netfx.cs</Link>
</Compile>

<Compile Include="$(CommonSourceRoot)System\Runtime\CompilerServices\IsExternalInit.netfx.cs">
<Link>System\Runtime\CompilerServices\IsExternalInit.netfx.cs</Link>
</Compile>

<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnection.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionHelper.cs" />
Expand Down
Loading
Loading