Skip to content

.Net: Shorten VectorStoreRecordDefinition option name #12085

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
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 @@ -58,7 +58,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
name,
new()
{
VectorStoreRecordDefinition = s_recordDefinition
Definition = s_recordDefinition
}) as VectorStoreCollection<TKey, TRecord>)!;
}

Expand All @@ -72,7 +72,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
name,
new()
{
VectorStoreRecordDefinition = s_recordDefinition
Definition = s_recordDefinition
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
name,
new()
{
VectorStoreRecordDefinition = s_recordDefinition
Definition = s_recordDefinition
}) as VectorStoreCollection<TKey, TRecord>)!;
}

Expand All @@ -74,7 +74,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
name,
new()
{
VectorStoreRecordDefinition = s_recordDefinition
Definition = s_recordDefinition
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void CanCreateCollectionWithMismatchedDefinitionAndType()
using var sut = new AzureAISearchCollection<string, MultiPropsModel>(
this._searchIndexClientMock.Object,
TestCollectionName,
new() { VectorStoreRecordDefinition = definition });
new() { Definition = definition });
}

[Fact]
Expand Down Expand Up @@ -515,7 +515,7 @@ private AzureAISearchCollection<string, MultiPropsModel> CreateRecordCollection(
TestCollectionName,
new()
{
VectorStoreRecordDefinition = useDefinition ? this._multiPropsDefinition : null,
Definition = useDefinition ? this._multiPropsDefinition : null,
JsonSerializerOptions = useCustomJsonSerializerOptions ? this._customJsonSerializerOptions : null
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void ConstructorWithImperativeModelInitializesCollection()
using var collection = new CosmosMongoCollection<string, TestModel>(
this._mockMongoDatabase.Object,
"collection",
new() { VectorStoreRecordDefinition = definition });
new() { Definition = definition });

// Assert
Assert.NotNull(collection);
Expand Down Expand Up @@ -609,7 +609,7 @@ private async Task TestUpsertWithModelAsync<TDataModel>(
var expectedDefinition = Builders<BsonDocument>.Filter.Eq(document => document["_id"], "key");

CosmosMongoCollectionOptions? options = definition != null ?
new() { VectorStoreRecordDefinition = definition } :
new() { Definition = definition } :
null;

using var sut = new CosmosMongoCollection<string, TDataModel>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void ConstructorWithImperativeModelInitializesCollection()
using var collection = new CosmosNoSqlCollection<string, TestModel>(
this._mockDatabase.Object,
"collection",
new() { VectorStoreRecordDefinition = definition });
new() { Definition = definition });

// Assert
Assert.NotNull(collection);
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.VectorStoreRecordDefinition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
.Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,21 @@

using System.Text.Json;
using Azure.Search.Documents.Indexes;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData;

namespace Microsoft.SemanticKernel.Connectors.AzureAISearch;

/// <summary>
/// Options when creating a <see cref="AzureAISearchCollection{TKey, TRecord}"/>.
/// </summary>
public sealed class AzureAISearchCollectionOptions
public sealed class AzureAISearchCollectionOptions : VectorStoreCollectionOptions
{
internal static readonly AzureAISearchCollectionOptions Default = new();

/// <summary>
/// Gets or sets an optional record definition that defines the schema of the record type.
/// </summary>
/// <remarks>
/// If not provided, the schema will be inferred from the record model class using reflection.
/// In this case, the record model properties must be annotated with the appropriate attributes to indicate their usage.
/// See <see cref="VectorStoreKeyAttribute"/>, <see cref="VectorStoreDataAttribute"/> and <see cref="VectorStoreVectorAttribute"/>.
/// </remarks>
public VectorStoreRecordDefinition? VectorStoreRecordDefinition { get; set; }

/// <summary>
/// Gets or sets the JSON serializer options to use when converting between the data model and the Azure AI Search record.
/// Note that when using the default mapper and you are constructing your own <see cref="SearchIndexClient"/>, you will need
/// to provide the same set of <see cref="System.Text.Json.JsonSerializerOptions"/> both here and when constructing the <see cref="SearchIndexClient"/>.
/// </summary>
public JsonSerializerOptions? JsonSerializerOptions { get; set; }

/// <summary>
/// Gets or sets the default embedding generator to use when generating vectors embeddings with this vector store.
/// </summary>
public IEmbeddingGenerator? EmbeddingGenerator { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AzureAISearchDynamicCollection(SearchIndexClient searchIndexClient, strin
searchIndexClient,
name,
static options => new AzureAISearchDynamicModelBuilder().BuildDynamic(
options.VectorStoreRecordDefinition ?? throw new ArgumentException("VectorStoreRecordDefinition is required for dynamic collections"),
options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections"),
options.EmbeddingGenerator),
options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
new AzureAISearchCollectionOptions()
{
JsonSerializerOptions = this._jsonSerializerOptions,
VectorStoreRecordDefinition = vectorStoreRecordDefinition,
Definition = vectorStoreRecordDefinition,
EmbeddingGenerator = this._embeddingGenerator
});

Expand All @@ -93,7 +93,7 @@ public override AzureAISearchDynamicCollection GetDynamicCollection(string name,
new()
{
JsonSerializerOptions = this._jsonSerializerOptions,
VectorStoreRecordDefinition = vectorStoreRecordDefinition,
Definition = vectorStoreRecordDefinition,
EmbeddingGenerator = this._embeddingGenerator
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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.VectorStoreRecordDefinition, options.EmbeddingGenerator),
: new MongoModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData;

namespace Microsoft.SemanticKernel.Connectors.CosmosMongoDB;

/// <summary>
/// Options when creating a <see cref="CosmosMongoCollection{TKey, TRecord}"/>.
/// </summary>
public sealed class CosmosMongoCollectionOptions
public sealed class CosmosMongoCollectionOptions : VectorStoreCollectionOptions
{
internal static readonly CosmosMongoCollectionOptions Default = new();

Expand All @@ -21,28 +20,13 @@ public CosmosMongoCollectionOptions()

internal CosmosMongoCollectionOptions(CosmosMongoCollectionOptions? source)
{
this.VectorStoreRecordDefinition = source?.VectorStoreRecordDefinition;
this.Definition = source?.Definition;
this.EmbeddingGenerator = source?.EmbeddingGenerator;
this.NumLists = source?.NumLists ?? Default.NumLists;
this.EfConstruction = source?.EfConstruction ?? Default.EfConstruction;
this.EfSearch = source?.EfSearch ?? Default.EfSearch;
}

/// <summary>
/// Gets or sets an optional record definition that defines the schema of the record type.
/// </summary>
/// <remarks>
/// If not provided, the schema will be inferred from the record model class using reflection.
/// In this case, the record model properties must be annotated with the appropriate attributes to indicate their usage.
/// See <see cref="VectorStoreKeyAttribute"/>, <see cref="VectorStoreDataAttribute"/> and <see cref="VectorStoreVectorAttribute"/>.
/// </remarks>
public VectorStoreRecordDefinition? VectorStoreRecordDefinition { get; set; }

/// <summary>
/// Gets or sets the default embedding generator to use when generating vectors embeddings with this vector store.
/// </summary>
public IEmbeddingGenerator? EmbeddingGenerator { get; set; }

/// <summary>
/// This integer is the number of clusters that the inverted file (IVF) index uses to group the vector data. Default is 1.
/// We recommend that numLists is set to documentCount/1000 for up to 1 million documents and to sqrt(documentCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CosmosMongoDynamicCollection(IMongoDatabase mongoDatabase, string name, C
name,
static options => new MongoModelBuilder()
.BuildDynamic(
options.VectorStoreRecordDefinition ?? throw new ArgumentException("VectorStoreRecordDefinition is required for dynamic collections"),
options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections"),
options.EmbeddingGenerator),
options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
name,
new()
{
VectorStoreRecordDefinition = vectorStoreRecordDefinition,
Definition = vectorStoreRecordDefinition,
EmbeddingGenerator = this._embeddingGenerator
});

Expand All @@ -83,7 +83,7 @@ public override CosmosMongoDynamicCollection GetDynamicCollection(string name, V
name,
new()
{
VectorStoreRecordDefinition = vectorStoreRecordDefinition,
Definition = vectorStoreRecordDefinition,
EmbeddingGenerator = this._embeddingGenerator,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ internal CosmosNoSqlCollection(
static options => typeof(TRecord) == typeof(Dictionary<string, object?>)
? throw new NotSupportedException(VectorDataStrings.NonDynamicCollectionWithDictionaryNotSupported(typeof(CosmosNoSqlDynamicCollection)))
: new CosmosNoSqlModelBuilder()
.Build(typeof(TRecord), options.VectorStoreRecordDefinition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
.Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator, options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

using System.Text.Json;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData;

namespace Microsoft.SemanticKernel.Connectors.CosmosNoSql;

/// <summary>
/// Options when creating a <see cref="CosmosNoSqlCollection{TKey, TRecord}"/>.
/// </summary>
public sealed class CosmosNoSqlCollectionOptions
public sealed class CosmosNoSqlCollectionOptions : VectorStoreCollectionOptions
{
internal static readonly CosmosNoSqlCollectionOptions Default = new();

Expand All @@ -23,24 +22,14 @@ public CosmosNoSqlCollectionOptions()

internal CosmosNoSqlCollectionOptions(CosmosNoSqlCollectionOptions? source)
{
this.VectorStoreRecordDefinition = source?.VectorStoreRecordDefinition;
this.Definition = source?.Definition;
this.JsonSerializerOptions = source?.JsonSerializerOptions;
this.PartitionKeyPropertyName = source?.PartitionKeyPropertyName;
this.IndexingMode = source?.IndexingMode ?? Default.IndexingMode;
this.Automatic = source?.Automatic ?? Default.Automatic;
this.EmbeddingGenerator = source?.EmbeddingGenerator;
}

/// <summary>
/// Gets or sets an optional record definition that defines the schema of the record type.
/// </summary>
/// <remarks>
/// If not provided, the schema will be inferred from the record model class using reflection.
/// In this case, the record model properties must be annotated with the appropriate attributes to indicate their usage.
/// See <see cref="VectorStoreKeyAttribute"/>, <see cref="VectorStoreDataAttribute"/> and <see cref="VectorStoreVectorAttribute"/>.
/// </remarks>
public VectorStoreRecordDefinition? VectorStoreRecordDefinition { get; set; }

/// <summary>
/// Gets or sets the JSON serializer options to use when converting between the data model and the Azure CosmosDB NoSQL record.
/// </summary>
Expand All @@ -67,9 +56,4 @@ internal CosmosNoSqlCollectionOptions(CosmosNoSqlCollectionOptions? source)
/// Default is <see langword="true" />.
/// </remarks>
public bool Automatic { get; set; } = true;

/// <summary>
/// Gets or sets the default embedding generator to use when generating vectors embeddings with this vector store.
/// </summary>
public IEmbeddingGenerator? EmbeddingGenerator { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal CosmosNoSqlDynamicCollection(
name,
static options => new CosmosNoSqlModelBuilder()
.BuildDynamic(
options.VectorStoreRecordDefinition ?? throw new ArgumentException("VectorStoreRecordDefinition is required for dynamic collections"),
options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections"),
options.EmbeddingGenerator,
options.JsonSerializerOptions ?? JsonSerializerOptions.Default),
options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord
name,
new()
{
VectorStoreRecordDefinition = vectorStoreRecordDefinition,
Definition = vectorStoreRecordDefinition,
JsonSerializerOptions = this._jsonSerializerOptions,
EmbeddingGenerator = this._embeddingGenerator
});
Expand All @@ -133,7 +133,7 @@ public override CosmosNoSqlDynamicCollection GetDynamicCollection(string name, V
name,
new()
{
VectorStoreRecordDefinition = vectorStoreRecordDefinition,
Definition = vectorStoreRecordDefinition,
JsonSerializerOptions = this._jsonSerializerOptions,
EmbeddingGenerator = this._embeddingGenerator
}
Expand Down
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.VectorStoreRecordDefinition, options.EmbeddingGenerator),
: new InMemoryModelBuilder().Build(typeof(TRecord), options.Definition, options.EmbeddingGenerator),
options)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData;

namespace Microsoft.SemanticKernel.Connectors.InMemory;

/// <summary>
/// Options when creating a <see cref="InMemoryCollection{TKey,TRecord}"/>.
/// </summary>
public sealed class InMemoryCollectionOptions
public sealed class InMemoryCollectionOptions : VectorStoreCollectionOptions
{
/// <summary>
/// Gets or sets an optional record definition that defines the schema of the record type.
/// </summary>
/// <remarks>
/// If not provided, the schema will be inferred from the record model class using reflection.
/// In this case, the record model properties must be annotated with the appropriate attributes to indicate their usage.
/// See <see cref="VectorStoreKeyAttribute"/>, <see cref="VectorStoreDataAttribute"/> and <see cref="VectorStoreVectorAttribute"/>.
/// </remarks>
public VectorStoreRecordDefinition? VectorStoreRecordDefinition { get; set; }

/// <summary>
/// Gets or sets the default embedding generator to use when generating vectors embeddings with this vector store.
/// </summary>
public IEmbeddingGenerator? EmbeddingGenerator { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public InMemoryDynamicCollection(string name, InMemoryCollectionOptions options)
internalCollectionTypes: null,
name,
static options => new InMemoryModelBuilder().BuildDynamic(
options.VectorStoreRecordDefinition ?? throw new ArgumentException("VectorStoreRecordDefinition is required for dynamic collections"),
options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections"),
options.EmbeddingGenerator),
options)
{
Expand All @@ -43,7 +43,7 @@ internal InMemoryDynamicCollection(
internalCollectionTypes,
name,
static options => new InMemoryModelBuilder().BuildDynamic(
options.VectorStoreRecordDefinition ?? throw new ArgumentException("VectorStoreRecordDefinition is required for dynamic collections"),
options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections"),
options.EmbeddingGenerator),
options)
{
Expand Down
Loading
Loading