Skip to content

Commit 8893956

Browse files
committed
Drop in Microsoft.SqlServer.VectorData
Moved from Semantic Kernel
1 parent ac266b9 commit 8893956

51 files changed

Lines changed: 5841 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,6 @@ MigrationBackup/
353353
src/Microsoft.Build.Sql/[Tt]ools/
354354

355355
## Ignore packages generated for testing
356-
test/Microsoft.Build.Sql.Tests/pkg/
356+
test/Microsoft.Build.Sql.Tests/pkg/
357+
358+
*.lscache

Directory.Packages.props

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.11.48" />
1414
<PackageVersion Include="Microsoft.SqlServer.DacFx" Version="$(DacFxPackageVersion)" />
1515
<PackageVersion Include="Microsoft.Data.SqlClient" Version="$(SqlClientPackageVersion)" />
16+
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="10.5.0" />
17+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.7" />
18+
<PackageVersion Include="Microsoft.Extensions.VectorData.Abstractions" Version="10.5.0" />
1619
<PackageVersion Include="Microsoft.SqlServer.Server" Version="1.0.0" />
1720
<PackageVersion Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="$(ScriptDomPackageVersion)" />
1821
<PackageVersion Include="Microsoft.SqlServer.Types" Version="170.1000.7" />
@@ -23,11 +26,19 @@
2326
<!-- Test -->
2427
<PackageVersion Include="Microsoft.Build" Version="17.11.48" />
2528
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="17.11.48" />
26-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
29+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.7" />
30+
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.7" />
31+
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.7" />
32+
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.7" />
33+
<PackageVersion Include="Microsoft.Extensions.VectorData.ConformanceTests" Version="10.5.0" />
34+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
2735
<PackageVersion Include="Moq" Version="4.20.70" />
2836
<PackageVersion Include="NuGet.Packaging" Version="6.13.2" />
2937
<PackageVersion Include="nunit" Version="3.13.2" />
3038
<PackageVersion Include="NUnit3TestAdapter" Version="4.0.0" />
3139
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
40+
<PackageVersion Include="Testcontainers.MsSql" Version="4.11.0" />
41+
<PackageVersion Include="xunit" Version="2.9.3" />
42+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
3243
</ItemGroup>
3344
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#pragma warning disable IDE0079
5+
#pragma warning disable SA1101
6+
#pragma warning disable SA1512
7+
8+
using System.Diagnostics.CodeAnalysis;
9+
10+
namespace System.Runtime.CompilerServices;
11+
12+
/// <summary>
13+
/// Tags parameter that should be filled with specific caller name.
14+
/// </summary>
15+
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
16+
[ExcludeFromCodeCoverage]
17+
internal sealed class CallerArgumentExpressionAttribute : Attribute
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="CallerArgumentExpressionAttribute"/> class.
21+
/// </summary>
22+
/// <param name="parameterName">Function parameter to take the name from.</param>
23+
public CallerArgumentExpressionAttribute(string parameterName)
24+
{
25+
ParameterName = parameterName;
26+
}
27+
28+
/// <summary>
29+
/// Gets name of the function parameter that name should be taken from.
30+
/// </summary>
31+
public string ParameterName { get; }
32+
}

src/LegacySupport/Index.cs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Runtime.CompilerServices;
6+
7+
#pragma warning disable CS0436 // Type conflicts with imported type
8+
#pragma warning disable S3427 // Method overloads with default parameter values should not overlap
9+
#pragma warning disable SA1642 // Constructor summary documentation should begin with standard text
10+
#pragma warning disable IDE0011 // Add braces
11+
#pragma warning disable SA1623 // Property summary documentation should match accessors
12+
#pragma warning disable IDE0023 // Use block body for conversion operator
13+
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
14+
#pragma warning disable LA0001 // Use the 'Microsoft.Shared.Diagnostics.Throws' class instead of explicitly throwing exception for improved performance
15+
#pragma warning disable CA1305 // Specify IFormatProvider
16+
17+
namespace System
18+
{
19+
internal readonly struct Index : IEquatable<Index>
20+
{
21+
private readonly int _value;
22+
23+
/// <summary>Construct an Index using a value and indicating if the index is from the start or from the end.</summary>
24+
/// <param name="value">The index value. it has to be zero or positive number.</param>
25+
/// <param name="fromEnd">Indicating if the index is from the start or from the end.</param>
26+
/// <remarks>
27+
/// If the Index constructed from the end, index value 1 means pointing at the last element and index value 0 means pointing at beyond last element.
28+
/// </remarks>
29+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
30+
public Index(int value, bool fromEnd = false)
31+
{
32+
if (value < 0)
33+
{
34+
ThrowValueArgumentOutOfRange_NeedNonNegNumException();
35+
}
36+
37+
if (fromEnd)
38+
_value = ~value;
39+
else
40+
_value = value;
41+
}
42+
43+
// The following private constructors mainly created for perf reason to avoid the checks
44+
private Index(int value)
45+
{
46+
_value = value;
47+
}
48+
49+
/// <summary>Create an Index pointing at first element.</summary>
50+
public static Index Start => new Index(0);
51+
52+
/// <summary>Create an Index pointing at beyond last element.</summary>
53+
public static Index End => new Index(~0);
54+
55+
/// <summary>Create an Index from the start at the position indicated by the value.</summary>
56+
/// <param name="value">The index value from the start.</param>
57+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
58+
public static Index FromStart(int value)
59+
{
60+
if (value < 0)
61+
{
62+
ThrowValueArgumentOutOfRange_NeedNonNegNumException();
63+
}
64+
65+
return new Index(value);
66+
}
67+
68+
/// <summary>Create an Index from the end at the position indicated by the value.</summary>
69+
/// <param name="value">The index value from the end.</param>
70+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
71+
public static Index FromEnd(int value)
72+
{
73+
if (value < 0)
74+
{
75+
ThrowValueArgumentOutOfRange_NeedNonNegNumException();
76+
}
77+
78+
return new Index(~value);
79+
}
80+
81+
/// <summary>Returns the index value.</summary>
82+
public int Value
83+
{
84+
get
85+
{
86+
if (_value < 0)
87+
return ~_value;
88+
else
89+
return _value;
90+
}
91+
}
92+
93+
/// <summary>Indicates whether the index is from the start or the end.</summary>
94+
public bool IsFromEnd => _value < 0;
95+
96+
/// <summary>Calculate the offset from the start using the giving collection length.</summary>
97+
/// <param name="length">The length of the collection that the Index will be used with. length has to be a positive value.</param>
98+
/// <remarks>
99+
/// For performance reason, we don't validate the input length parameter and the returned offset value against negative values.
100+
/// we don't validate either the returned offset is greater than the input length.
101+
/// It is expected Index will be used with collections which always have non negative length/count. If the returned offset is negative and
102+
/// then used to index a collection will get out of range exception which will be same affect as the validation.
103+
/// </remarks>
104+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
105+
public int GetOffset(int length)
106+
{
107+
int offset = _value;
108+
if (IsFromEnd)
109+
{
110+
// offset = length - (~value)
111+
// offset = length + (~(~value) + 1)
112+
// offset = length + value + 1
113+
114+
offset += length + 1;
115+
}
116+
117+
return offset;
118+
}
119+
120+
/// <summary>Indicates whether the current Index object is equal to another object of the same type.</summary>
121+
/// <param name="value">An object to compare with this object.</param>
122+
public override bool Equals([NotNullWhen(true)] object? value) => value is Index && _value == ((Index)value)._value;
123+
124+
/// <summary>Indicates whether the current Index object is equal to another Index object.</summary>
125+
/// <param name="other">An object to compare with this object.</param>
126+
public bool Equals(Index other) => _value == other._value;
127+
128+
/// <summary>Returns the hash code for this instance.</summary>
129+
public override int GetHashCode() => _value;
130+
131+
/// <summary>Converts integer number to an Index.</summary>
132+
public static implicit operator Index(int value) => FromStart(value);
133+
134+
/// <summary>Converts the value of the current Index object to its equivalent string representation.</summary>
135+
public override string ToString()
136+
{
137+
if (IsFromEnd)
138+
return ToStringFromEnd();
139+
140+
return ((uint)Value).ToString();
141+
}
142+
143+
private static void ThrowValueArgumentOutOfRange_NeedNonNegNumException()
144+
{
145+
throw new ArgumentOutOfRangeException("value", "value must be non-negative");
146+
}
147+
148+
private string ToStringFromEnd()
149+
{
150+
#if (!NETSTANDARD2_0 && !NETFRAMEWORK)
151+
Span<char> span = stackalloc char[11]; // 1 for ^ and 10 for longest possible uint value
152+
bool formatted = ((uint)Value).TryFormat(span.Slice(1), out int charsWritten);
153+
span[0] = '^';
154+
return new string(span.Slice(0, charsWritten + 1));
155+
#else
156+
return '^' + Value.ToString();
157+
#endif
158+
}
159+
}
160+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#pragma warning disable IDE0079
5+
#pragma warning disable S3903
6+
7+
/* This enables support for C# 9/10 records on older frameworks */
8+
9+
namespace System.Runtime.CompilerServices;
10+
11+
internal static class IsExternalInit
12+
{
13+
}

0 commit comments

Comments
 (0)