Skip to content

.Net: [MEVD] Added GetRequiredService and renamed CollectionName #11573

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
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 @@ -49,7 +49,7 @@ public TextEmbeddingVectorStoreRecordCollection(IVectorStoreRecordCollection<TKe
}

/// <inheritdoc />
public string CollectionName => this._decoratedVectorStoreRecordCollection.CollectionName;
public string Name => this._decoratedVectorStoreRecordCollection.Name;

/// <inheritdoc />
public Task<bool> CollectionExistsAsync(CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public sealed class AzureAISearchVectorStoreRecordCollection<TKey, TRecord> :
/// Initializes a new instance of the <see cref="AzureAISearchVectorStoreRecordCollection{TKey, TRecord}"/> class.
/// </summary>
/// <param name="searchIndexClient">Azure AI Search client that can be used to manage the list of indices in an Azure AI Search Service.</param>
/// <param name="collectionName">The name of the collection that this <see cref="AzureAISearchVectorStoreRecordCollection{TKey, TRecord}"/> will access.</param>
/// <param name="name">The name of the collection that this <see cref="AzureAISearchVectorStoreRecordCollection{TKey, TRecord}"/> will access.</param>
/// <param name="options">Optional configuration options for this class.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="searchIndexClient"/> is null.</exception>
/// <exception cref="ArgumentException">Thrown when options are misconfigured.</exception>
public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexClient, string collectionName, AzureAISearchVectorStoreRecordCollectionOptions<TRecord>? options = default)
public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexClient, string name, AzureAISearchVectorStoreRecordCollectionOptions<TRecord>? options = default)
{
// Verify.
Verify.NotNull(searchIndexClient);
Verify.NotNullOrWhiteSpace(collectionName);
Verify.NotNullOrWhiteSpace(name);

if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object))
{
Expand All @@ -81,9 +81,9 @@ public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexCli

// Assign.
this._searchIndexClient = searchIndexClient;
this._collectionName = collectionName;
this._collectionName = name;
this._options = options ?? new AzureAISearchVectorStoreRecordCollectionOptions<TRecord>();
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);
Expand All @@ -100,12 +100,12 @@ public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexCli
{
VectorStoreSystemName = AzureAISearchConstants.VectorStoreSystemName,
VectorStoreName = searchIndexClient.ServiceName,
CollectionName = collectionName
CollectionName = name
};
}

/// <inheritdoc />
public string CollectionName => this._collectionName;
public string Name => this._collectionName;

/// <inheritdoc />
public async Task<bool> CollectionExistsAsync(CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ public sealed class AzureCosmosDBMongoDBVectorStoreRecordCollection<TKey, TRecor
private readonly VectorStoreRecordModel _model;

/// <inheritdoc />
public string CollectionName { get; }
public string Name { get; }

/// <summary>
/// Initializes a new instance of the <see cref="AzureCosmosDBMongoDBVectorStoreRecordCollection{TKey, TRecord}"/> class.
/// </summary>
/// <param name="mongoDatabase"><see cref="IMongoDatabase"/> that can be used to manage the collections in Azure CosmosDB MongoDB.</param>
/// <param name="collectionName">The name of the collection that this <see cref="AzureCosmosDBMongoDBVectorStoreRecordCollection{TKey, TRecord}"/> will access.</param>
/// <param name="name">The name of the collection that this <see cref="AzureCosmosDBMongoDBVectorStoreRecordCollection{TKey, TRecord}"/> will access.</param>
/// <param name="options">Optional configuration options for this class.</param>
public AzureCosmosDBMongoDBVectorStoreRecordCollection(
IMongoDatabase mongoDatabase,
string collectionName,
string name,
AzureCosmosDBMongoDBVectorStoreRecordCollectionOptions<TRecord>? options = default)
{
// Verify.
Verify.NotNull(mongoDatabase);
Verify.NotNullOrWhiteSpace(collectionName);
Verify.NotNullOrWhiteSpace(name);

if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(object))
{
Expand All @@ -82,8 +82,8 @@ public AzureCosmosDBMongoDBVectorStoreRecordCollection(

// Assign.
this._mongoDatabase = mongoDatabase;
this._mongoCollection = mongoDatabase.GetCollection<BsonDocument>(collectionName);
this.CollectionName = collectionName;
this._mongoCollection = mongoDatabase.GetCollection<BsonDocument>(name);
this.Name = name;
this._options = options ?? new AzureCosmosDBMongoDBVectorStoreRecordCollectionOptions<TRecord>();
this._model = new MongoDBModelBuilder().Build(typeof(TRecord), this._options.VectorStoreRecordDefinition);
this._mapper = typeof(TRecord) == typeof(Dictionary<string, object?>)
Expand All @@ -94,7 +94,7 @@ public AzureCosmosDBMongoDBVectorStoreRecordCollection(
{
VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
VectorStoreName = mongoDatabase.DatabaseNamespace?.DatabaseName,
CollectionName = collectionName
CollectionName = name
};
}

Expand All @@ -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"
};
}
Expand All @@ -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);
}

/// <inheritdoc />
Expand All @@ -153,7 +153,7 @@ await this.RunOperationAsync("DeleteMany", () => this._mongoCollection.DeleteMan

/// <inheritdoc />
public Task DeleteCollectionAsync(CancellationToken cancellationToken = default)
=> this.RunOperationAsync("DropCollection", () => this._mongoDatabase.DropCollectionAsync(this.CollectionName, cancellationToken));
=> this.RunOperationAsync("DropCollection", () => this._mongoDatabase.DropCollectionAsync(this.Name, cancellationToken));

/// <inheritdoc />
public async Task<TRecord?> GetAsync(TKey key, GetRecordOptions? options = null, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -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 }));
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public async IAsyncEnumerable<TRecord> GetAsync(
yield return VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
OperationName,
() => this._mapper.MapFromStorageToDataModel(record, new()));
}
Expand All @@ -230,7 +230,7 @@ public Task<TKey> UpsertAsync(TRecord record, CancellationToken cancellationToke
var storageModel = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
OperationName,
() => this._mapper.MapFromDataToStorageModel(record));

Expand Down Expand Up @@ -391,7 +391,7 @@ public async IAsyncEnumerable<TRecord> GetAsync(Expression<Func<TRecord, bool>>
var record = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
"GetAsync",
() => this._mapper.MapFromStorageToDataModel(response, new() { IncludeVectors = options.IncludeVectors }));

Expand Down Expand Up @@ -475,7 +475,7 @@ private async IAsyncEnumerable<VectorSearchResult<TRecord>> EnumerateAndMapSearc
var record = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
OperationName,
() => this._mapper.MapFromStorageToDataModel(response[DocumentPropertyName].AsBsonDocument, new()));

Expand All @@ -495,7 +495,7 @@ private FilterDefinition<BsonDocument> GetFilterByIds(IEnumerable<string> ids)

private async Task<bool> 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);
Expand All @@ -515,7 +515,7 @@ private async Task RunOperationAsync(string operationName, Func<Task> operation)
{
VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
VectorStoreName = this._collectionMetadata.VectorStoreName,
CollectionName = this.CollectionName,
CollectionName = this.Name,
OperationName = operationName
};
}
Expand All @@ -533,7 +533,7 @@ private async Task<T> RunOperationAsync<T>(string operationName, Func<Task<T>> o
{
VectorStoreSystemName = AzureCosmosDBMongoDBConstants.VectorStoreSystemName,
VectorStoreName = this._collectionMetadata.VectorStoreName,
CollectionName = this.CollectionName,
CollectionName = this.Name,
OperationName = operationName
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ public sealed class AzureCosmosDBNoSQLVectorStoreRecordCollection<TKey, TRecord>
private readonly ICosmosNoSQLMapper<TRecord> _mapper;

/// <inheritdoc />
public string CollectionName { get; }
public string Name { get; }

/// <summary>
/// Initializes a new instance of the <see cref="AzureCosmosDBNoSQLVectorStoreRecordCollection{TKey, TRecord}"/> class.
/// </summary>
/// <param name="database"><see cref="Database"/> that can be used to manage the collections in Azure CosmosDB NoSQL.</param>
/// <param name="collectionName">The name of the collection that this <see cref="AzureCosmosDBNoSQLVectorStoreRecordCollection{TKey, TRecord}"/> will access.</param>
/// <param name="name">The name of the collection that this <see cref="AzureCosmosDBNoSQLVectorStoreRecordCollection{TKey, TRecord}"/> will access.</param>
/// <param name="options">Optional configuration options for this class.</param>
public AzureCosmosDBNoSQLVectorStoreRecordCollection(
Database database,
string collectionName,
string name,
AzureCosmosDBNoSQLVectorStoreRecordCollectionOptions<TRecord>? 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))
{
Expand All @@ -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()
Expand Down Expand Up @@ -124,7 +124,7 @@ public AzureCosmosDBNoSQLVectorStoreRecordCollection(
{
VectorStoreSystemName = AzureCosmosDBNoSQLConstants.VectorStoreSystemName,
VectorStoreName = database.Id,
CollectionName = collectionName
CollectionName = name
};
}

Expand All @@ -135,7 +135,7 @@ public Task<bool> 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<string>(queryDefinition);

Expand Down Expand Up @@ -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));
}

Expand All @@ -194,7 +194,7 @@ public async Task DeleteAsync(IEnumerable<TKey> keys, CancellationToken cancella

return this.RunOperationAsync("DeleteItem", () =>
this._database
.GetContainer(this.CollectionName)
.GetContainer(this.Name)
.DeleteItemAsync<JsonObject>(key.RecordKey, new PartitionKey(key.PartitionKey), cancellationToken: cancellationToken));
});

Expand Down Expand Up @@ -233,7 +233,7 @@ public async IAsyncEnumerable<TRecord> GetAsync(
var record = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBNoSQLConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
OperationName,
() => this._mapper.MapFromStorageToDataModel(jsonObject, new() { IncludeVectors = includeVectors }));

Expand All @@ -254,7 +254,7 @@ public async Task<TKey> UpsertAsync(TRecord record, CancellationToken cancellati
var jsonObject = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBNoSQLConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
OperationName,
() => this._mapper.MapFromDataToStorageModel(record));

Expand All @@ -273,7 +273,7 @@ public async Task<TKey> 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);

Expand Down Expand Up @@ -361,7 +361,7 @@ public async IAsyncEnumerable<TRecord> GetAsync(Expression<Func<TRecord, bool>>
var record = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBNoSQLConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
"GetAsync",
() => this._mapper.MapFromStorageToDataModel(jsonObject, new() { IncludeVectors = options.IncludeVectors }));

Expand Down Expand Up @@ -447,7 +447,7 @@ private async Task<T> RunOperationAsync<T>(string operationName, Func<Task<T>> o
{
VectorStoreSystemName = AzureCosmosDBNoSQLConstants.VectorStoreSystemName,
VectorStoreName = this._collectionMetadata.VectorStoreName,
CollectionName = this.CollectionName,
CollectionName = this.Name,
OperationName = operationName
};
}
Expand All @@ -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
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -583,7 +583,7 @@ private static VectorDataType GetDataType(Type vectorDataType, string vectorProp
private async IAsyncEnumerable<T> GetItemsAsync<T>(QueryDefinition queryDefinition, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var iterator = this._database
.GetContainer(this.CollectionName)
.GetContainer(this.Name)
.GetItemQueryIterator<T>(queryDefinition);

while (iterator.HasMoreResults)
Expand Down Expand Up @@ -617,7 +617,7 @@ private async IAsyncEnumerable<VectorSearchResult<TRecord>> MapSearchResultsAsyn
var record = VectorStoreErrorHandler.RunModelConversion(
AzureCosmosDBNoSQLConstants.VectorStoreSystemName,
this._collectionMetadata.VectorStoreName,
this.CollectionName,
this.Name,
operationName,
() => this._mapper.MapFromStorageToDataModel(jsonObject, new() { IncludeVectors = includeVectors }));

Expand Down
Loading
Loading