Galosys.Foundation.Agents.AI.Milvus 26.10.29.1

dotnet add package Galosys.Foundation.Agents.AI.Milvus --version 26.10.29.1
                    
NuGet\Install-Package Galosys.Foundation.Agents.AI.Milvus -Version 26.10.29.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.Agents.AI.Milvus" Version="26.10.29.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Agents.AI.Milvus" Version="26.10.29.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Agents.AI.Milvus" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.Agents.AI.Milvus --version 26.10.29.1
                    
#r "nuget: Galosys.Foundation.Agents.AI.Milvus, 26.10.29.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.Agents.AI.Milvus@26.10.29.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.Agents.AI.Milvus&version=26.10.29.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Agents.AI.Milvus&version=26.10.29.1
                    
Install as a Cake Tool

Galosys.Foundation.Agents.AI.Milvus

MAF Milvus 向量数据库模块,提供两块能力:

  1. 连接抽象(IMilvusConnection + MilvusClientConnection):封装官方 Milvus.Client(gRPC),抽象层不暴露 SDK 类型。
  2. RAG Provider(AgentMilvusRagProvider : AIContextProvider):在 Agent 调用前将用户问题向量化,从 Milvus 检索最相关文档并注入 AIContext。

提供程序无关、不依赖 Hosting、不依赖 Redis。作为 Phase 2「记忆与知识」的独立升级路径(大规模/混合检索时替代/补充 Redis 实现)。

安装

<PackageReference Include="Galosys.Foundation.Agents.AI.Milvus" />

存储设计

Milvus 结构 说明
Collection 一个知识库对应一个集合(默认 rag_docs),含 id(主键)、content、embedding(float_vector)字段
向量检索 L2 距离近邻检索,按相似度排序取 TopK
  • 摄入:IngestAsync 把文本分段嵌入后写入集合(集合不存在时自动创建并加载)。
  • 检索:InvokingCoreAsync 取用户最近一条消息 → 实时生成查询向量 → 检索 → 注入上下文。
  • 会话隔离:会话特定键(命名空间/会话键)存 AgentSession.StateBag,单实例服务多会话不串。

注册

using Microsoft.Extensions.DependencyInjection;

var builder = Host.CreateApplicationBuilder(args);

// 1. 注册 Milvus 连接
builder.Services.AddMilvusConnection(options =>
{
    options.Endpoint = "localhost";
    options.Port = 19530;
    // options.Username = "root";
    // options.Password = "milvus123";
});

// 2. 注册嵌入生成器(从 DI 解析,Provider 不自建)
builder.Services.AddEmbeddingGenerator(); // 具体实现由应用提供(如 OpenAI/Ollama)

// 3. 注册 RAG Provider
builder.Services.AddAgentMilvusRagProvider(options =>
{
    options.CollectionName = "rag_docs"; // 默认集合名
    options.TopK = 5;                    // 默认命中数
    options.VectorDimension = 1536;      // 嵌入维度,须与嵌入模型一致
});

AddMilvusConnection() 幂等注册 IMilvusConnection(Scoped);AddAgentMilvusRagProvider() 幂等注册 AgentMilvusRagProvider 与 AIContextProvider(Transient,工厂解析 IMilvusConnection 与 IEmbeddingGenerator<string, Embedding<float>>)。

摄入知识

// 从容器解析 Provider(或 AgentMilvusRagProvider)
var rag = sp.GetRequiredService<AgentMilvusRagProvider>();

await rag.IngestAsync("Milvus 是开源的向量数据库,支持大规模向量近邻检索。", ct);
await rag.IngestAsync("Galosys.Foundation.Agents.AI.Milvus 封装官方 Milvus.Client SDK。", ct);

配置到 Agent

using Microsoft.Agents.AI;

var agent = new ChatClientAgent(chatClient, new ChatClientAgentOptions
{
    Name = "assistant",
    ChatOptions = new ChatOptions { Instructions = "You are a helpful assistant." },
    AIContextProviders = new[] { ragProvider } // 解析 AIContextProvider 注入
});
// 或 AIAgentBuilder.UseAIContextProviders(...)

Options

MilvusConnectionOptions

  • Endpoint — Milvus 服务主机地址,默认 "localhost"
  • Port — 服务端口,默认 19530
  • Username / Password — 可选认证
  • Database — 可选数据库名

AgentMilvusRagOptions

  • CollectionName — 知识库集合名,默认 "rag_docs"
  • VectorFieldName — 向量字段名,默认 "embedding"
  • IdFieldName — 主键字段名,默认 "id"
  • ContentFieldName — 文本内容字段名,默认 "content"
  • TopK — 注入的命中数,默认 5
  • VectorDimension — 嵌入维度,默认 1536(须与嵌入模型一致)
  • Namespace — 检索命名空间,默认 "default"
  • PromptTemplate — 注入提示词模板,含 {context} / {question} 占位符
  • StateKey — 存入 AgentSession.StateBag 的状态键,默认 Provider 类型名
  • JsonSerializerOptions — 状态序列化选项,默认模块自带 Web 默认

命名空间

  • 实现类型 IMilvusConnection / MilvusClientConnection / MilvusCollectionSchema / MilvusFieldSchema / MilvusSearchHit / AgentMilvusRagProvider / AgentMilvusRagOptions / MilvusConnectionOptions / MilvusRagProviderState 在 Galosys.Foundation.Agents.AI.Milvus(域实现,不寄生)。
  • DI 注册扩展 AddMilvusConnection() / AddAgentMilvusRagProvider() 寄生 Microsoft.Extensions.DependencyInjection。

与 Agents.AI.Redis 的关系

维度 Redis 版(长记忆) Milvus 版(RAG)
依赖 Galosys.Foundation.Redis 抽象层 官方 Milvus.Client(gRPC)
数据模型 Hash 键值记忆 Collection + float_vector 向量近邻检索
嵌入 无(直接存记忆值) 需 IEmbeddingGenerator<string, Embedding<float>>
适用场景 高频、轻量、跨会话画像/事实记忆 大规模知识库、语义检索、RAG 问答
环境 任意 Redis(含 5.0) Milvus 服务

依赖

  • Galosys.Foundation.Agents.AI — Agent 核心(AIContextProvider 抽象)
  • Milvus.Client — 官方 Milvus .NET SDK(gRPC)
  • Microsoft.Agents.AI — MAF 核心(1.13)
  • Microsoft.Extensions.AI — 嵌入生成抽象(IEmbeddingGenerator)
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.10.29.1 80 10/29/2026
26.10.20.1 61 10/20/2026
26.10.16.2 66 10/16/2026
26.10.16.1 71 10/16/2026
26.10.9.1 63 10/9/2026
26.10.8.1 62 10/8/2026
26.9.23.1 93 9/23/2026
26.9.16.1 74 9/16/2026
26.9.15.1 73 9/15/2026
26.9.14.1 68 9/14/2026
26.9.10.1 96 9/10/2026
26.9.3.1 94 9/3/2026
26.8.29.1 93 8/31/2026
26.8.26.1 95 8/26/2026
26.8.23.1 105 8/23/2026
26.8.21.1 84 8/21/2026
26.8.20.1 80 8/20/2026
26.8.18.1 96 8/18/2026
26.8.17.1 96 8/17/2026
26.8.13.2 90 8/13/2026
Loading failed