From 057ad3f9725a8e94a5ada8025c417b7138e7d4d3 Mon Sep 17 00:00:00 2001 From: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Date: Tue, 15 Apr 2025 14:12:36 -0700 Subject: [PATCH 1/2] Added extension methods of GetRequiredService --- .../VectorData.Abstractions/Throw.cs | 14 ++++++++ .../KeywordHybridSearchExtensions.cs | 33 +++++++++++++++++++ .../VectorizableTextSearchExtensions.cs | 33 +++++++++++++++++++ .../VectorizedSearchExtensions.cs | 33 +++++++++++++++++++ .../VectorStorage/VectorStoreExtensions.cs | 33 +++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 dotnet/src/Connectors/VectorData.Abstractions/Throw.cs create mode 100644 dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/KeywordHybridSearchExtensions.cs create mode 100644 dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizableTextSearchExtensions.cs create mode 100644 dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizedSearchExtensions.cs create mode 100644 dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/VectorStoreExtensions.cs diff --git a/dotnet/src/Connectors/VectorData.Abstractions/Throw.cs b/dotnet/src/Connectors/VectorData.Abstractions/Throw.cs new file mode 100644 index 000000000000..42682c708155 --- /dev/null +++ b/dotnet/src/Connectors/VectorData.Abstractions/Throw.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; + +namespace Microsoft.Extensions.VectorData; + +internal static class Throw +{ + /// Throws an exception indicating that a required service is not available. + public static InvalidOperationException CreateMissingServiceException(Type serviceType, object? serviceKey) => + new(serviceKey is null ? + $"No service of type '{serviceType}' is available." : + $"No service of type '{serviceType}' for the key '{serviceKey}' is available."); +} diff --git a/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/KeywordHybridSearchExtensions.cs b/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/KeywordHybridSearchExtensions.cs new file mode 100644 index 000000000000..0e8435ae25c2 --- /dev/null +++ b/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/KeywordHybridSearchExtensions.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.Extensions.VectorData; + +/// Provides a collection of static methods for extending instances. +[Experimental("MEVD9000")] +public static class KeywordHybridSearchExtensions +{ + /// + /// Asks the for an object of the specified type + /// and throw an exception if one isn't available. + /// + /// The record data model to use for retrieving data from the store. + /// The keyword hybrid search. + /// The type of object being requested. + /// An optional key that can be used to help identify the target service. + /// The found object. + /// is . + /// is . + /// No service of the requested type for the specified key is available. + public static object GetRequiredService(this IKeywordHybridSearch keywordHybridSearch, Type serviceType, object? serviceKey = null) + { + if (keywordHybridSearch is null) { throw new ArgumentNullException(nameof(keywordHybridSearch)); } + if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); } + + return + keywordHybridSearch.GetService(serviceType, serviceKey) ?? + throw Throw.CreateMissingServiceException(serviceType, serviceKey); + } +} diff --git a/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizableTextSearchExtensions.cs b/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizableTextSearchExtensions.cs new file mode 100644 index 000000000000..442155bdcccc --- /dev/null +++ b/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizableTextSearchExtensions.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.Extensions.VectorData; + +/// Provides a collection of static methods for extending instances. +[Experimental("MEVD9000")] +public static class VectorizableTextSearchExtensions +{ + /// + /// Asks the for an object of the specified type + /// and throw an exception if one isn't available. + /// + /// The record data model to use for retrieving data from the store. + /// The vectorizable text search. + /// The type of object being requested. + /// An optional key that can be used to help identify the target service. + /// The found object. + /// is . + /// is . + /// No service of the requested type for the specified key is available. + public static object GetRequiredService(this IVectorizableTextSearch vectorizableTextSearch, Type serviceType, object? serviceKey = null) + { + if (vectorizableTextSearch is null) { throw new ArgumentNullException(nameof(vectorizableTextSearch)); } + if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); } + + return + vectorizableTextSearch.GetService(serviceType, serviceKey) ?? + throw Throw.CreateMissingServiceException(serviceType, serviceKey); + } +} diff --git a/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizedSearchExtensions.cs b/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizedSearchExtensions.cs new file mode 100644 index 000000000000..07b40aa39b21 --- /dev/null +++ b/dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorizedSearchExtensions.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.Extensions.VectorData; + +/// Provides a collection of static methods for extending instances. +[Experimental("MEVD9000")] +public static class VectorizedSearchExtensions +{ + /// + /// Asks the for an object of the specified type + /// and throw an exception if one isn't available. + /// + /// The record data model to use for retrieving data from the store. + /// The vectorized search. + /// The type of object being requested. + /// An optional key that can be used to help identify the target service. + /// The found object. + /// is . + /// is . + /// No service of the requested type for the specified key is available. + public static object GetRequiredService(this IVectorizedSearch vectorizedSearch, Type serviceType, object? serviceKey = null) + { + if (vectorizedSearch is null) { throw new ArgumentNullException(nameof(vectorizedSearch)); } + if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); } + + return + vectorizedSearch.GetService(serviceType, serviceKey) ?? + throw Throw.CreateMissingServiceException(serviceType, serviceKey); + } +} diff --git a/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/VectorStoreExtensions.cs b/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/VectorStoreExtensions.cs new file mode 100644 index 000000000000..9d50678cc118 --- /dev/null +++ b/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/VectorStoreExtensions.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.Extensions.VectorData; + +/// Provides a collection of static methods for extending instances. +[Experimental("MEVD9000")] +public static class VectorStoreExtensions +{ + /// + /// Asks the for an object of the specified type + /// and throw an exception if one isn't available. + /// + /// The record data model to use for retrieving data from the store. + /// The vector store. + /// The type of object being requested. + /// An optional key that can be used to help identify the target service. + /// The found object. + /// is . + /// is . + /// No service of the requested type for the specified key is available. + public static object GetRequiredService(this IVectorStore vectorStore, Type serviceType, object? serviceKey = null) + { + if (vectorStore is null) { throw new ArgumentNullException(nameof(vectorStore)); } + if (serviceType is null) { throw new ArgumentNullException(nameof(serviceType)); } + + return + vectorStore.GetService(serviceType, serviceKey) ?? + throw Throw.CreateMissingServiceException(serviceType, serviceKey); + } +} From cb4c52dfc5ea8f7c17db1c8a35cef5927d033887 Mon Sep 17 00:00:00 2001 From: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Date: Tue, 15 Apr 2025 14:39:04 -0700 Subject: [PATCH 2/2] Renamed CollectionName to Name --- ...extEmbeddingVectorStoreRecordCollection.cs | 2 +- ...zureAISearchVectorStoreRecordCollection.cs | 14 ++--- ...mosDBMongoDBVectorStoreRecordCollection.cs | 38 ++++++------ ...osmosDBNoSQLVectorStoreRecordCollection.cs | 36 +++++------ .../InMemoryVectorStoreRecordCollection.cs | 14 ++--- .../MongoDBVectorStoreRecordCollection.cs | 44 ++++++------- .../PineconeVectorStoreRecordCollection.cs | 38 ++++++------ .../PostgresVectorStoreRecordCollection.cs | 62 +++++++++---------- .../QdrantVectorStoreRecordCollection.cs | 24 +++---- ...RedisHashSetVectorStoreRecordCollection.cs | 12 ++-- .../RedisJsonVectorStoreRecordCollection.cs | 12 ++-- .../SqlServerVectorStoreRecordCollection.cs | 52 ++++++++-------- .../SqliteVectorStoreRecordCollection.cs | 22 +++---- .../WeaviateVectorStoreRecordCollection.cs | 46 +++++++------- .../IVectorStoreRecordCollection.cs | 2 +- 15 files changed, 209 insertions(+), 209 deletions(-) diff --git a/dotnet/samples/Concepts/Memory/VectorStoreEmbeddingGeneration/TextEmbeddingVectorStoreRecordCollection.cs b/dotnet/samples/Concepts/Memory/VectorStoreEmbeddingGeneration/TextEmbeddingVectorStoreRecordCollection.cs index d3ae50ec7130..eaf346e90020 100644 --- a/dotnet/samples/Concepts/Memory/VectorStoreEmbeddingGeneration/TextEmbeddingVectorStoreRecordCollection.cs +++ b/dotnet/samples/Concepts/Memory/VectorStoreEmbeddingGeneration/TextEmbeddingVectorStoreRecordCollection.cs @@ -49,7 +49,7 @@ public TextEmbeddingVectorStoreRecordCollection(IVectorStoreRecordCollection - public string CollectionName => this._decoratedVectorStoreRecordCollection.CollectionName; + public string Name => this._decoratedVectorStoreRecordCollection.Name; /// public Task CollectionExistsAsync(CancellationToken cancellationToken = default) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorStoreRecordCollection.cs index 60a5e26e320f..711467eb1ba2 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorStoreRecordCollection.cs @@ -64,15 +64,15 @@ public sealed class AzureAISearchVectorStoreRecordCollection : /// Initializes a new instance of the class. /// /// Azure AI Search client that can be used to manage the list of indices in an Azure AI Search Service. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. /// Thrown when is null. /// Thrown when options are misconfigured. - public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexClient, string collectionName, AzureAISearchVectorStoreRecordCollectionOptions? options = default) + public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexClient, string name, AzureAISearchVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(searchIndexClient); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object)) { @@ -81,9 +81,9 @@ public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexCli // Assign. this._searchIndexClient = searchIndexClient; - this._collectionName = collectionName; + this._collectionName = name; this._options = options ?? new AzureAISearchVectorStoreRecordCollectionOptions(); - this._searchClient = this._searchIndexClient.GetSearchClient(collectionName); + this._searchClient = this._searchIndexClient.GetSearchClient(name); this._model = new VectorStoreRecordJsonModelBuilder(AzureAISearchConstants.s_modelBuildingOptions) .Build(typeof(TRecord), this._options.VectorStoreRecordDefinition, this._options.JsonSerializerOptions); @@ -100,12 +100,12 @@ public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexCli { VectorStoreSystemName = AzureAISearchConstants.VectorStoreSystemName, VectorStoreName = searchIndexClient.ServiceName, - CollectionName = collectionName + CollectionName = name }; } /// - public string CollectionName => this._collectionName; + public string Name => this._collectionName; /// public async Task CollectionExistsAsync(CancellationToken cancellationToken = default) diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBVectorStoreRecordCollection.cs index c9cdc5a9c7d5..77ab871771c9 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBMongoDB/AzureCosmosDBMongoDBVectorStoreRecordCollection.cs @@ -58,22 +58,22 @@ public sealed class AzureCosmosDBMongoDBVectorStoreRecordCollection - public string CollectionName { get; } + public string Name { get; } /// /// Initializes a new instance of the class. /// /// that can be used to manage the collections in Azure CosmosDB MongoDB. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. public AzureCosmosDBMongoDBVectorStoreRecordCollection( IMongoDatabase mongoDatabase, - string collectionName, + string name, AzureCosmosDBMongoDBVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(mongoDatabase); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object)) { @@ -82,8 +82,8 @@ public AzureCosmosDBMongoDBVectorStoreRecordCollection( // Assign. this._mongoDatabase = mongoDatabase; - this._mongoCollection = mongoDatabase.GetCollection(collectionName); - this.CollectionName = collectionName; + this._mongoCollection = mongoDatabase.GetCollection(name); + this.Name = name; this._options = options ?? new AzureCosmosDBMongoDBVectorStoreRecordCollectionOptions(); this._model = new MongoDBModelBuilder().Build(typeof(TRecord), this._options.VectorStoreRecordDefinition); this._mapper = typeof(TRecord) == typeof(Dictionary) @@ -94,7 +94,7 @@ public AzureCosmosDBMongoDBVectorStoreRecordCollection( { VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName, VectorStoreName = mongoDatabase.DatabaseNamespace?.DatabaseName, - CollectionName = collectionName + CollectionName = name }; } @@ -113,7 +113,7 @@ public async Task CreateCollectionAsync(CancellationToken cancellationToken = de { VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = "CreateCollection" }; } @@ -125,10 +125,10 @@ public async Task CreateCollectionAsync(CancellationToken cancellationToken = de public async Task CreateCollectionIfNotExistsAsync(CancellationToken cancellationToken = default) { await this.RunOperationAsync("CreateCollection", - () => this._mongoDatabase.CreateCollectionAsync(this.CollectionName, cancellationToken: cancellationToken)).ConfigureAwait(false); + () => this._mongoDatabase.CreateCollectionAsync(this.Name, cancellationToken: cancellationToken)).ConfigureAwait(false); await this.RunOperationAsync("CreateIndexes", - () => this.CreateIndexesAsync(this.CollectionName, cancellationToken: cancellationToken)).ConfigureAwait(false); + () => this.CreateIndexesAsync(this.Name, cancellationToken: cancellationToken)).ConfigureAwait(false); } /// @@ -153,7 +153,7 @@ await this.RunOperationAsync("DeleteMany", () => this._mongoCollection.DeleteMan /// public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) - => this.RunOperationAsync("DropCollection", () => this._mongoDatabase.DropCollectionAsync(this.CollectionName, cancellationToken)); + => this.RunOperationAsync("DropCollection", () => this._mongoDatabase.DropCollectionAsync(this.Name, cancellationToken)); /// public async Task GetAsync(TKey key, GetRecordOptions? options = null, CancellationToken cancellationToken = default) @@ -181,7 +181,7 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) return VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBMongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(record, new() { IncludeVectors = includeVectors })); } @@ -211,7 +211,7 @@ public async IAsyncEnumerable GetAsync( yield return VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBMongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(record, new())); } @@ -230,7 +230,7 @@ public Task UpsertAsync(TRecord record, CancellationToken cancellationToke var storageModel = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBMongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record)); @@ -391,7 +391,7 @@ public async IAsyncEnumerable GetAsync(Expression> var record = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBMongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "GetAsync", () => this._mapper.MapFromStorageToDataModel(response, new() { IncludeVectors = options.IncludeVectors })); @@ -475,7 +475,7 @@ private async IAsyncEnumerable> EnumerateAndMapSearc var record = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBMongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(response[DocumentPropertyName].AsBsonDocument, new())); @@ -495,7 +495,7 @@ private FilterDefinition GetFilterByIds(IEnumerable ids) private async Task InternalCollectionExistsAsync(CancellationToken cancellationToken) { - var filter = new BsonDocument("name", this.CollectionName); + var filter = new BsonDocument("name", this.Name); var options = new ListCollectionNamesOptions { Filter = filter }; using var cursor = await this._mongoDatabase.ListCollectionNamesAsync(options, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -515,7 +515,7 @@ private async Task RunOperationAsync(string operationName, Func operation) { VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -533,7 +533,7 @@ private async Task RunOperationAsync(string operationName, Func> o { VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLVectorStoreRecordCollection.cs index fff3d2fd5a56..b61112ff5439 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLVectorStoreRecordCollection.cs @@ -57,22 +57,22 @@ public sealed class AzureCosmosDBNoSQLVectorStoreRecordCollection private readonly ICosmosNoSQLMapper _mapper; /// - public string CollectionName { get; } + public string Name { get; } /// /// Initializes a new instance of the class. /// /// that can be used to manage the collections in Azure CosmosDB NoSQL. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. public AzureCosmosDBNoSQLVectorStoreRecordCollection( Database database, - string collectionName, + string name, AzureCosmosDBNoSQLVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(database); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(AzureCosmosDBNoSQLCompositeKey) && typeof(TKey) != typeof(object)) { @@ -88,7 +88,7 @@ public AzureCosmosDBNoSQLVectorStoreRecordCollection( // Assign. this._database = database; - this.CollectionName = collectionName; + this.Name = name; this._options = options ?? new(); var jsonSerializerOptions = this._options.JsonSerializerOptions ?? JsonSerializerOptions.Default; this._model = new AzureCosmosDBNoSqlVectorStoreModelBuilder() @@ -124,7 +124,7 @@ public AzureCosmosDBNoSQLVectorStoreRecordCollection( { VectorStoreSystemName = AzureCosmosDBNoSQLConstants.VectorStoreSystemName, VectorStoreName = database.Id, - CollectionName = collectionName + CollectionName = name }; } @@ -135,7 +135,7 @@ public Task CollectionExistsAsync(CancellationToken cancellationToken = de { const string Query = "SELECT VALUE(c.id) FROM c WHERE c.id = @collectionName"; - var queryDefinition = new QueryDefinition(Query).WithParameter("@collectionName", this.CollectionName); + var queryDefinition = new QueryDefinition(Query).WithParameter("@collectionName", this.Name); using var feedIterator = this._database.GetContainerQueryIterator(queryDefinition); @@ -174,7 +174,7 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) { return this.RunOperationAsync("DeleteContainer", () => this._database - .GetContainer(this.CollectionName) + .GetContainer(this.Name) .DeleteContainerAsync(cancellationToken: cancellationToken)); } @@ -194,7 +194,7 @@ public async Task DeleteAsync(IEnumerable keys, CancellationToken cancella return this.RunOperationAsync("DeleteItem", () => this._database - .GetContainer(this.CollectionName) + .GetContainer(this.Name) .DeleteItemAsync(key.RecordKey, new PartitionKey(key.PartitionKey), cancellationToken: cancellationToken)); }); @@ -233,7 +233,7 @@ public async IAsyncEnumerable GetAsync( var record = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBNoSQLConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(jsonObject, new() { IncludeVectors = includeVectors })); @@ -254,7 +254,7 @@ public async Task UpsertAsync(TRecord record, CancellationToken cancellati var jsonObject = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBNoSQLConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record)); @@ -273,7 +273,7 @@ public async Task UpsertAsync(TRecord record, CancellationToken cancellati await this.RunOperationAsync(OperationName, () => this._database - .GetContainer(this.CollectionName) + .GetContainer(this.Name) .UpsertItemAsync(jsonObject, new PartitionKey(partitionKeyValue), cancellationToken: cancellationToken)) .ConfigureAwait(false); @@ -361,7 +361,7 @@ public async IAsyncEnumerable GetAsync(Expression> var record = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBNoSQLConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "GetAsync", () => this._mapper.MapFromStorageToDataModel(jsonObject, new() { IncludeVectors = options.IncludeVectors })); @@ -447,7 +447,7 @@ private async Task RunOperationAsync(string operationName, Func> o { VectorStoreSystemName = AzureCosmosDBNoSQLConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -471,7 +471,7 @@ private ContainerProperties GetContainerProperties() if (this._options.IndexingMode == IndexingMode.None) { - return new ContainerProperties(this.CollectionName, partitionKeyPath: $"/{this._partitionKeyProperty.StorageName}") + return new ContainerProperties(this.Name, partitionKeyPath: $"/{this._partitionKeyProperty.StorageName}") { IndexingPolicy = indexingPolicy }; @@ -528,7 +528,7 @@ private ContainerProperties GetContainerProperties() indexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = $"{vectorIndexPath.Path}/*" }); } - return new ContainerProperties(this.CollectionName, partitionKeyPath: $"/{this._partitionKeyProperty.StorageName}") + return new ContainerProperties(this.Name, partitionKeyPath: $"/{this._partitionKeyProperty.StorageName}") { VectorEmbeddingPolicy = vectorEmbeddingPolicy, IndexingPolicy = indexingPolicy, @@ -583,7 +583,7 @@ private static VectorDataType GetDataType(Type vectorDataType, string vectorProp private async IAsyncEnumerable GetItemsAsync(QueryDefinition queryDefinition, [EnumeratorCancellation] CancellationToken cancellationToken) { var iterator = this._database - .GetContainer(this.CollectionName) + .GetContainer(this.Name) .GetItemQueryIterator(queryDefinition); while (iterator.HasMoreResults) @@ -617,7 +617,7 @@ private async IAsyncEnumerable> MapSearchResultsAsyn var record = VectorStoreErrorHandler.RunModelConversion( AzureCosmosDBNoSQLConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, operationName, () => this._mapper.MapFromStorageToDataModel(jsonObject, new() { IncludeVectors = includeVectors })); diff --git a/dotnet/src/Connectors/Connectors.Memory.InMemory/InMemoryVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.InMemory/InMemoryVectorStoreRecordCollection.cs index 419996e7bc00..810f9932245b 100644 --- a/dotnet/src/Connectors/Connectors.Memory.InMemory/InMemoryVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.InMemory/InMemoryVectorStoreRecordCollection.cs @@ -67,15 +67,15 @@ public sealed class InMemoryVectorStoreRecordCollection : IVector /// /// Initializes a new instance of the class. /// - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. - public InMemoryVectorStoreRecordCollection(string collectionName, InMemoryVectorStoreRecordCollectionOptions? options = default) + public InMemoryVectorStoreRecordCollection(string name, InMemoryVectorStoreRecordCollectionOptions? options = default) { // Verify. - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); // Assign. - this._collectionName = collectionName; + this._collectionName = name; this._internalCollections = new(); this._internalCollectionTypes = new(); this._options = options ?? new InMemoryVectorStoreRecordCollectionOptions(); @@ -111,7 +111,7 @@ public InMemoryVectorStoreRecordCollection(string collectionName, InMemoryVector this._collectionMetadata = new() { VectorStoreSystemName = InMemoryConstants.VectorStoreSystemName, - CollectionName = collectionName + CollectionName = name }; } @@ -134,7 +134,7 @@ internal InMemoryVectorStoreRecordCollection( } /// - public string CollectionName => this._collectionName; + public string Name => this._collectionName; /// public Task CollectionExistsAsync(CancellationToken cancellationToken = default) @@ -155,7 +155,7 @@ public Task CreateCollectionAsync(CancellationToken cancellationToken = default) return Task.FromException(new VectorStoreOperationException("Collection already exists.") { VectorStoreSystemName = InMemoryConstants.VectorStoreSystemName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = "CreateCollection" }); } diff --git a/dotnet/src/Connectors/Connectors.Memory.MongoDB/MongoDBVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.MongoDB/MongoDBVectorStoreRecordCollection.cs index 38244c4292a1..7ed0a3cc0b45 100644 --- a/dotnet/src/Connectors/Connectors.Memory.MongoDB/MongoDBVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.MongoDB/MongoDBVectorStoreRecordCollection.cs @@ -58,22 +58,22 @@ public sealed class MongoDBVectorStoreRecordCollection : IVectorS private readonly VectorStoreRecordModel _model; /// - public string CollectionName { get; } + public string Name { get; } /// /// Initializes a new instance of the class. /// /// that can be used to manage the collections in MongoDB. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. public MongoDBVectorStoreRecordCollection( IMongoDatabase mongoDatabase, - string collectionName, + string name, MongoDBVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(mongoDatabase); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object)) { @@ -82,8 +82,8 @@ public MongoDBVectorStoreRecordCollection( // Assign. this._mongoDatabase = mongoDatabase; - this._mongoCollection = mongoDatabase.GetCollection(collectionName); - this.CollectionName = collectionName; + this._mongoCollection = mongoDatabase.GetCollection(name); + this.Name = name; this._options = options ?? new MongoDBVectorStoreRecordCollectionOptions(); this._model = new MongoDBModelBuilder().Build(typeof(TRecord), this._options.VectorStoreRecordDefinition); this._mapper = typeof(TRecord) == typeof(Dictionary) @@ -94,7 +94,7 @@ public MongoDBVectorStoreRecordCollection( { VectorStoreSystemName = MongoDBConstants.VectorStoreSystemName, VectorStoreName = mongoDatabase.DatabaseNamespace?.DatabaseName, - CollectionName = collectionName + CollectionName = name }; } @@ -113,7 +113,7 @@ public async Task CreateCollectionAsync(CancellationToken cancellationToken = de { VectorStoreSystemName = MongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = "CreateCollection" }; } @@ -127,13 +127,13 @@ public async Task CreateCollectionIfNotExistsAsync(CancellationToken cancellatio // The IMongoDatabase.CreateCollectionAsync "Creates a new collection if not already available". // So for CreateCollectionIfNotExistsAsync, we don't perform an additional check. await this.RunOperationAsync("CreateCollection", - () => this._mongoDatabase.CreateCollectionAsync(this.CollectionName, cancellationToken: cancellationToken)).ConfigureAwait(false); + () => this._mongoDatabase.CreateCollectionAsync(this.Name, cancellationToken: cancellationToken)).ConfigureAwait(false); await this.RunOperationWithRetryAsync( "CreateIndexes", this._options.MaxRetries, this._options.DelayInMilliseconds, - () => this.CreateIndexesAsync(this.CollectionName, cancellationToken), + () => this.CreateIndexesAsync(this.Name, cancellationToken), cancellationToken).ConfigureAwait(false); } @@ -159,7 +159,7 @@ await this.RunOperationAsync("DeleteMany", () => this._mongoCollection.DeleteMan /// public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) - => this.RunOperationAsync("DropCollection", () => this._mongoDatabase.DropCollectionAsync(this.CollectionName, cancellationToken)); + => this.RunOperationAsync("DropCollection", () => this._mongoDatabase.DropCollectionAsync(this.Name, cancellationToken)); /// public async Task GetAsync(TKey key, GetRecordOptions? options = null, CancellationToken cancellationToken = default) @@ -187,7 +187,7 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) return VectorStoreErrorHandler.RunModelConversion( MongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(record, new() { IncludeVectors = includeVectors })); } @@ -217,7 +217,7 @@ public async IAsyncEnumerable GetAsync( yield return VectorStoreErrorHandler.RunModelConversion( MongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(record, new())); } @@ -236,7 +236,7 @@ public Task UpsertAsync(TRecord record, CancellationToken cancellationToke var storageModel = VectorStoreErrorHandler.RunModelConversion( MongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record)); @@ -374,7 +374,7 @@ public async IAsyncEnumerable GetAsync(Expression> var record = VectorStoreErrorHandler.RunModelConversion( MongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "GetAsync", () => this._mapper.MapFromStorageToDataModel(response, new() { IncludeVectors = options.IncludeVectors })); @@ -412,7 +412,7 @@ public async IAsyncEnumerable> HybridSearchAsync> EnumerateAndMapSearc var record = VectorStoreErrorHandler.RunModelConversion( MongoDBConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(response[DocumentPropertyName].AsBsonDocument, new() { IncludeVectors = includeVectors })); @@ -589,7 +589,7 @@ private FilterDefinition GetFilterByIds(IEnumerable ids) private async Task InternalCollectionExistsAsync(CancellationToken cancellationToken) { - var filter = new BsonDocument("name", this.CollectionName); + var filter = new BsonDocument("name", this.Name); var options = new ListCollectionNamesOptions { Filter = filter }; using var cursor = await this._mongoDatabase.ListCollectionNamesAsync(options, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -609,7 +609,7 @@ private async Task RunOperationAsync(string operationName, Func operation) { VectorStoreSystemName = MongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -627,7 +627,7 @@ private async Task RunOperationAsync(string operationName, Func> o { VectorStoreSystemName = MongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -659,7 +659,7 @@ private async Task RunOperationWithRetryAsync( { VectorStoreSystemName = MongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -694,7 +694,7 @@ private async Task RunOperationWithRetryAsync( { VectorStoreSystemName = MongoDBConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } diff --git a/dotnet/src/Connectors/Connectors.Memory.Pinecone/PineconeVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Pinecone/PineconeVectorStoreRecordCollection.cs index 220b1d0110e9..92b150310696 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Pinecone/PineconeVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Pinecone/PineconeVectorStoreRecordCollection.cs @@ -38,7 +38,7 @@ public sealed class PineconeVectorStoreRecordCollection : IVector private IndexClient? _indexClient; /// - public string CollectionName { get; } + public string Name { get; } /// /// Initializes a new instance of the class. @@ -46,12 +46,12 @@ public sealed class PineconeVectorStoreRecordCollection : IVector /// Pinecone client that can be used to manage the collections and vectors in a Pinecone store. /// Optional configuration options for this class. /// Thrown if the is null. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Thrown for any misconfigured options. - public PineconeVectorStoreRecordCollection(Sdk.PineconeClient pineconeClient, string collectionName, PineconeVectorStoreRecordCollectionOptions? options = null) + public PineconeVectorStoreRecordCollection(Sdk.PineconeClient pineconeClient, string name, PineconeVectorStoreRecordCollectionOptions? options = null) { Verify.NotNull(pineconeClient); - VerifyCollectionName(collectionName); + VerifyCollectionName(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object)) { @@ -59,7 +59,7 @@ public PineconeVectorStoreRecordCollection(Sdk.PineconeClient pineconeClient, st } this._pineconeClient = pineconeClient; - this.CollectionName = collectionName; + this.Name = name; this._options = options ?? new PineconeVectorStoreRecordCollectionOptions(); this._model = new VectorStoreRecordModelBuilder(PineconeVectorStoreRecordFieldMapping.ModelBuildingOptions) .Build(typeof(TRecord), this._options.VectorStoreRecordDefinition); @@ -68,7 +68,7 @@ public PineconeVectorStoreRecordCollection(Sdk.PineconeClient pineconeClient, st this._collectionMetadata = new() { VectorStoreSystemName = PineconeConstants.VectorStoreSystemName, - CollectionName = collectionName + CollectionName = name }; } @@ -80,7 +80,7 @@ public Task CollectionExistsAsync(CancellationToken cancellationToken = de { var collections = await this._pineconeClient.ListIndexesAsync(cancellationToken: cancellationToken).ConfigureAwait(false); - return collections.Indexes?.Any(x => x.Name == this.CollectionName) is true; + return collections.Indexes?.Any(x => x.Name == this.Name) is true; }); /// @@ -97,7 +97,7 @@ public Task CreateCollectionAsync(CancellationToken cancellationToken = default) CreateIndexRequest request = new() { - Name = this.CollectionName, + Name = this.Name, Dimension = vectorProperty.Dimensions, Metric = MapDistanceFunction(vectorProperty), Spec = new ServerlessIndexSpec @@ -135,7 +135,7 @@ public async Task DeleteCollectionAsync(CancellationToken cancellationToken = de { try { - await this._pineconeClient.DeleteIndexAsync(this.CollectionName, cancellationToken: cancellationToken).ConfigureAwait(false); + await this._pineconeClient.DeleteIndexAsync(this.Name, cancellationToken: cancellationToken).ConfigureAwait(false); } catch (NotFoundError) { @@ -147,7 +147,7 @@ public async Task DeleteCollectionAsync(CancellationToken cancellationToken = de { VectorStoreSystemName = PineconeConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = "DeleteCollection" }; } @@ -176,7 +176,7 @@ public async Task DeleteCollectionAsync(CancellationToken cancellationToken = de return VectorStoreErrorHandler.RunModelConversion( PineconeConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "Get", () => this._mapper.MapFromStorageToDataModel(result, mapperOptions)); } @@ -221,7 +221,7 @@ public async IAsyncEnumerable GetAsync( var records = VectorStoreErrorHandler.RunModelConversion( PineconeConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "GetBatch", () => response.Vectors.Values.Select(x => this._mapper.MapFromStorageToDataModel(x, mapperOptions))); @@ -281,7 +281,7 @@ public async Task UpsertAsync(TRecord record, CancellationToken cancellati var vector = VectorStoreErrorHandler.RunModelConversion( PineconeConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "Upsert", () => this._mapper.MapFromDataToStorageModel(record)); @@ -306,7 +306,7 @@ public async Task> UpsertAsync(IEnumerable records, var vectors = VectorStoreErrorHandler.RunModelConversion( PineconeConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "UpsertBatch", () => records.Select(this._mapper.MapFromDataToStorageModel).ToList()); @@ -379,7 +379,7 @@ public async IAsyncEnumerable> VectorizedSearchAsync var records = VectorStoreErrorHandler.RunModelConversion( PineconeConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "VectorizedSearch", () => skippedResults.Select(x => new VectorSearchResult(this._mapper.MapFromStorageToDataModel(new Sdk.Vector() { @@ -434,7 +434,7 @@ public async IAsyncEnumerable GetAsync(Expression> var records = VectorStoreErrorHandler.RunModelConversion( PineconeConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "Query", () => response.Matches.Skip(options.Skip).Select(x => this._mapper.MapFromStorageToDataModel(new Sdk.Vector() { @@ -471,7 +471,7 @@ private async Task RunIndexOperationAsync(string operationName, Func RunIndexOperationAsync(string operationName, Func RunCollectionOperationAsync(string operationName, Func< { VectorStoreSystemName = PineconeConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } diff --git a/dotnet/src/Connectors/Connectors.Memory.Postgres/PostgresVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Postgres/PostgresVectorStoreRecordCollection.cs index aab25cfe6d1f..3932bebb2ac8 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Postgres/PostgresVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Postgres/PostgresVectorStoreRecordCollection.cs @@ -24,7 +24,7 @@ public sealed class PostgresVectorStoreRecordCollection : IVector where TRecord : notnull { /// - public string CollectionName { get; } + public string Name { get; } /// Metadata about vector store record collection. private readonly VectorStoreRecordCollectionMetadata _collectionMetadata; @@ -48,10 +48,10 @@ public sealed class PostgresVectorStoreRecordCollection : IVector /// Initializes a new instance of the class. /// /// The data source to use for connecting to the database. - /// The name of the collection. + /// The name of the collection. /// Optional configuration options for this class. - public PostgresVectorStoreRecordCollection(NpgsqlDataSource dataSource, string collectionName, PostgresVectorStoreRecordCollectionOptions? options = default) - : this(new PostgresVectorStoreDbClient(dataSource), collectionName, options) + public PostgresVectorStoreRecordCollection(NpgsqlDataSource dataSource, string name, PostgresVectorStoreRecordCollectionOptions? options = default) + : this(new PostgresVectorStoreDbClient(dataSource), name, options) { } @@ -59,20 +59,20 @@ public PostgresVectorStoreRecordCollection(NpgsqlDataSource dataSource, string c /// Initializes a new instance of the class. /// /// The client to use for interacting with the database. - /// The name of the collection. + /// The name of the collection. /// Optional configuration options for this class. /// /// This constructor is internal. It allows internal code to create an instance of this class with a custom client. /// - internal PostgresVectorStoreRecordCollection(IPostgresVectorStoreDbClient client, string collectionName, PostgresVectorStoreRecordCollectionOptions? options = default) + internal PostgresVectorStoreRecordCollection(IPostgresVectorStoreDbClient client, string name, PostgresVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(client); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); // Assign. this._client = client; - this.CollectionName = collectionName; + this.Name = name; this._options = options ?? new PostgresVectorStoreRecordCollectionOptions(); this._model = new VectorStoreRecordModelBuilder(PostgresConstants.ModelBuildingOptions) @@ -84,7 +84,7 @@ internal PostgresVectorStoreRecordCollection(IPostgresVectorStoreDbClient client { VectorStoreSystemName = PostgresConstants.VectorStoreSystemName, VectorStoreName = this._client.DatabaseName, - CollectionName = collectionName + CollectionName = name }; } @@ -93,7 +93,7 @@ public Task CollectionExistsAsync(CancellationToken cancellationToken = de { const string OperationName = "DoesTableExists"; return this.RunOperationAsync(OperationName, () => - this._client.DoesTableExistsAsync(this.CollectionName, cancellationToken) + this._client.DoesTableExistsAsync(this.Name, cancellationToken) ); } @@ -120,7 +120,7 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) { const string OperationName = "DeleteCollection"; return this.RunOperationAsync(OperationName, () => - this._client.DeleteTableAsync(this.CollectionName, cancellationToken) + this._client.DeleteTableAsync(this.Name, cancellationToken) ); } @@ -132,7 +132,7 @@ public Task UpsertAsync(TRecord record, CancellationToken cancellationToke var storageModel = VectorStoreErrorHandler.RunModelConversion( PostgresConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record)); @@ -144,7 +144,7 @@ public Task UpsertAsync(TRecord record, CancellationToken cancellationToke return this.RunOperationAsync(OperationName, async () => { - await this._client.UpsertAsync(this.CollectionName, storageModel, this._model.KeyProperty.StorageName, cancellationToken).ConfigureAwait(false); + await this._client.UpsertAsync(this.Name, storageModel, this._model.KeyProperty.StorageName, cancellationToken).ConfigureAwait(false); return key; } ); @@ -160,7 +160,7 @@ public async Task> UpsertAsync(IEnumerable records, var storageModels = records.Select(record => VectorStoreErrorHandler.RunModelConversion( PostgresConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record))).ToList(); @@ -172,7 +172,7 @@ public async Task> UpsertAsync(IEnumerable records, var keys = storageModels.Select(model => model[this._model.KeyProperty.StorageName]!).ToList(); await this.RunOperationAsync(OperationName, () => - this._client.UpsertBatchAsync(this.CollectionName, storageModels, this._model.KeyProperty.StorageName, cancellationToken) + this._client.UpsertBatchAsync(this.Name, storageModels, this._model.KeyProperty.StorageName, cancellationToken) ).ConfigureAwait(false); return keys.Select(key => (TKey)key!).ToList(); @@ -189,13 +189,13 @@ await this.RunOperationAsync(OperationName, () => return this.RunOperationAsync(OperationName, async () => { - var row = await this._client.GetAsync(this.CollectionName, key, this._model, includeVectors, cancellationToken).ConfigureAwait(false); + var row = await this._client.GetAsync(this.Name, key, this._model, includeVectors, cancellationToken).ConfigureAwait(false); if (row is null) { return default; } return VectorStoreErrorHandler.RunModelConversion( PostgresConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(row, new() { IncludeVectors = includeVectors })); }); @@ -211,19 +211,19 @@ public IAsyncEnumerable GetAsync(IEnumerable keys, GetRecordOptio bool includeVectors = options?.IncludeVectors is true; return PostgresVectorStoreUtils.WrapAsyncEnumerableAsync( - this._client.GetBatchAsync(this.CollectionName, keys, this._model, includeVectors, cancellationToken) + this._client.GetBatchAsync(this.Name, keys, this._model, includeVectors, cancellationToken) .SelectAsync(row => VectorStoreErrorHandler.RunModelConversion( PostgresConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(row, new() { IncludeVectors = includeVectors })), cancellationToken ), OperationName, this._collectionMetadata.VectorStoreName, - this.CollectionName + this.Name ); } @@ -232,7 +232,7 @@ public Task DeleteAsync(TKey key, CancellationToken cancellationToken = default) { const string OperationName = "Delete"; return this.RunOperationAsync(OperationName, () => - this._client.DeleteAsync(this.CollectionName, this._model.KeyProperty.StorageName, key, cancellationToken) + this._client.DeleteAsync(this.Name, this._model.KeyProperty.StorageName, key, cancellationToken) ); } @@ -243,7 +243,7 @@ public Task DeleteAsync(IEnumerable keys, CancellationToken cancellationTo const string OperationName = "DeleteBatch"; return this.RunOperationAsync(OperationName, () => - this._client.DeleteBatchAsync(this.CollectionName, this._model.KeyProperty.StorageName, keys, cancellationToken) + this._client.DeleteBatchAsync(this.Name, this._model.KeyProperty.StorageName, keys, cancellationToken) ); } @@ -278,13 +278,13 @@ public IAsyncEnumerable> VectorizedSearchAsync { var record = VectorStoreErrorHandler.RunModelConversion( PostgresConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(result.Row, mapperOptions)); @@ -292,7 +292,7 @@ public IAsyncEnumerable> VectorizedSearchAsync GetAsync(Expression> filter StorageToDataModelMapperOptions mapperOptions = new() { IncludeVectors = options.IncludeVectors }; return PostgresVectorStoreUtils.WrapAsyncEnumerableAsync( - this._client.GetMatchingRecordsAsync(this.CollectionName, this._model, filter, top, options, cancellationToken) + this._client.GetMatchingRecordsAsync(this.Name, this._model, filter, top, options, cancellationToken) .SelectAsync(dictionary => { return VectorStoreErrorHandler.RunModelConversion( PostgresConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, "Get", () => this._mapper.MapFromStorageToDataModel(dictionary, mapperOptions)); }, cancellationToken), "Get", this._collectionMetadata.VectorStoreName, - this.CollectionName); + this.Name); } /// @@ -338,7 +338,7 @@ public IAsyncEnumerable GetAsync(Expression> filter private Task InternalCreateCollectionAsync(bool ifNotExists, CancellationToken cancellationToken = default) { - return this._client.CreateTableAsync(this.CollectionName, this._model, ifNotExists, cancellationToken); + return this._client.CreateTableAsync(this.Name, this._model, ifNotExists, cancellationToken); } private async Task RunOperationAsync(string operationName, Func operation) @@ -353,7 +353,7 @@ private async Task RunOperationAsync(string operationName, Func operation) { VectorStoreSystemName = PostgresConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -371,7 +371,7 @@ private async Task RunOperationAsync(string operationName, Func> o { VectorStoreSystemName = PostgresConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } diff --git a/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorStoreRecordCollection.cs index 91aeb02b170d..101a907805f1 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorStoreRecordCollection.cs @@ -62,12 +62,12 @@ public sealed class QdrantVectorStoreRecordCollection : IVectorSt /// Initializes a new instance of the class. /// /// Qdrant client that can be used to manage the collections and points in a Qdrant store. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. /// Thrown if the is null. /// Thrown for any misconfigured options. - public QdrantVectorStoreRecordCollection(QdrantClient qdrantClient, string collectionName, QdrantVectorStoreRecordCollectionOptions? options = null) - : this(new MockableQdrantClient(qdrantClient), collectionName, options) + public QdrantVectorStoreRecordCollection(QdrantClient qdrantClient, string name, QdrantVectorStoreRecordCollectionOptions? options = null) + : this(new MockableQdrantClient(qdrantClient), name, options) { } @@ -75,15 +75,15 @@ public QdrantVectorStoreRecordCollection(QdrantClient qdrantClient, string colle /// Initializes a new instance of the class. /// /// Qdrant client that can be used to manage the collections and points in a Qdrant store. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. /// Thrown if the is null. /// Thrown for any misconfigured options. - internal QdrantVectorStoreRecordCollection(MockableQdrantClient qdrantClient, string collectionName, QdrantVectorStoreRecordCollectionOptions? options = null) + internal QdrantVectorStoreRecordCollection(MockableQdrantClient qdrantClient, string name, QdrantVectorStoreRecordCollectionOptions? options = null) { // Verify. Verify.NotNull(qdrantClient); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(ulong) && typeof(TKey) != typeof(Guid) && typeof(TKey) != typeof(object)) { @@ -92,7 +92,7 @@ internal QdrantVectorStoreRecordCollection(MockableQdrantClient qdrantClient, st // Assign. this._qdrantClient = qdrantClient; - this._collectionName = collectionName; + this._collectionName = name; this._options = options ?? new QdrantVectorStoreRecordCollectionOptions(); this._model = new VectorStoreRecordModelBuilder(QdrantVectorStoreRecordFieldMapping.GetModelBuildOptions(this._options.HasNamedVectors)) @@ -103,12 +103,12 @@ internal QdrantVectorStoreRecordCollection(MockableQdrantClient qdrantClient, st this._collectionMetadata = new() { VectorStoreSystemName = QdrantConstants.VectorStoreSystemName, - CollectionName = collectionName + CollectionName = name }; } /// - public string CollectionName => this._collectionName; + public string Name => this._collectionName; /// public Task CollectionExistsAsync(CancellationToken cancellationToken = default) @@ -511,7 +511,7 @@ public async IAsyncEnumerable> VectorizedSearchAsync var points = await this.RunOperationAsync( "Query", () => this._qdrantClient.QueryAsync( - this.CollectionName, + this.Name, query: query, usingVector: this._options.HasNamedVectors ? vectorProperty.StorageName : null, filter: filter, @@ -570,7 +570,7 @@ public async IAsyncEnumerable GetAsync(Expression> var scrollResponse = await this.RunOperationAsync( "Scroll", () => this._qdrantClient.ScrollAsync( - this.CollectionName, + this.Name, translatedFilter, vectorsSelector, limit: (uint)(top + options.Skip), @@ -657,7 +657,7 @@ public async IAsyncEnumerable> HybridSearchAsync this._qdrantClient.QueryAsync( - this.CollectionName, + this.Name, prefetch: new List() { vectorQuery, keywordQuery }, query: fusionQuery, limit: (ulong)top, diff --git a/dotnet/src/Connectors/Connectors.Memory.Redis/RedisHashSetVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Redis/RedisHashSetVectorStoreRecordCollection.cs index 219a865cc12c..53000a1dcbb1 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Redis/RedisHashSetVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Redis/RedisHashSetVectorStoreRecordCollection.cs @@ -93,14 +93,14 @@ public sealed class RedisHashSetVectorStoreRecordCollection : IVe /// Initializes a new instance of the class. /// /// The Redis database to read/write records from. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. /// Throw when parameters are invalid. - public RedisHashSetVectorStoreRecordCollection(IDatabase database, string collectionName, RedisHashSetVectorStoreRecordCollectionOptions? options = null) + public RedisHashSetVectorStoreRecordCollection(IDatabase database, string name, RedisHashSetVectorStoreRecordCollectionOptions? options = null) { // Verify. Verify.NotNull(database); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object)) { @@ -109,7 +109,7 @@ public RedisHashSetVectorStoreRecordCollection(IDatabase database, string collec // Assign. this._database = database; - this._collectionName = collectionName; + this._collectionName = name; this._options = options ?? new RedisHashSetVectorStoreRecordCollectionOptions(); this._model = new VectorStoreRecordModelBuilder(ModelBuildingOptions).Build(typeof(TRecord), this._options.VectorStoreRecordDefinition); @@ -124,12 +124,12 @@ public RedisHashSetVectorStoreRecordCollection(IDatabase database, string collec { VectorStoreSystemName = RedisConstants.VectorStoreSystemName, VectorStoreName = database.Database.ToString(), - CollectionName = collectionName + CollectionName = name }; } /// - public string CollectionName => this._collectionName; + public string Name => this._collectionName; /// public async Task CollectionExistsAsync(CancellationToken cancellationToken = default) diff --git a/dotnet/src/Connectors/Connectors.Memory.Redis/RedisJsonVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Redis/RedisJsonVectorStoreRecordCollection.cs index 097095953866..0c79dd5d65e9 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Redis/RedisJsonVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Redis/RedisJsonVectorStoreRecordCollection.cs @@ -84,14 +84,14 @@ public sealed class RedisJsonVectorStoreRecordCollection : IVecto /// Initializes a new instance of the class. /// /// The Redis database to read/write records from. - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. /// Throw when parameters are invalid. - public RedisJsonVectorStoreRecordCollection(IDatabase database, string collectionName, RedisJsonVectorStoreRecordCollectionOptions? options = null) + public RedisJsonVectorStoreRecordCollection(IDatabase database, string name, RedisJsonVectorStoreRecordCollectionOptions? options = null) { // Verify. Verify.NotNull(database); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object)) { @@ -100,7 +100,7 @@ public RedisJsonVectorStoreRecordCollection(IDatabase database, string collectio // Assign. this._database = database; - this._collectionName = collectionName; + this._collectionName = name; this._options = options ?? new RedisJsonVectorStoreRecordCollectionOptions(); this._jsonSerializerOptions = this._options.JsonSerializerOptions ?? JsonSerializerOptions.Default; this._model = new VectorStoreRecordJsonModelBuilder(ModelBuildingOptions) @@ -118,12 +118,12 @@ public RedisJsonVectorStoreRecordCollection(IDatabase database, string collectio { VectorStoreSystemName = RedisConstants.VectorStoreSystemName, VectorStoreName = database.Database.ToString(), - CollectionName = collectionName + CollectionName = name }; } /// - public string CollectionName => this._collectionName; + public string Name => this._collectionName; /// public async Task CollectionExistsAsync(CancellationToken cancellationToken = default) diff --git a/dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerVectorStoreRecordCollection.cs index 9036cddd2575..6d20ef10d89c 100644 --- a/dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.SqlServer/SqlServerVectorStoreRecordCollection.cs @@ -52,7 +52,7 @@ public SqlServerVectorStoreRecordCollection( .Build(typeof(TRecord), options?.RecordDefinition); this._connectionString = connectionString; - this.CollectionName = name; + this.Name = name; // We need to create a copy, so any changes made to the option bag after // the ctor call do not affect this instance. this._options = options is null @@ -75,14 +75,14 @@ public SqlServerVectorStoreRecordCollection( } /// - public string CollectionName { get; } + public string Name { get; } /// public async Task CollectionExistsAsync(CancellationToken cancellationToken = default) { using SqlConnection connection = new(this._connectionString); using SqlCommand command = SqlServerCommandBuilder.SelectTableName( - connection, this._options.Schema, this.CollectionName); + connection, this._options.Schema, this.Name); return await ExceptionWrapper.WrapAsync(connection, command, static async (cmd, ct) => @@ -92,7 +92,7 @@ static async (cmd, ct) => }, "CollectionExists", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); } @@ -110,7 +110,7 @@ private async Task CreateCollectionAsync(bool ifNotExists, CancellationToken can using SqlCommand command = SqlServerCommandBuilder.CreateTable( connection, this._options.Schema, - this.CollectionName, + this.Name, ifNotExists, this._model); @@ -118,7 +118,7 @@ await ExceptionWrapper.WrapAsync(connection, command, static (cmd, ct) => cmd.ExecuteNonQueryAsync(ct), "CreateCollection", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); } @@ -127,13 +127,13 @@ public async Task DeleteCollectionAsync(CancellationToken cancellationToken = de { using SqlConnection connection = new(this._connectionString); using SqlCommand command = SqlServerCommandBuilder.DropTableIfExists( - connection, this._options.Schema, this.CollectionName); + connection, this._options.Schema, this.Name); await ExceptionWrapper.WrapAsync(connection, command, static (cmd, ct) => cmd.ExecuteNonQueryAsync(ct), "DeleteCollection", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); } @@ -146,7 +146,7 @@ public async Task DeleteAsync(TKey key, CancellationToken cancellationToken = de using SqlCommand command = SqlServerCommandBuilder.DeleteSingle( connection, this._options.Schema, - this.CollectionName, + this.Name, this._model.KeyProperty, key); @@ -154,7 +154,7 @@ await ExceptionWrapper.WrapAsync(connection, command, static (cmd, ct) => cmd.ExecuteNonQueryAsync(ct), "Delete", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); } @@ -183,7 +183,7 @@ public async Task DeleteAsync(IEnumerable keys, CancellationToken cancella if (!SqlServerCommandBuilder.DeleteMany( command, this._options.Schema, - this.CollectionName, + this.Name, this._model.KeyProperty, keys.Skip(taken).Take(SqlServerConstants.MaxParameterCount))) { @@ -220,7 +220,7 @@ public async Task DeleteAsync(IEnumerable keys, CancellationToken cancella { VectorStoreSystemName = SqlServerConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = "DeleteBatch" }; } @@ -237,7 +237,7 @@ public async Task DeleteAsync(IEnumerable keys, CancellationToken cancella using SqlCommand command = SqlServerCommandBuilder.SelectSingle( connection, this._options.Schema, - this.CollectionName, + this.Name, this._model, key, includeVectors); @@ -251,7 +251,7 @@ static async (cmd, ct) => }, "Get", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); return reader.HasRows @@ -283,7 +283,7 @@ public async IAsyncEnumerable GetAsync(IEnumerable keys, GetRecor if (!SqlServerCommandBuilder.SelectMany( command, this._options.Schema, - this.CollectionName, + this.Name, this._model, keys.Skip(taken).Take(SqlServerConstants.MaxParameterCount), includeVectors)) @@ -300,14 +300,14 @@ public async IAsyncEnumerable GetAsync(IEnumerable keys, GetRecor static (cmd, ct) => cmd.ExecuteReaderAsync(ct), "GetBatch", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); while (await ExceptionWrapper.WrapReadAsync( reader, "GetBatch", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false)) { yield return this._mapper.MapFromStorageToDataModel( @@ -326,7 +326,7 @@ public async Task UpsertAsync(TRecord record, CancellationToken cancellati using SqlCommand command = SqlServerCommandBuilder.MergeIntoSingle( connection, this._options.Schema, - this.CollectionName, + this.Name, this._model, this._mapper.MapFromDataToStorageModel(record)); @@ -339,7 +339,7 @@ async static (cmd, ct) => }, "Upsert", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); } @@ -369,7 +369,7 @@ public async Task> UpsertAsync(IEnumerable records, if (!SqlServerCommandBuilder.MergeIntoMany( command, this._options.Schema, - this.CollectionName, + this.Name, this._model, records.Skip(taken) .Take(SqlServerConstants.MaxParameterCount / parametersPerRecord) @@ -408,7 +408,7 @@ public async Task> UpsertAsync(IEnumerable records, { VectorStoreSystemName = SqlServerConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = "UpsertBatch" }; } @@ -447,7 +447,7 @@ public IAsyncEnumerable> VectorizedSearchAsync> ReadVectorSearchResu static (cmd, ct) => cmd.ExecuteReaderAsync(ct), "VectorizedSearch", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false); int scoreIndex = -1; @@ -493,7 +493,7 @@ private async IAsyncEnumerable> ReadVectorSearchResu reader, "VectorizedSearch", this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, cancellationToken).ConfigureAwait(false)) { if (scoreIndex < 0) @@ -529,12 +529,12 @@ public async IAsyncEnumerable GetAsync(Expression> options, connection, this._options.Schema, - this.CollectionName, + this.Name, this._model); using SqlDataReader reader = await ExceptionWrapper.WrapAsync(connection, command, static (cmd, ct) => cmd.ExecuteReaderAsync(ct), - "GetAsync", this._collectionMetadata.VectorStoreName, this.CollectionName, cancellationToken).ConfigureAwait(false); + "GetAsync", this._collectionMetadata.VectorStoreName, this.Name, cancellationToken).ConfigureAwait(false); var vectorProperties = options.IncludeVectors ? this._model.VectorProperties : []; StorageToDataModelMapperOptions mapperOptions = new() { IncludeVectors = options.IncludeVectors }; diff --git a/dotnet/src/Connectors/Connectors.Memory.Sqlite/SqliteVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Sqlite/SqliteVectorStoreRecordCollection.cs index 4006d5c21006..1d1a044f6eb5 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Sqlite/SqliteVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Sqlite/SqliteVectorStoreRecordCollection.cs @@ -72,22 +72,22 @@ public sealed class SqliteVectorStoreRecordCollection : IVectorSt private readonly string _vectorSearchExtensionName; /// - public string CollectionName { get; } + public string Name { get; } /// /// Initializes a new instance of the class. /// /// The connection string for the SQLite database represented by this . - /// The name of the collection/table that this will access. + /// The name of the collection/table that this will access. /// Optional configuration options for this class. public SqliteVectorStoreRecordCollection( string connectionString, - string collectionName, + string name, SqliteVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(connectionString); - Verify.NotNullOrWhiteSpace(collectionName); + Verify.NotNullOrWhiteSpace(name); if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(ulong) && typeof(TKey) != typeof(object)) { @@ -96,11 +96,11 @@ public SqliteVectorStoreRecordCollection( // Assign. this._connectionString = connectionString; - this.CollectionName = collectionName; + this.Name = name; this._options = options ?? new(); this._vectorSearchExtensionName = this._options.VectorSearchExtensionName ?? SqliteConstants.VectorSearchExtensionName; - this._dataTableName = this.CollectionName; + this._dataTableName = this.Name; this._vectorTableName = GetVectorTableName(this._dataTableName, this._options); this._model = new VectorStoreRecordModelBuilder(SqliteConstants.ModelBuildingOptions) @@ -144,7 +144,7 @@ public SqliteVectorStoreRecordCollection( { VectorStoreSystemName = SqliteConstants.VectorStoreSystemName, VectorStoreName = connectionStringBuilder.DataSource, - CollectionName = collectionName + CollectionName = name }; } @@ -347,7 +347,7 @@ public async Task UpsertAsync(TRecord record, CancellationToken cancellati var storageModel = VectorStoreErrorHandler.RunModelConversion( SqliteConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record)); @@ -373,7 +373,7 @@ public async Task> UpsertAsync(IEnumerable records, var storageModels = records.Select(record => VectorStoreErrorHandler.RunModelConversion( SqliteConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record))).ToList(); @@ -687,7 +687,7 @@ private TRecord GetAndMapRecord( return VectorStoreErrorHandler.RunModelConversion( SqliteConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, operationName, () => this._mapper.MapFromStorageToDataModel(storageModel, new() { IncludeVectors = includeVectors })); } @@ -704,7 +704,7 @@ private async Task RunOperationAsync(string operationName, Func> o { VectorStoreSystemName = SqliteConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } diff --git a/dotnet/src/Connectors/Connectors.Memory.Weaviate/WeaviateVectorStoreRecordCollection.cs b/dotnet/src/Connectors/Connectors.Memory.Weaviate/WeaviateVectorStoreRecordCollection.cs index 49a07cad043e..7275b1b5e08b 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Weaviate/WeaviateVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Weaviate/WeaviateVectorStoreRecordCollection.cs @@ -68,7 +68,7 @@ public sealed class WeaviateVectorStoreRecordCollection : IVector private readonly string? _apiKey; /// - public string CollectionName { get; } + public string Name { get; } /// /// Initializes a new instance of the class. @@ -78,17 +78,17 @@ public sealed class WeaviateVectorStoreRecordCollection : IVector /// should point to remote or local cluster and API key can be configured via . /// It's also possible to provide these parameters via . /// - /// The name of the collection that this will access. + /// The name of the collection that this will access. /// Optional configuration options for this class. /// The collection name must start with a capital letter and contain only ASCII letters and digits. public WeaviateVectorStoreRecordCollection( HttpClient httpClient, - string collectionName, + string name, WeaviateVectorStoreRecordCollectionOptions? options = default) { // Verify. Verify.NotNull(httpClient); - VerifyCollectionName(collectionName); + VerifyCollectionName(name); if (typeof(TKey) != typeof(Guid) && typeof(TKey) != typeof(object)) { @@ -100,20 +100,20 @@ public WeaviateVectorStoreRecordCollection( // Assign. this._httpClient = httpClient; this._endpoint = endpoint; - this.CollectionName = collectionName; + this.Name = name; this._options = options ?? new(); this._apiKey = this._options.ApiKey; this._model = new WeaviateModelBuilder().Build(typeof(TRecord), this._options.VectorStoreRecordDefinition, s_jsonSerializerOptions); // Assign mapper. this._mapper = typeof(TRecord) == typeof(Dictionary) - ? (new WeaviateDynamicDataModelMapper(this.CollectionName, this._model, s_jsonSerializerOptions) as IWeaviateMapper)! - : new WeaviateVectorStoreRecordMapper(this.CollectionName, this._model, s_jsonSerializerOptions); + ? (new WeaviateDynamicDataModelMapper(this.Name, this._model, s_jsonSerializerOptions) as IWeaviateMapper)! + : new WeaviateVectorStoreRecordMapper(this.Name, this._model, s_jsonSerializerOptions); this._collectionMetadata = new() { VectorStoreSystemName = WeaviateConstants.VectorStoreSystemName, - CollectionName = collectionName + CollectionName = name }; } @@ -124,7 +124,7 @@ public Task CollectionExistsAsync(CancellationToken cancellationToken = de return this.RunOperationAsync(OperationName, async () => { - var request = new WeaviateGetCollectionSchemaRequest(this.CollectionName).Build(); + var request = new WeaviateGetCollectionSchemaRequest(this.Name).Build(); var response = await this .ExecuteRequestWithNotFoundHandlingAsync(request, cancellationToken) @@ -141,7 +141,7 @@ public Task CreateCollectionAsync(CancellationToken cancellationToken = default) return this.RunOperationAsync(OperationName, () => { - var schema = WeaviateVectorStoreCollectionCreateMapping.MapToSchema(this.CollectionName, this._model); + var schema = WeaviateVectorStoreCollectionCreateMapping.MapToSchema(this.Name, this._model); var request = new WeaviateCreateCollectionSchemaRequest(schema).Build(); @@ -165,7 +165,7 @@ public Task DeleteCollectionAsync(CancellationToken cancellationToken = default) return this.RunOperationAsync(OperationName, () => { - var request = new WeaviateDeleteCollectionSchemaRequest(this.CollectionName).Build(); + var request = new WeaviateDeleteCollectionSchemaRequest(this.Name).Build(); return this.ExecuteRequestAsync(request, cancellationToken); }); @@ -185,7 +185,7 @@ public Task DeleteAsync(TKey key, CancellationToken cancellationToken = default) _ => throw new UnreachableException("Guid key should have been validated during model building") }; - var request = new WeaviateDeleteObjectRequest(this.CollectionName, guid).Build(); + var request = new WeaviateDeleteObjectRequest(this.Name, guid).Build(); return this.ExecuteRequestAsync(request, cancellationToken); }); @@ -210,7 +210,7 @@ public Task DeleteAsync(IEnumerable keys, CancellationToken cancellationTo { var match = new WeaviateQueryMatch { - CollectionName = this.CollectionName, + CollectionName = this.Name, WhereClause = new WeaviateQueryMatchWhereClause { Operator = ContainsAnyOperator, @@ -240,7 +240,7 @@ public Task DeleteAsync(IEnumerable keys, CancellationToken cancellationTo }; var includeVectors = options?.IncludeVectors is true; - var request = new WeaviateGetCollectionObjectRequest(this.CollectionName, guid, includeVectors).Build(); + var request = new WeaviateGetCollectionObjectRequest(this.Name, guid, includeVectors).Build(); var jsonObject = await this.ExecuteRequestWithNotFoundHandlingAsync(request, cancellationToken).ConfigureAwait(false); @@ -252,7 +252,7 @@ public Task DeleteAsync(IEnumerable keys, CancellationToken cancellationTo return VectorStoreErrorHandler.RunModelConversion( WeaviateConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromStorageToDataModel(jsonObject!, new() { IncludeVectors = includeVectors })); }); @@ -297,7 +297,7 @@ public async Task> UpsertAsync(IEnumerable records, var jsonObjects = records.Select(record => VectorStoreErrorHandler.RunModelConversion( WeaviateConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, OperationName, () => this._mapper.MapFromDataToStorageModel(record))).ToList(); @@ -346,7 +346,7 @@ public IAsyncEnumerable> VectorizedSearchAsync GetAsync(Expression> filter filter, top, options, - this.CollectionName, + this.Name, this._model); return this.ExecuteQueryAsync(query, options.IncludeVectors, WeaviateConstants.ScorePropertyName, "GetAsync", cancellationToken) @@ -392,7 +392,7 @@ public IAsyncEnumerable> HybridSearchAsync( vector, top, string.Join(" ", keywords), - this.CollectionName, + this.Name, this._model, vectorProperty, textDataProperty, @@ -423,7 +423,7 @@ private async IAsyncEnumerable> ExecuteQueryAsync(st var (responseModel, content) = await this.ExecuteRequestWithResponseContentAsync(request, cancellationToken).ConfigureAwait(false); - var collectionResults = responseModel?.Data?.GetOperation?[this.CollectionName]; + var collectionResults = responseModel?.Data?.GetOperation?[this.Name]; if (collectionResults is null) { @@ -431,7 +431,7 @@ private async IAsyncEnumerable> ExecuteQueryAsync(st { VectorStoreSystemName = WeaviateConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } @@ -445,7 +445,7 @@ private async IAsyncEnumerable> ExecuteQueryAsync(st var record = VectorStoreErrorHandler.RunModelConversion( WeaviateConstants.VectorStoreSystemName, this._collectionMetadata.VectorStoreName, - this.CollectionName, + this.Name, operationName, () => this._mapper.MapFromStorageToDataModel(storageModel, new() { IncludeVectors = includeVectors })); @@ -510,7 +510,7 @@ private async Task RunOperationAsync(string operationName, Func> o { VectorStoreSystemName = WeaviateConstants.VectorStoreSystemName, VectorStoreName = this._collectionMetadata.VectorStoreName, - CollectionName = this.CollectionName, + CollectionName = this.Name, OperationName = operationName }; } diff --git a/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/IVectorStoreRecordCollection.cs b/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/IVectorStoreRecordCollection.cs index 97e898fd7b56..84acae5bb6d2 100644 --- a/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/IVectorStoreRecordCollection.cs +++ b/dotnet/src/Connectors/VectorData.Abstractions/VectorStorage/IVectorStoreRecordCollection.cs @@ -25,7 +25,7 @@ public interface IVectorStoreRecordCollection : IVectorizedSearch /// /// Gets the name of the collection. /// - string CollectionName { get; } + string Name { get; } /// /// Checks if the collection exists in the vector store.