Skip to content
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
2 changes: 0 additions & 2 deletions MEVD/src/SqliteVec/SqliteFilterTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,12 @@ private void TranslateConstant(object? value)
case DateTimeOffset dateTimeOffset:
_sql.Append('\'').Append(dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFFzzz", System.Globalization.CultureInfo.InvariantCulture)).Append('\'');
return;
#if NET
case DateOnly dateOnly:
_sql.Append('\'').Append(dateOnly.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)).Append('\'');
return;
case TimeOnly timeOnly:
_sql.Append('\'').Append(timeOnly.ToString("HH:mm:ss.FFFFFFF", System.Globalization.CultureInfo.InvariantCulture)).Append('\'');
return;
#endif

case null:
_sql.Append("NULL");
Expand Down
9 changes: 1 addition & 8 deletions MEVD/src/SqliteVec/SqliteMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public TRecord MapFromStorageToDataModel(DbDataReader reader, bool includeVector
}

// SqliteVec provides the vector data as a byte[], which we need to convert to a float[].
// In modern .NET, we allocate a float[] of the right size, reinterpret-cast it into byte[],
// We allocate a float[] of the right size, reinterpret-cast it into byte[],
// and then read the data into that via Stream.
// In .NET Framework, which doesn't have Span APIs on Stream, we just create a copy (inefficient).
#if NET
using var stream = reader.GetStream(ordinal);

var length = stream.Length;
Expand All @@ -58,9 +56,6 @@ public TRecord MapFromStorageToDataModel(DbDataReader reader, bool includeVector
var floats = new float[length / 4];
var bytes = MemoryMarshal.Cast<float, byte>(floats.AsSpan());
stream.ReadExactly(bytes);
#else
var floats = MemoryMarshal.Cast<byte, float>((byte[])reader[ordinal]).ToArray();
#endif

property.SetValueAsObject(
record,
Expand Down Expand Up @@ -99,10 +94,8 @@ public TRecord MapFromStorageToDataModel(DbDataReader reader, bool includeVector
Type t when t == typeof(Guid) => reader.GetGuid(ordinal),
Type t when t == typeof(DateTime) => reader.GetDateTime(ordinal),
Type t when t == typeof(DateTimeOffset) => reader.GetFieldValue<DateTimeOffset>(ordinal),
#if NET
Type t when t == typeof(DateOnly) => reader.GetFieldValue<DateOnly>(ordinal),
Type t when t == typeof(TimeOnly) => reader.GetFieldValue<TimeOnly>(ordinal),
#endif
Type t when t == typeof(byte[]) => (byte[])reader[ordinal],
Type t when t == typeof(ReadOnlyMemory<float>) => (byte[])reader[ordinal],
Type t when t == typeof(Embedding<float>) => (byte[])reader[ordinal],
Expand Down
8 changes: 1 addition & 7 deletions MEVD/src/SqliteVec/SqliteModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)

protected override bool IsDataPropertyTypeValid(Type type, [NotNullWhen(false)] out string? supportedTypes)
{
supportedTypes = "int, long, short, string, bool, float, double, byte[], Guid, DateTime, DateTimeOffset"
#if NET
+ ", DateOnly, TimeOnly"
#endif
;
supportedTypes = "int, long, short, string, bool, float, double, byte[], Guid, DateTime, DateTimeOffset, DateOnly, TimeOnly";

if (Nullable.GetUnderlyingType(type) is Type underlyingType)
{
Expand All @@ -56,10 +52,8 @@ protected override bool IsDataPropertyTypeValid(Type type, [NotNullWhen(false)]
|| type == typeof(Guid)
|| type == typeof(DateTime)
|| type == typeof(DateTimeOffset)
#if NET
|| type == typeof(DateOnly)
|| type == typeof(TimeOnly)
#endif
;
}

Expand Down
2 changes: 0 additions & 2 deletions MEVD/src/SqliteVec/SqlitePropertyMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ private static string GetStorageDataPropertyType(PropertyModel property)
// Date/time types - represent as TEXT (ISO 8601)
Type t when t == typeof(DateTime) || t == typeof(DateTime?) => "TEXT",
Type t when t == typeof(DateTimeOffset) || t == typeof(DateTimeOffset?) => "TEXT",
#if NET
Type t when t == typeof(DateOnly) || t == typeof(DateOnly?) => "TEXT",
Type t when t == typeof(TimeOnly) || t == typeof(TimeOnly?) => "TEXT",
#endif

// Byte array (BLOB)
Type t when t == typeof(byte[]) => "BLOB",
Expand Down
4 changes: 2 additions & 2 deletions MEVD/src/SqliteVec/SqliteVec.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.2-preview</Version>
<Version>1.0.3-preview</Version>
<AssemblyName>CommunityToolkit.VectorData.SqliteVec</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFrameworks>net10.0;net8.0;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>

<Title>SQLite provider for Microsoft.Extensions.VectorData</Title>
Expand Down
8 changes: 0 additions & 8 deletions MEVD/src/SqliteVec/SqliteVectorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public SqliteVectorStore(string connectionString, SqliteVectorStoreOptions? opti
/// <inheritdoc />
[RequiresDynamicCode("This overload of GetCollection() is incompatible with NativeAOT. For dynamic mapping via Dictionary<string, object?>, call GetDynamicCollection() instead.")]
[RequiresUnreferencedCode("This overload of GetCollecttion() is incompatible with trimming. For dynamic mapping via Dictionary<string, object?>, call GetDynamicCollection() instead.")]
#if NET
public override SqliteCollection<TKey, TRecord> GetCollection<TKey, TRecord>(string name, VectorStoreCollectionDefinition? definition = null)
#else
public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord>(string name, VectorStoreCollectionDefinition? definition = null)
#endif
=> typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new ArgumentException(VectorDataStrings.GetCollectionWithDictionaryNotSupported)
: new SqliteCollection<TKey, TRecord>(
Expand All @@ -79,11 +75,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
});

/// <inheritdoc />
#if NET
public override SqliteDynamicCollection GetDynamicCollection(string name, VectorStoreCollectionDefinition definition)
#else
public override VectorStoreCollection<object, Dictionary<string, object?>> GetDynamicCollection(string name, VectorStoreCollectionDefinition definition)
#endif
=> new SqliteDynamicCollection(
_connectionString,
name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0;$(NetFrameworkTfm)</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsTestProject>true</IsTestProject>
Expand Down
Loading