⚡ 融合行动
Agent原生检索引擎
人工智能代理的混合向量+推理+记忆
 ](https://nodejs.org) ](https://www.npmjs.com/package/fusionpact)
相似性≠相关性。 FusionAction是第一个将HNSW向量搜索、基于推理的树检索和代理内存结合在一个平台上的检索引擎,专为人工智能代理和多代理系统而构建。
快速入门 · 混合检索 · 代理内存 · 多Agent · MCP服务器 · 树索引 · RAG 流程 · API 参考 · 基准测试 · 贡献
______________________________________________________________________
为什么选择FusionAct?
传统的矢量数据库检索 相似的.但相似≠相关。向向量数据库询问“2024年第三季度收入”,你可能会得到第二季度或第四季度的数据——语义相似,但 错误答案.
FusionAction通过结合 三种检索范式:
| 策略 | 如何运作 | 最适合 |
|---|---|---|
| 向量搜索 (HNSW) | 嵌入相似性,O(log N) | 跨大型集合的广泛搜索 |
| 树推理 | LLM导航文档结构 | 在结构化文档中进行精确检索 |
| 关键字搜索 (BM25) | 词频匹配 | 精确匹配要求 |
加上专门打造 代理存储器, 多代理编排,以及 MCP服务器 --全零依赖,本地优先,免费。
┌──────────────────────────────────────────────────────────┐
│ FusionPact Retrieval Engine │
│ │
│ ┌────────────┐ ┌─────────────┐ ┌────────────────┐ │
│ │ Vector │ │ Tree │ │ Keyword │ │
│ │ (HNSW) │ │ (Reasoning) │ │ (BM25) │ │
│ └─────┬──────┘ └──────┬──────┘ └───────┬────────┘ │
│ └────────────┬────┴─────────────────┘ │
│ ▼ │
│ Reciprocal Rank Fusion │
│ ▼ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Agent Memory (Multi-Agent) │ │
│ │ Episodic │ Semantic │ Procedural │ Shared │ │
│ └──────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ MCP Server (Claude, Cursor, etc.) │ │
│ └──────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────┘______________________________________________________________________
⚡ 快速入门
# Install
npm install fusionpact
# Run the demo
npx fusionpact demo
# Start HTTP + MCP server
npx fusionpact serve --port 8080
# Start MCP server for Claude Desktop
npx fusionpact mcp10行代码
const { create } = require('fusionpact');
const fp = create({ embedder: 'ollama' }); // or 'mock' for zero-config
// Ingest a document — auto-chunks, embeds, indexes
await fp.rag.ingest('Your document text here...', { source: 'doc.pdf' });
// Hybrid search — vector + reasoning + keyword, fused automatically
const results = await fp.retriever.retrieve('What safety protocols exist?', {
collection: 'default',
strategy: 'hybrid'
});
// Or build LLM-ready context directly
const context = await fp.rag.buildContext('What safety protocols exist?');
console.log(context.prompt); // Ready to paste into any LLM______________________________________________________________________
🔀 混合检索引擎
核心区别:单个API通过多种检索策略智能路由查询,并使用倒数排名融合融合结果。
const { create } = require('fusionpact');
const fp = create({
embedder: 'ollama', // Local, free, private
llmProvider: 'ollama', // For tree reasoning
enableHybrid: true
});
// Index a structured document with tree structure
await fp.treeIndex.indexDocument('annual-report', reportText, {
format: 'markdown'
});
// Hybrid retrieval — automatically uses the best strategy
const results = await fp.retriever.retrieve(
'What were the total deferred tax assets in Q3?',
{
collection: 'documents', // Vector search here
docId: 'annual-report', // Tree reasoning here
topK: 5,
strategy: 'hybrid' // Fuse all strategies
}
);
// Each result includes:
// - score: Fused relevance score
// - content: Retrieved text
// - sources: Which strategies contributed { vector: 0.8, tree: 0.9, keyword: 0.3 }
// - citation: "Section 3 > Financial Data > Table 3.2.1"
// - reasoning: Full tree traversal reasoning trace战略权重
const retriever = new HybridRetriever({
engine, treeIndex, embedder,
weights: {
vector: 0.4, // 40% weight to vector similarity
tree: 0.4, // 40% weight to reasoning-based retrieval
keyword: 0.2 // 20% weight to keyword matching
}
});自适应学习
FusionAction学习哪种检索策略最适合不同的查询模式:
// Record feedback on result quality
retriever.recordFeedback('financial query', 'tree', 0.95);
retriever.recordFeedback('general search', 'vector', 0.85);
// Get recommended weights for a new query
const weights = retriever.getAdaptiveWeights('new financial query');
// → { vector: 0.25, tree: 0.6, keyword: 0.15 }______________________________________________________________________
🌲 树索引
基于推理的结构化文档检索。构建一个层次树(如智能目录),并使用LLM推理导航到最相关的部分。
const { TreeIndex, LLMProvider } = require('fusionpact');
const llm = new LLMProvider({ provider: 'ollama' }); // Free, local
const tree = new TreeIndex({ llmProvider: llm });
// Index a document
await tree.indexDocument('sec-filing', filingText, {
format: 'markdown',
metadata: { source: '10-K', year: 2024 }
});
// Reasoning-based search
const results = await tree.search('sec-filing', 'Total deferred tax assets', {
maxResults: 3,
includeReasoning: true
});
// results[0]:
// {
// content: "Table 5.2: Deferred Tax Assets...",
// relevanceScore: 0.95,
// citation: "Financial Statements > Note 5 > Tax Assets > Table 5.2",
// reasoningPath: [
// { title: "Financial Statements", reasoning: "Deferred tax assets are in financial notes", action: "explore" },
// { title: "Note 5: Income Taxes", reasoning: "This note covers tax-related assets", action: "explore" },
// { title: "Table 5.2", reasoning: "Contains the deferred tax asset breakdown", action: "retrieve" }
// ]
// }没有法学硕士也能工作
如果没有配置LLM提供程序,TreeIndex将回退到基于关键字的树遍历——仍然有用,只是没有推理路径:
const tree = new TreeIndex(); // No LLM — keyword fallback
await tree.indexDocument('doc', text, { format: 'markdown' });
const results = await tree.search('doc', 'safety protocols');______________________________________________________________________
🧠 代理内存
专门为AI代理构建的内存系统,有四种内存类型:
| 内存类型 | 存储内容 | 示例 |
|---|---|---|
| 情节性的 | 事件、对话、观察 | “用户询问了实验室B的化学品储存情况” |
| 语义 | 事实、领域知识、学习信息 | “OSHA 1910.106涵盖易燃液体” |
| 程序性 | 工具架构、API规范、工作流 | search_incidents工具定义 |
| 共享 | 跨代理知识库 | “客户ACME更喜欢ISO 14001” |
const { create } = require('fusionpact');
const fp = create({ embedder: 'ollama', enableMemory: true });
// Episodic — remember what happened
await fp.memory.remember('agent-1', {
content: 'User prefers dark mode and concise answers',
role: 'system',
importance: 0.8
});
// Semantic — learn knowledge
await fp.memory.learn('agent-1',
'OSHA 29 CFR 1910 covers general industry safety standards.',
{ source: 'regulations', category: 'compliance' }
);
// Procedural — register tools
await fp.memory.registerTool('agent-1', {
name: 'search_incidents',
description: 'Search EHS incident reports by category and severity',
schema: { type: 'object', properties: { severity: { type: 'string' } } }
});
// Recall — cross-memory search
const memories = await fp.memory.recall('agent-1', 'safety compliance');
// → { episodic: [...], semantic: [...], procedural: [...], shared: [...] }
// Conversation memory
fp.memory.addMessage('agent-1', 'thread-001', { role: 'user', content: 'What are the PPE requirements?' });
fp.memory.addMessage('agent-1', 'thread-001', { role: 'assistant', content: 'PPE requirements include...' });
const history = fp.memory.getConversation('agent-1', 'thread-001');
// GDPR-friendly forget
fp.memory.forget('agent-1', { type: 'all' });______________________________________________________________________
🤖 多代理编排
通过隔离内存、共享知识和消息路由协调多个AI代理:
const { create, AgentOrchestrator } = require('fusionpact');
const fp = create({ embedder: 'ollama', enableMemory: true });
const orchestrator = new AgentOrchestrator({
engine: fp.engine,
memory: fp.memory,
retriever: fp.retriever
});
// Register agents
orchestrator.registerAgent({
agentId: 'researcher',
name: 'Research Agent',
role: 'Find and analyze information',
capabilities: ['search', 'analysis', 'summarization']
});
orchestrator.registerAgent({
agentId: 'writer',
name: 'Writing Agent',
role: 'Generate reports and documentation',
capabilities: ['writing', 'formatting', 'editing']
});
// Agent-to-agent communication
await orchestrator.send({
from: 'researcher',
to: 'writer',
type: 'result',
payload: { findings: 'Safety incidents decreased 12% YoY...' }
});
// Capability-based task delegation
await orchestrator.delegate('coordinator', 'Write a safety summary report', {
requiredCapabilities: ['writing', 'formatting']
});
// → Automatically routes to 'writer' agent
// Collaborative retrieval across all agents
const results = await orchestrator.collaborativeRecall('safety compliance');
// → Returns memories from all agents, plus shared knowledge
// Message handling
orchestrator.onMessage('writer', async (msg) => {
console.log(`Writer received: ${msg.type} from ${msg.from}`);
// Process task...
});______________________________________________________________________
🔌 MCP服务器
FusionAction作为MCP(模型上下文协议)服务器提供。任何AI代理(Claude、Cursor、Windsurf)都可以将其用作持久内存,无需自定义集成。
Claude桌面设置
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"fusionpact": {
"command": "npx",
"args": ["fusionpact", "mcp"],
"env": {
"EMBEDDING_PROVIDER": "ollama"
}
}
}
}可用的MCP工具
| 工具 | 说明 |
|---|---|
fusionpact_create_collection | 创建HNSW索引矢量集合 |
fusionpact_search | 语义向量搜索 |
fusionpact_hybrid_search | 混合检索(向量+树+关键字) |
fusionpact_rag_ingest | 一键式RAG摄取 |
fusionpact_rag_query | 构建LLM就绪上下文 |
fusionpact_memory_remember | 存储情景记忆 |
fusionpact_memory_recall | 回忆相关记忆 |
fusionpact_memory_learn | 添加语义知识 |
fusionpact_memory_share | 分享跨代理知识 |
fusionpact_memory_forget | GDPR风格的内存擦除 |
fusionpact_memory_conversation | 管理对话线程 |
______________________________________________________________________
📄 RAG 流程
一次通话中的端到端RAG:
const fp = require('fusionpact').create({ embedder: 'ollama' });
// Ingest — auto-chunks, embeds, indexes
await fp.rag.ingest(documentText, {
source: 'safety-manual.pdf',
title: 'Safety Manual 2024'
});
// Build context for any LLM
const ctx = await fp.rag.buildContext('What PPE is required?', {
topK: 5,
maxTokens: 4000,
strategy: 'hybrid' // Uses HybridRetriever if available
});
// ctx.prompt → Ready for any LLM
// ctx.sources → Source citations
// ctx.chunks → Number of chunks used分块策略
const rag = new RAGPipeline(engine, {
chunkStrategy: 'recursive', // 'recursive' | 'sentence' | 'paragraph'
chunkSize: 512,
chunkOverlap: 50
});______________________________________________________________________
🔒 多租户
零信任软隔离——租户永远看不到彼此的数据:
const tenantA = engine.tenant('shared-collection', 'acme_corp');
const tenantB = engine.tenant('shared-collection', 'globex_inc');
tenantA.insert([{ id: 'doc-1', vector: [...], metadata: { doc: 'Acme Plan' } }]);
// Tenant A queries — only sees Acme data. Always.
const results = tenantA.search(queryVec, { topK: 10 });______________________________________________________________________
🔌 嵌入提供者
| 提供商 | 设置 | 尺寸 | 成本 |
|---|---|---|---|
| 奥拉玛 (推荐) | ollama pull nomic-embed-text | 768 | 免费 |
| 开放人工智能 | 设置 OPENAI_API_KEY | 1536 | 约0.02美元/百万代币 |
| 模拟 (测试) | 无 | 64 | 免费 |
// Ollama (local, free, private)
const fp = create({ embedder: 'ollama' });
// OpenAI
const fp = create({ embedder: 'openai', openaiConfig: { apiKey: 'sk-...' } });
// Mock (for demos/testing — no dependencies)
const fp = create({ embedder: 'mock' });______________________________________________________________________
📊 基准测试
HNSW性能(128D矢量)
| 矢量 | 插入 | 搜索(第50页) | QPS |
|---|---|---|---|
| 1000 | 15ms | 0.2ms | ~5000 |
| 10000 | 180毫秒 | 0.3毫秒 | ~3300 |
| 100000 | 2.8秒 | 0.5秒 | ~2000 |
运行自己的:
npx fusionpact bench --count 10000______________________________________________________________________
🆚 比较
| 功能 | 融合效果 | 页面索引 | 松果体 | 色度 | Qdrant |
|---|---|---|---|---|---|
| 混合检索(向量+树+关键字) | ✅ | ❌ | ❌ | ❌ | ❌ |
| 基于推理的树索引 | ✅ | ✅ | ❌ | ❌ | ❌ |
| 代理内存架构 | ✅ | ❌ | ❌ | ❌ | ❌ |
| 多代理编排 | ✅ | ❌ | ❌ | ❌ | ❌ |
| MCP服务器(本机代理) | ✅ | ✅ | ❌ | ❌ | ❌ |
| 一键RAG | ✅ | ❌ | ❌ | ❌ | ❌ |
| 多租户 | ✅ | ❌ | ✅ | ❌ | ✅ |
| 本地优先/零成本 | ✅ | ✅ | ❌ | ✅ | ✅ |
| HNSW矢量索引 | ✅ | ❌ | ✅ | ✅ | ✅ |
| 零依赖 | ✅ | ❌ | ❌ | ❌ | ❌ |
______________________________________________________________________
📖 API 参考
完整文档: docs/API.md文件
核心课程
| 类别 | 描述 |
|---|---|
FusionEngine | 核心数据库引擎、集合管理、CRUD |
HNSWIndex | HNSW近似最近邻指数 |
TreeIndex | 用于推理检索的层次化文档索引 |
HybridRetriever | 基于秩融合的多策略检索 |
AgentMemory | 多类型代理存储系统 |
AgentOrchestrator | 多智能体协调层 |
RAGPipeline | 端到端RAG管道 |
MCPServer | 模型上下文协议服务器 |
OllamaEmbedder | Ollama植入物提供商 |
OpenAIEmbedder | OpenAI嵌入提供商 |
MockEmbedder | 测试/演示嵌入器 |
LLMProvider | 多提供商LLM接口 |
______________________________________________________________________
🗺 路线图
- \[x\] 具有可配置M/ef参数的HNSW索引
- \[x\] 多租户,软隔离
- \[x\] 一键式RAG管道
- \[x\] Agent记忆(情景记忆、语义记忆、程序记忆、共享记忆)
- \[x\] 多代理编排
- \[x\] 树索引(基于推理的检索)
- \[x\] 混合检索器(矢量+树+关键字融合)
- \[x\] MCP服务器(标准输入+HTTP)
- \[x\] HTTP API服务器
- \[x\] Ollama+OpenAI嵌入提供商
- \[x\] 自适应检索学习
- \[\]SQLite/PPostgreSQL持久性
- \[\]Python SDK(
pip install fusionpact) - \[\]LangChain集成
- \[\]LlamaIdex集成
- \[\]CrewAI/AutoGen集成
- \[\]视觉RAG(PDF页面图像)
- \[\]Rust核心(NAPI绑定)
- \[\]FusionAction云(托管)
- \[\]仪表板用户界面
______________________________________________________________________
🤝 贡献
我们欢迎捐款!看 贡献.md 作为指导方针。
git clone https://github.com/FusionpactTech/fusionpact-vectordb.git
cd fusionpact-vectordb
npm install
npm test
npx fusionpact demo______________________________________________________________________
📜 归因
FusionAction由以下人员构建和维护 FusionPact技术股份有限公司。
如果您在项目中使用FusionAct,请通过以下方式之一添加归因:
- 在应用程序的关于页面或文档中包含“Powered by FusionAct”
- 保持
NOTICE分发中的文件 - 在项目确认书中参考FusionPact Technologies股份有限公司
看 属性.md 了解全部细节。
许可证
Apache 2.0 --在商业和开源项目中自由使用。
Apache 2.0许可证要求您:
- 在任何重新分发中包含许可证副本
- 包括归属于FusionPact Technologies股份有限公司的通知文件。
- 说明您对代码所做的任何重大更改
______________________________________________________________________
内置于❤️ 通过 FusionPact技术股份有限公司。
⭐ 如果你觉得这个仓库有用,就把它标上!
