Bitzsoft.Integrations.RAG
1.0.0-alpha.7
This is a prerelease version of Bitzsoft.Integrations.RAG.
dotnet add package Bitzsoft.Integrations.RAG --version 1.0.0-alpha.7
NuGet\Install-Package Bitzsoft.Integrations.RAG -Version 1.0.0-alpha.7
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="Bitzsoft.Integrations.RAG" Version="1.0.0-alpha.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.RAG" Version="1.0.0-alpha.7" />
<PackageReference Include="Bitzsoft.Integrations.RAG" />
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 Bitzsoft.Integrations.RAG --version 1.0.0-alpha.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.RAG, 1.0.0-alpha.7"
#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 Bitzsoft.Integrations.RAG@1.0.0-alpha.7
#: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=Bitzsoft.Integrations.RAG&version=1.0.0-alpha.7&prerelease
#tool nuget:?package=Bitzsoft.Integrations.RAG&version=1.0.0-alpha.7&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.RAG
检索增强生成 — Qdrant 向量数据库 + IEmbeddingGenerator 抽象(Ollama / OpenAI 可插拔),开箱即用的 RAG 解决方案。
功能特性
- 基于 Qdrant 向量数据库的高性能相似度检索
- 嵌入层基于 MEAI
IEmbeddingGenerator<string, Embedding<float>>抽象,支持 Ollama / OpenAI 双后端 - BM25 混合检索:向量检索 + 关键词 BM25 评分 + 倒排排融合(RRF)重排序
- 提供完整的文档处理管线:清理、分块(按段落 / 按固定大小)、嵌入、索引
- 支持元数据过滤(按 category、sourceFile 等字段筛选检索范围)
- 自动生成基于检索结果的系统提示词(SystemPrompt),无缝对接 AI 对话流程
- 所有服务均通过 DI 注册,可独立替换各层实现
安装
dotnet add package Bitzsoft.Integrations.RAG
配置
Ollama 嵌入后端(默认)
{
"Ollama": {
"Url": "http://localhost:11434",
"ApiKey": "",
"DefaultModel": "nomic-embed-text",
"VectorSize": 1536
},
"Qdrant": {
"Url": "http://localhost:6334",
"ApiKey": "",
"CertificateThumbprint": ""
}
}
Qdrant 配置
| 配置项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Url |
string |
"http://localhost:6334" |
Qdrant gRPC 服务地址 |
ApiKey |
string |
- | API 密钥 |
CertificateThumbprint |
string |
- | TLS 证书指纹 |
注册服务
使用 Ollama 嵌入(默认)
using Bitzsoft.Integrations.RAG;
using Bitzsoft.Integrations.RAG.Ollama;
using Bitzsoft.Integrations.RAG.Qdrant;
// Program.cs
services.AddRAG(
configureOllama: options =>
{
options.Url = "http://localhost:11434";
options.DefaultModel = "nomic-embed-text";
options.VectorSize = 1536;
},
configureQdrant: options =>
{
options.Url = "http://localhost:6334";
options.ApiKey = "your-qdrant-api-key";
});
使用 OpenAI 嵌入(无需部署 Ollama)
services.AddRAGWithOpenAIEmbeddings(
configureEmbedding: options =>
{
options.Endpoint = "https://api.openai.com/v1";
options.ApiKey = "sk-your-openai-key";
options.ModelId = "text-embedding-3-small";
},
configureQdrant: options =>
{
options.Url = "http://localhost:6334";
});
AddRAG/AddRAGWithOpenAIEmbeddings均会注册IEmbeddingGenerator<string, Embedding<float>>、IQdrantService和IRAGService,可在 DI 容器中独立注入。
使用示例
文档索引与检索问答
using Microsoft.Extensions.AI;
using Bitzsoft.Integrations.RAG;
using Bitzsoft.Integrations.RAG.Dto;
public class KnowledgeBaseService(
IRAGService ragService,
IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator)
{
private const string CollectionName = "company-docs";
/// <summary>
/// 索引一篇文档到知识库(自动分块 + 向量化)
/// </summary>
public Task<bool> IndexDocumentAsync(
string content, string fileName, string title,
string category = "", CancellationToken ct = default)
{
var cleanedContent = DocumentProcessor.CleanDocument(content);
return ragService.IndexDocumentAsync(CollectionName, cleanedContent, fileName, title, category);
}
/// <summary>
/// 基于知识库回答用户问题
/// </summary>
public async Task<(string SystemPrompt, List<DocumentChunkDto> Sources)> AskAsync(
string question, CancellationToken ct = default)
{
// 生成查询向量
var queryVector = (await embeddingGenerator.GenerateVectorAsync(question, ct)).ToArray();
// 检索相关文档并生成 SystemPrompt
var (success, systemPrompt, documents) = await ragService.GetSystemPromptAsync(
CollectionName, queryVector, topK: 3, scoreThreshold: 0.7);
return (systemPrompt, documents);
}
}
BM25 混合检索(语义 + 关键词 + RRF 融合)
public class HybridSearchExample(IRAGService ragService)
{
/// <summary>
/// 混合检索:向量语义匹配 + BM25 关键词匹配,RRF 融合重排序
/// </summary>
public Task<List<DocumentChunkDto>> SearchAsync(string question, CancellationToken ct = default)
{
return ragService.HybridSearchAsync(
collectionName: "company-docs",
queryText: question,
topK: 5,
metadataFilter: new() { ["category"] = "技术文档" });
}
}
直接使用底层 Qdrant 服务
using Bitzsoft.Integrations.RAG.Qdrant;
using Microsoft.Extensions.AI;
public class VectorSearchService(
IQdrantService qdrantService,
IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator)
{
public Task<bool> InitializeCollectionAsync(string name, CancellationToken ct = default)
=> qdrantService.CreateCollectionAsync(name, vectorSize: 1536);
public async Task<List<DocumentChunkDto>> SearchAsync(
string query, string collectionName, int topK = 5, CancellationToken ct = default)
{
var queryVector = (await embeddingGenerator.GenerateVectorAsync(query, ct)).ToArray();
return await qdrantService.SearchAsync(collectionName, queryVector, (ulong)topK);
}
}
相关包
| 包名 | 说明 |
|---|---|
| Bitzsoft.Integrations.AI | 轻量级 AI 客户端(IChatClient),可与 RAG 检索结果组合使用 |
| Bitzsoft.Integrations.SemanticKernel | Semantic Kernel 编排层(插件、函数调用) |
| Bitzsoft.Integrations.AI.Abstractions | AI 共享抽象层(AiOptions、DI 扩展) |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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.
-
net10.0
- Bitzsoft.Integrations.AI.Abstractions (>= 1.0.0-alpha.7)
- Microsoft.Extensions.AI (>= 10.7.0)
- Microsoft.Extensions.AI.Abstractions (>= 10.7.0)
- Microsoft.Extensions.AI.Ollama (>= 9.7.0-preview.1.25356.2)
- Microsoft.Extensions.AI.OpenAI (>= 10.7.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- OpenAI (>= 2.11.0)
- Qdrant.Client (>= 1.18.1)
-
net8.0
- Bitzsoft.Integrations.AI.Abstractions (>= 1.0.0-alpha.7)
- Microsoft.Extensions.AI (>= 10.7.0)
- Microsoft.Extensions.AI.Abstractions (>= 10.7.0)
- Microsoft.Extensions.AI.Ollama (>= 9.7.0-preview.1.25356.2)
- Microsoft.Extensions.AI.OpenAI (>= 10.7.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- OpenAI (>= 2.11.0)
- Qdrant.Client (>= 1.18.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.RAG:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.All
Bitzsoft 第三方集成聚合包 — 包含全部 Integration 模块 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.7 | 57 | 6/16/2026 |
| 1.0.0-alpha.6 | 58 | 6/16/2026 |
| 1.0.0-alpha.5 | 56 | 6/14/2026 |
| 1.0.0-alpha.3 | 63 | 6/7/2026 |
| 1.0.0-alpha.2 | 58 | 5/29/2026 |
| 1.0.0-alpha.1 | 53 | 5/28/2026 |