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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ protected override bool SupportsKeyAutoGeneration(Type keyPropertyType)

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(int) && type != typeof(long) && type != typeof(Guid) && type != typeof(ObjectId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public AzureAISearchCollection(SearchIndexClient searchIndexClient, string name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(AzureAISearchDynamicCollection)))
: new AzureAISearchModelBuilder()
.Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
.Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class AzureAISearchDynamicModelBuilder() : CollectionModelBuilder(s_mod

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(Guid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal class AzureAISearchModelBuilder() : CollectionJsonModelBuilder(s_modelB

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(Guid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public CosmosMongoCollection(
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(CosmosMongoDynamicCollection)))
: new MongoModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new MongoModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal CosmosNoSqlCollection(
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(CosmosNoSqlDynamicCollection)))
: new CosmosNoSqlModelBuilder()
.Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
.Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ internal class CosmosNoSqlModelBuilder() : CollectionJsonModelBuilder(s_modelBui

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
// CosmosNoSqlKey is a composite key type (document ID + partition key) that doesn't correspond to any single key property type;
// skip the base TKey-to-key-property validation when it's used.
if (this.KeyType != typeof(CosmosNoSqlKey))
{
base.ValidateKeyProperty(keyProperty);
}

// Note that the key property in Cosmos NoSQL refers to the document ID, not to the CosmosNoSqlKey structure which includes both
// the document ID and the partition key (and which is the generic TKey type parameter of the collection).
var type = keyProperty.Type;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/InMemory/InMemoryCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public InMemoryCollection(string name, InMemoryCollectionOptions? options = defa
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(InMemoryDynamicCollection)))
: new InMemoryModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new InMemoryModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/InMemory/InMemoryModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal class InMemoryModelBuilder() : CollectionModelBuilder(ValidationOptions

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

// All .NET types are supported by the InMemory provider, but we support auto-generation of keys only for GUIDs
if (keyProperty.IsAutoGenerated && keyProperty.Type != typeof(Guid))
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/MongoDB/MongoCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public MongoCollection(
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(MongoDynamicCollection)))
: new MongoModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new MongoModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/PgVector/PostgresCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal PostgresCollection(NpgsqlDataSource dataSource, NpgsqlDataSourceArc? da
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(PostgresDynamicCollection)))
: new PostgresModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new PostgresModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/PgVector/PostgresModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ protected override bool SupportsKeyAutoGeneration(Type keyPropertyType)

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(short)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/Pinecone/PineconeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public PineconeCollection(PineconeClient pineconeClient, string name, PineconeCo
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(PineconeDynamicCollection)))
: new PineconeModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new PineconeModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/Pinecone/PineconeModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal class PineconeModelBuilder() : CollectionModelBuilder(s_validationOptio

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(Guid))
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/Qdrant/QdrantCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal QdrantCollection(Func<MockableQdrantClient> clientFactory, string name,
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(QdrantDynamicCollection)))
: new QdrantModelBuilder(options.HasNamedVectors).Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new QdrantModelBuilder(options.HasNamedVectors).Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/Qdrant/QdrantModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private static CollectionModelBuildingOptions GetModelBuildOptions(bool hasNamed

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(ulong) && type != typeof(Guid))
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/Redis/RedisHashSetCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public RedisHashSetCollection(IDatabase database, string name, RedisHashSetColle
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(RedisHashSetDynamicCollection)))
: new RedisModelBuilder(ModelBuildingOptions).Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new RedisModelBuilder(ModelBuildingOptions).Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/VectorData/Redis/RedisJsonCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public RedisJsonCollection(IDatabase database, string name, RedisJsonCollectionO
: new RedisJsonModelBuilder(ModelBuildingOptions)
.Build(
typeof(TRecord),
typeof(TKey),
options.Definition,
options.EmbeddingGenerator,
options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/Redis/RedisJsonDynamicModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal class RedisJsonDynamicModelBuilder(CollectionModelBuildingOptions optio

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(Guid))
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/Redis/RedisJsonModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal class RedisJsonModelBuilder(CollectionModelBuildingOptions options) : C

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(Guid))
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/Redis/RedisModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal class RedisModelBuilder(CollectionModelBuildingOptions options) : Colle

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(string) && type != typeof(Guid))
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/SqlServer/SqlServerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SqlServerCollection(
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(SqlServerDynamicCollection)))
: new SqlServerModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new SqlServerModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/SqlServer/SqlServerModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ protected override bool SupportsKeyAutoGeneration(Type keyPropertyType)

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(int) && type != typeof(long) && type != typeof(string) && type != typeof(Guid))
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/VectorData/SqliteVec/SqliteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public SqliteCollection(
name,
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(SqliteDynamicCollection)))
: new SqliteModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
: new SqliteModelBuilder().Build(typeof(TRecord), typeof(TKey), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/VectorData/SqliteVec/SqliteModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ protected override bool SupportsKeyAutoGeneration(Type keyPropertyType)

protected override void ValidateKeyProperty(KeyPropertyModel keyProperty)
{
base.ValidateKeyProperty(keyProperty);

var type = keyProperty.Type;

if (type != typeof(int) && type != typeof(long) && type != typeof(string) && type != typeof(Guid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ protected CollectionJsonModelBuilder(CollectionModelBuildingOptions options)
}

/// <summary>
/// Builds and returns a <see cref="CollectionModel"/> from the given <paramref name="type"/> and <paramref name="definition"/>.
/// Builds and returns a <see cref="CollectionModel"/> from the given <paramref name="recordType"/> and <paramref name="definition"/>.
/// </summary>
[RequiresDynamicCode("This model building variant is not compatible with NativeAOT. See BuildDynamic() for dynamic mapping, and a third variant accepting source-generated delegates will be introduced in the future.")]
[RequiresUnreferencedCode("This model building variant is not compatible with trimming. See BuildDynamic() for dynamic mapping, and a third variant accepting source-generated delegates will be introduced in the future.")]
public virtual CollectionModel Build(
Type type,
Type recordType,
Type keyType,
VectorStoreCollectionDefinition? definition,
IEmbeddingGenerator? defaultEmbeddingGenerator,
JsonSerializerOptions jsonSerializerOptions)
{
this._jsonSerializerOptions = jsonSerializerOptions;

return this.Build(type, definition, defaultEmbeddingGenerator);
return this.Build(recordType, keyType, definition, defaultEmbeddingGenerator);
}

/// <summary>
Expand Down
Loading
Loading