chore: import upstream snapshot with attribution
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:21:23 +08:00
commit b957a53def
5423 changed files with 863745 additions and 0 deletions
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
using VectorData.ConformanceTests.Support;
namespace SqliteVec.ConformanceTests.Support;
public class SqliteFixture : VectorStoreFixture
{
public override TestStore TestStore => SqliteTestStore.Instance;
}
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Data.Sqlite;
namespace SqliteVec.ConformanceTests.Support;
internal static class SqliteTestEnvironment
{
private static readonly Lazy<bool> s_canUseSqlite = new(CanCreateConnectionAndLoadExtension);
internal static bool CanUseSqlite => s_canUseSqlite.Value;
private static bool CanCreateConnectionAndLoadExtension()
{
try
{
using var connection = new SqliteConnection("Data Source=:memory:;");
connection.Open();
connection.LoadVector();
}
catch (TypeInitializationException ex)
{
Console.WriteLine("Failed to load sqlite native dependency: " + ex.Message);
return false;
}
catch (SqliteException ex)
{
Console.WriteLine("Failed to load sqlite_vec extension: " + ex.Message);
return false;
}
return true;
}
}
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.SemanticKernel.Connectors.SqliteVec;
using VectorData.ConformanceTests.Support;
namespace SqliteVec.ConformanceTests.Support;
internal sealed class SqliteTestStore : TestStore
{
private string? _databasePath;
private string? _connectionString;
public string ConnectionString => this._connectionString ?? throw new InvalidOperationException("Not initialized");
public static SqliteTestStore Instance { get; } = new();
public override string DefaultDistanceFunction => Microsoft.Extensions.VectorData.DistanceFunction.CosineDistance;
public SqliteVectorStore GetVectorStore(SqliteVectorStoreOptions options)
=> new(this.ConnectionString, options);
private SqliteTestStore()
{
}
protected override Task StartAsync()
{
this._databasePath = Path.GetTempFileName();
this._connectionString = $"Data Source={this._databasePath};Pooling=false";
this.DefaultVectorStore = new SqliteVectorStore(this._connectionString);
return Task.CompletedTask;
}
protected override Task StopAsync()
{
File.Delete(this._databasePath!);
this._databasePath = null;
return Task.CompletedTask;
}
}
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft. All rights reserved.
using VectorData.ConformanceTests.Xunit;
namespace SqliteVec.ConformanceTests.Support;
/// <summary>
/// Checks whether the sqlite_vec extension is properly installed, and skips the test(s) otherwise.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
public sealed class SqliteVecRequiredAttribute : Attribute, ITestCondition
{
public ValueTask<bool> IsMetAsync() => new(SqliteTestEnvironment.CanUseSqlite);
public string Skip { get; set; } = "Some native Sqlite dependencies are missing.";
public string SkipReason
=> this.Skip;
}