Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CommunityToolkit.AI.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Folder Name="/MEVD/src/">
<File Path="MEVD/src/Directory.Build.props" />
<Project Path="MEVD/src/AzureAISearch/AzureAISearch.csproj" />
<Project Path="MEVD/src/CosmosNoSql/CosmosNoSql.csproj" />
<Project Path="MEVD/src/AzureCosmosDB/AzureCosmosDB.csproj" />
<Project Path="MEVD/src/AzureDocumentDB/AzureDocumentDB.csproj" />
<Project Path="MEVD/src/InMemory/InMemory.csproj" />
<Project Path="MEVD/src/PgVector/PgVector.csproj" />
Expand All @@ -23,8 +23,8 @@
<File Path="MEVD/test/Directory.Build.props" />
<Project Path="MEVD/test/AzureAISearch.UnitTests/AzureAISearch.UnitTests.csproj" />
<Project Path="MEVD/test/AzureAISearch.ConformanceTests/AzureAISearch.ConformanceTests.csproj" />
<Project Path="MEVD/test/CosmosNoSql.UnitTests/CosmosNoSql.UnitTests.csproj" />
<Project Path="MEVD/test/CosmosNoSql.ConformanceTests/CosmosNoSql.ConformanceTests.csproj" />
<Project Path="MEVD/test/AzureCosmosDB.UnitTests/AzureCosmosDB.UnitTests.csproj" />
<Project Path="MEVD/test/AzureCosmosDB.ConformanceTests/AzureCosmosDB.ConformanceTests.csproj" />
<Project Path="MEVD/test/AzureDocumentDB.UnitTests/AzureDocumentDB.UnitTests.csproj" />
<Project Path="MEVD/test/AzureDocumentDB.ConformanceTests/AzureDocumentDB.ConformanceTests.csproj" />
<Project Path="MEVD/test/InMemory.UnitTests/InMemory.UnitTests.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions MEVD/MEVD.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"projects":
[
"MEVD/src/AzureAISearch/AzureAISearch.csproj",
"MEVD/src/CosmosNoSql/CosmosNoSql.csproj",
"MEVD/src/AzureCosmosDB/AzureCosmosDB.csproj",
"MEVD/src/AzureDocumentDB/AzureDocumentDB.csproj",
"MEVD/src/InMemory/InMemory.csproj",
"MEVD/src/PgVector/PgVector.csproj",
Expand All @@ -16,8 +16,8 @@

"MEVD/test/AzureAISearch.UnitTests/AzureAISearch.UnitTests.csproj",
"MEVD/test/AzureAISearch.ConformanceTests/AzureAISearch.ConformanceTests.csproj",
"MEVD/test/CosmosNoSql.UnitTests/CosmosNoSql.UnitTests.csproj",
"MEVD/test/CosmosNoSql.ConformanceTests/CosmosNoSql.ConformanceTests.csproj",
"MEVD/test/AzureCosmosDB.UnitTests/AzureCosmosDB.UnitTests.csproj",
"MEVD/test/AzureCosmosDB.ConformanceTests/AzureCosmosDB.ConformanceTests.csproj",
"MEVD/test/AzureDocumentDB.UnitTests/AzureDocumentDB.UnitTests.csproj",
"MEVD/test/AzureDocumentDB.ConformanceTests/AzureDocumentDB.ConformanceTests.csproj",
"MEVD/test/InMemory.UnitTests/InMemory.UnitTests.csproj",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<AssemblyName>CommunityToolkit.VectorData.CosmosNoSql</AssemblyName>
<AssemblyName>CommunityToolkit.VectorData.AzureCosmosDB</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFrameworks>net10.0;net8.0;netstandard2.0;net462</TargetFrameworks>

<Title>Azure Cosmos DB for NoSQL provider for Microsoft.Extensions.VectorData</Title>
<Description>Azure Cosmos DB for NoSQL provider for Microsoft.Extensions.VectorData by the .NET Community Toolkit</Description>
<PackageTags>AzureCosmosDB;CosmosNoSql;VectorData</PackageTags>

<AzureCosmosDisableNewtonsoftJsonCheck>true</AzureCosmosDisableNewtonsoftJsonCheck>
</PropertyGroup>
Expand All @@ -20,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="CommunityToolkit.VectorData.CosmosNoSql.UnitTests" />
<InternalsVisibleTo Include="CommunityToolkit.VectorData.AzureCosmosDB.UnitTests" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

/// <summary>
/// A JSON converter for byte arrays that serializes them as JSON arrays of numbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading;
using Microsoft.Azure.Cosmos;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

internal sealed class ClientWrapper : IDisposable
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.VectorData;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

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

/// <summary>
/// Initializes a new instance of the <see cref="CosmosNoSqlCollectionOptions"/> class.
/// Initializes a new instance of the <see cref="CosmosCollectionOptions"/> class.
/// </summary>
public CosmosNoSqlCollectionOptions()
public CosmosCollectionOptions()
{
}

internal CosmosNoSqlCollectionOptions(CosmosNoSqlCollectionOptions? source) : base(source)
internal CosmosCollectionOptions(CosmosCollectionOptions? source) : base(source)
{
this.JsonSerializerOptions = source?.JsonSerializerOptions;
this.PartitionKeyProperties = source?.PartitionKeyProperties is null ? null : [.. source.PartitionKeyProperties];
Expand All @@ -31,7 +31,7 @@ internal CosmosNoSqlCollectionOptions(CosmosNoSqlCollectionOptions? source) : ba
}

/// <summary>
/// Gets or sets the JSON serializer options to use when converting between the data model and the Azure CosmosDB NoSQL record.
/// Gets or sets the JSON serializer options to use when converting between the data model and the Azure Cosmos NoSQL record.
/// </summary>
public JsonSerializerOptions? JsonSerializerOptions { get; set; }

Expand All @@ -47,7 +47,7 @@ internal CosmosNoSqlCollectionOptions(CosmosNoSqlCollectionOptions? source) : ba
/// When <see langword="null" /> (the default), the key property (document ID) is automatically used as the partition key - a common
/// Cosmos DB strategy; in this mode, the collection key type must be <see cref="string"/> or <see cref="System.Guid"/>.
/// To use a different partition key (or hierarchical partition keys), specify the key properties here and use
/// <see cref="CosmosNoSqlKey"/> as the key type.
/// <see cref="CosmosKey"/> as the key type.
/// </para>
/// </remarks>
public IReadOnlyList<string>? PartitionKeyProperties { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
using Microsoft.Extensions.VectorData.ProviderServices;
using Microsoft.Shared.Diagnostics;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

/// <summary>
/// Contains helpers to build queries for Azure CosmosDB NoSQL.
/// Contains helpers to build queries for Azure Cosmos NoSQL.
/// </summary>
internal static class CosmosNoSqlCollectionQueryBuilder
internal static class CosmosCollectionQueryBuilder
{
/// <summary>
/// Builds <see cref="QueryDefinition"/> to get items from Azure CosmosDB NoSQL using vector search.
/// Builds <see cref="QueryDefinition"/> to get items from Azure Cosmos NoSQL using vector search.
/// </summary>
public static QueryDefinition BuildSearchQuery<TRecord>(
object vector,
Expand All @@ -41,7 +41,7 @@ public static QueryDefinition BuildSearchQuery<TRecord>(
const string VectorVariableName = "@vector";
const string KeywordVariablePrefix = "@keyword";

var tableVariableName = CosmosNoSqlConstants.ContainerAlias;
var tableVariableName = CosmosConstants.ContainerAlias;

IEnumerable<PropertyModel> projectionProperties = model.Properties;
if (!includeVectors)
Expand All @@ -56,7 +56,7 @@ public static QueryDefinition BuildSearchQuery<TRecord>(

// Build filter object.
var (filterClause, filterParameters) = filter is not null
? new CosmosNoSqlFilterTranslator().Translate(filter, model)
? new CosmosFilterTranslator().Translate(filter, model)
: ((string?)null, new Dictionary<string, object?>());

var queryParameters = new Dictionary<string, object?>
Expand Down Expand Up @@ -162,7 +162,7 @@ internal static QueryDefinition BuildSearchQuery<TRecord>(
FilteredRecordRetrievalOptions<TRecord> filterOptions,
int top)
{
var tableVariableName = CosmosNoSqlConstants.ContainerAlias;
var tableVariableName = CosmosConstants.ContainerAlias;

IEnumerable<PropertyModel> projectionProperties = model.Properties;
if (!filterOptions.IncludeVectors)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

internal static class CosmosNoSqlConstants
internal static class CosmosConstants
{
internal const string VectorStoreSystemName = "azure.cosmosdbnosql";

/// <summary>
/// Reserved key property name in Azure CosmosDB NoSQL.
/// Reserved key property name in Azure Cosmos NoSQL.
/// </summary>
internal const string ReservedKeyPropertyName = "id";

/// <summary>
/// Variable name for table in Azure CosmosDB NoSQL queries.
/// Variable name for table in Azure Cosmos NoSQL queries.
/// Can be any string. Example: "SELECT x.Name FROM x".
/// </summary>
internal const char ContainerAlias = 'x';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
using Microsoft.Azure.Cosmos;
using Microsoft.Shared.Diagnostics;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

/// <summary>
/// Represents a collection of vector store records in a CosmosNoSql database, mapped to a dynamic <c>Dictionary&lt;string, object?&gt;</c>.
/// Represents a collection of vector store records in a Cosmos database, mapped to a dynamic <c>Dictionary&lt;string, object?&gt;</c>.
/// </summary>
/// <remarks>
/// <para>
/// This collection accepts keys of type <see cref="object"/>, but only <see cref="CosmosNoSqlKey"/> instances
/// This collection accepts keys of type <see cref="object"/>, but only <see cref="CosmosKey"/> instances
/// are supported at runtime. Passing any other key type will result in an <see cref="InvalidOperationException"/>.
/// </para>
/// </remarks>
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
public sealed class CosmosNoSqlDynamicCollection : CosmosNoSqlCollection<object, Dictionary<string, object?>>
public sealed class CosmosDynamicCollection : CosmosCollection<object, Dictionary<string, object?>>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <summary>
/// Initializes a new instance of the <see cref="CosmosNoSqlDynamicCollection"/> class.
/// Initializes a new instance of the <see cref="CosmosDynamicCollection"/> class.
/// </summary>
/// <param name="database"><see cref="Database"/> that can be used to manage the collections in Azure CosmosDB NoSQL.</param>
/// <param name="database"><see cref="Database"/> that can be used to manage the collections in Azure Cosmos NoSQL.</param>
/// <param name="name">The name of the collection.</param>
/// <param name="options">Optional configuration options for this class.</param>
[RequiresUnreferencedCode("The Cosmos NoSQL provider is currently incompatible with trimming.")]
[RequiresDynamicCode("The Cosmos NoSQL provider is currently incompatible with NativeAOT.")]
public CosmosNoSqlDynamicCollection(Database database, string name, CosmosNoSqlCollectionOptions options)
public CosmosDynamicCollection(Database database, string name, CosmosCollectionOptions options)
: this(
new(database.Client, ownsClient: false),
_ => database,
Expand All @@ -41,21 +41,21 @@ public CosmosNoSqlDynamicCollection(Database database, string name, CosmosNoSqlC
}

/// <summary>
/// Initializes a new instance of the <see cref="CosmosNoSqlDynamicCollection"/> class.
/// Initializes a new instance of the <see cref="CosmosDynamicCollection"/> class.
/// </summary>
/// <param name="connectionString">Connection string required to connect to Azure CosmosDB NoSQL.</param>
/// <param name="databaseName">Database name for Azure CosmosDB NoSQL.</param>
/// <param name="collectionName">The name of the collection that this <see cref="CosmosNoSqlDynamicCollection"/> will access.</param>
/// <param name="connectionString">Connection string required to connect to Azure Cosmos NoSQL.</param>
/// <param name="databaseName">Database name for Azure Cosmos NoSQL.</param>
/// <param name="collectionName">The name of the collection that this <see cref="CosmosDynamicCollection"/> will access.</param>
/// <param name="clientOptions">Optional configuration options for <see cref="CosmosClient"/>.</param>
/// <param name="options">Optional configuration options for this class.</param>
[RequiresUnreferencedCode("The Cosmos NoSQL provider is currently incompatible with trimming.")]
[RequiresDynamicCode("The Cosmos NoSQL provider is currently incompatible with NativeAOT.")]
public CosmosNoSqlDynamicCollection(
public CosmosDynamicCollection(
string connectionString,
string databaseName,
string collectionName,
CosmosClientOptions? clientOptions = null,
CosmosNoSqlCollectionOptions? options = null)
CosmosCollectionOptions? options = null)
: this(
new(new CosmosClient(connectionString, clientOptions), ownsClient: true),
client => client.GetDatabase(databaseName),
Expand All @@ -67,16 +67,16 @@ public CosmosNoSqlDynamicCollection(
Throw.IfNullOrWhitespace(collectionName);
}

internal CosmosNoSqlDynamicCollection(
internal CosmosDynamicCollection(
ClientWrapper clientWrapper,
Func<CosmosClient, Database> databaseProvider,
string name,
CosmosNoSqlCollectionOptions? options)
CosmosCollectionOptions? options)
: base(
clientWrapper,
databaseProvider,
name,
static options => new CosmosNoSqlModelBuilder()
static options => new CosmosModelBuilder()
.BuildDynamic(
options.Definition ?? throw new ArgumentException("Definition is required for dynamic collections"),
options.EmbeddingGenerator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
using MEAI = Microsoft.Extensions.AI;
using Microsoft.Shared.Diagnostics;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

/// <summary>
/// A mapper that maps between the generic Semantic Kernel data model and the model that the data is stored under, within Azure CosmosDB NoSQL.
/// A mapper that maps between the generic Semantic Kernel data model and the model that the data is stored under, within Azure Cosmos NoSQL.
/// </summary>
internal sealed class CosmosNoSqlDynamicMapper(CollectionModel model, JsonSerializerOptions jsonSerializerOptions)
: ICosmosNoSqlMapper<Dictionary<string, object?>>
internal sealed class CosmosDynamicMapper(CollectionModel model, JsonSerializerOptions jsonSerializerOptions)
: ICosmosMapper<Dictionary<string, object?>>
{
public JsonObject MapFromDataToStorageModel(Dictionary<string, object?> dataModel, int recordIndex, IReadOnlyList<MEAI.Embedding>?[]? generatedEmbeddings)
{
Throw.IfNull(dataModel);

var jsonObject = new JsonObject
{
[CosmosNoSqlConstants.ReservedKeyPropertyName] = !dataModel.TryGetValue(model.KeyProperty.ModelName, out var keyValue)
[CosmosConstants.ReservedKeyPropertyName] = !dataModel.TryGetValue(model.KeyProperty.ModelName, out var keyValue)
? throw new InvalidOperationException($"Missing value for key property '{model.KeyProperty.ModelName}")
: keyValue switch
{
Expand Down Expand Up @@ -124,7 +124,7 @@ static bool TryGetReadOnlyMemory<T>(object value, [NotNullWhen(true)] out ReadOn
switch (property)
{
case KeyPropertyModel keyProperty:
var key = (string?)storageModel[CosmosNoSqlConstants.ReservedKeyPropertyName]
var key = (string?)storageModel[CosmosConstants.ReservedKeyPropertyName]
?? throw new InvalidOperationException($"The key property '{keyProperty.StorageName}' is missing from the record retrieved from storage.");

result[keyProperty.ModelName] = keyProperty.Type switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
using Microsoft.Extensions.VectorData.ProviderServices;
using Microsoft.Extensions.VectorData.ProviderServices.Filter;

namespace CommunityToolkit.VectorData.CosmosNoSql;
namespace CommunityToolkit.VectorData.AzureCosmosDB;

#pragma warning disable MEVD9001 // Experimental: filter translation base types

internal class CosmosNoSqlFilterTranslator : FilterTranslatorBase
internal class CosmosFilterTranslator : FilterTranslatorBase
{
private readonly Dictionary<string, object?> _parameters = [];
private readonly StringBuilder _sql = new();
Expand Down Expand Up @@ -364,7 +364,7 @@ protected void TranslateQueryParameter(string name, object? value)

protected virtual void GeneratePropertyAccess(PropertyModel property)
=> this._sql
.Append(CosmosNoSqlConstants.ContainerAlias)
.Append(CosmosConstants.ContainerAlias)
.Append("[\"")
.Append(property.StorageName.Replace(@"\", @"\\").Replace("\"", "\\\""))
.Append("\"]");
Expand Down
Loading