Skip to content
Open
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
3 changes: 3 additions & 0 deletions CommunityToolkit.AI.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Project Path="MEVD/src/AzureDocumentDB/AzureDocumentDB.csproj" />
<Project Path="MEVD/src/Chroma/Chroma.csproj" />
<Project Path="MEVD/src/InMemory/InMemory.csproj" />
<Project Path="MEVD/src/Milvus/Milvus.csproj" />
<Project Path="MEVD/src/PgVector/PgVector.csproj" />
<Project Path="MEVD/src/Qdrant/Qdrant.csproj" />
<Project Path="MEVD/src/Redis/Redis.csproj" />
Expand All @@ -32,6 +33,8 @@
<Project Path="MEVD/test/Chroma.ConformanceTests/Chroma.ConformanceTests.csproj" />
<Project Path="MEVD/test/InMemory.UnitTests/InMemory.UnitTests.csproj" />
<Project Path="MEVD/test/InMemory.ConformanceTests/InMemory.ConformanceTests.csproj" />
<Project Path="MEVD/test/Milvus.UnitTests/Milvus.UnitTests.csproj" />
<Project Path="MEVD/test/Milvus.ConformanceTests/Milvus.ConformanceTests.csproj" />
<Project Path="MEVD/test/PgVector.UnitTests/PgVector.UnitTests.csproj" />
<Project Path="MEVD/test/PgVector.ConformanceTests/PgVector.ConformanceTests.csproj" />
<Project Path="MEVD/test/Qdrant.UnitTests/Qdrant.UnitTests.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.6" />
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="10.0.13" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="10.0.10" />
<PackageVersion Include="Milvus.Client" Version="2.6.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.10.0" />
<PackageVersion Include="Npgsql" Version="10.0.3" />
<PackageVersion Include="NRedisStack" Version="1.6.0" />
Expand Down Expand Up @@ -46,6 +47,7 @@
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Testcontainers" Version="4.14.0" />
<PackageVersion Include="Testcontainers.CosmosDb" Version="4.14.0" />
<PackageVersion Include="Testcontainers.Milvus" Version="4.14.0" />
<PackageVersion Include="Testcontainers.MsSql" Version="4.14.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.14.0" />
<PackageVersion Include="Testcontainers.Qdrant" Version="4.14.0" />
Expand Down
3 changes: 3 additions & 0 deletions MEVD/MEVD.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"MEVD/src/AzureDocumentDB/AzureDocumentDB.csproj",
"MEVD/src/Chroma/Chroma.csproj",
"MEVD/src/InMemory/InMemory.csproj",
"MEVD/src/Milvus/Milvus.csproj",
"MEVD/src/PgVector/PgVector.csproj",
"MEVD/src/Qdrant/Qdrant.csproj",
"MEVD/src/Redis/Redis.csproj",
Expand All @@ -25,6 +26,8 @@
"MEVD/test/Chroma.ConformanceTests/Chroma.ConformanceTests.csproj",
"MEVD/test/InMemory.UnitTests/InMemory.UnitTests.csproj",
"MEVD/test/InMemory.ConformanceTests/InMemory.ConformanceTests.csproj",
"MEVD/test/Milvus.UnitTests/Milvus.UnitTests.csproj",
"MEVD/test/Milvus.ConformanceTests/Milvus.ConformanceTests.csproj",
"MEVD/test/PgVector.UnitTests/PgVector.UnitTests.csproj",
"MEVD/test/PgVector.ConformanceTests/PgVector.ConformanceTests.csproj",
"MEVD/test/Qdrant.UnitTests/Qdrant.UnitTests.csproj",
Expand Down
2 changes: 2 additions & 0 deletions MEVD/src/Milvus/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
67 changes: 67 additions & 0 deletions MEVD/src/Milvus/ClientWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Milvus.Client;
using Microsoft.Shared.Diagnostics;

namespace CommunityToolkit.VectorData.Milvus;

/// <summary>
/// The <see cref="MilvusClient"/> of a vector store or of a collection. A vector store shares it with the collections it returns,
/// and the <see cref="MilvusClient"/> it owns is disposed when the last of them is disposed.
/// </summary>
internal sealed class ClientWrapper : IDisposable
{
private readonly MilvusClient? _ownedClient;
private int _referenceCount = 1;

/// <summary>
/// Gets the client.
/// </summary>
public MilvusClient Client { get; }

/// <summary>
/// Gets the database name for telemetry, or <see langword="null"/> for a client created by the caller: the SDK does not
/// expose the configured database.
/// </summary>
public string? DatabaseName { get; }

/// <summary>
/// Initializes a new instance of the <see cref="ClientWrapper"/> class.
/// </summary>
/// <param name="milvusClient">Milvus client that can be used to manage the collections and records in a Milvus store.</param>
/// <param name="ownsClient">A value indicating whether <paramref name="milvusClient"/> is disposed with the last of the vector store and its collections.</param>
/// <param name="databaseName">
/// The database the SDK client connects to, for telemetry: known to the host-based registrations, which create the client.
/// </param>
public ClientWrapper(MilvusClient milvusClient, bool ownsClient, string? databaseName = null)
{
Throw.IfNull(milvusClient);

Client = milvusClient;
DatabaseName = databaseName;
_ownedClient = ownsClient ? milvusClient : null;
}

/// <summary>
/// Gets this client for one more user, a collection of the vector store, which disposes it too.
/// </summary>
public ClientWrapper Share()
{
if (_ownedClient is not null)
{
Interlocked.Increment(ref _referenceCount);
}

return this;
}

/// <inheritdoc />
public void Dispose()
{
if (_ownedClient is not null && Interlocked.Decrement(ref _referenceCount) == 0)
{
_ownedClient.Dispose();
}
}
}
31 changes: 31 additions & 0 deletions MEVD/src/Milvus/Milvus.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.0-preview</Version>
<AssemblyName>CommunityToolkit.VectorData.Milvus</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFrameworks>net10.0;net8.0;netstandard2.0;net462</TargetFrameworks>

<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>

<Title>Milvus provider for Microsoft.Extensions.VectorData</Title>
<Description>Milvus provider for Microsoft.Extensions.VectorData by the .NET Community Toolkit</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Linq.AsyncEnumerable" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" />
<PackageReference Include="Milvus.Client" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'net462' ">
<PackageReference Include="System.Text.Json" />
</ItemGroup>

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

</Project>
Loading