# @claude-flow/neural 中文文档

规范地址：https://npmcn.com/package/%40claude-flow/neural/

版本：3\.0\.3
npm 元数据更新时间：2026-11-06T12:46:34.926Z
中文译文更新时间：2026-11-10T00:02:52.925Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40claude-flow/neural
原文对照：https://npmcn.com/package/%40claude-flow/neural/?lang=original
项目主页：https://github.com/ruvnet/ruflo
源码仓库：https://github.com/ruvnet/ruflo

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：847 kB，130 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2026-01-06T21:44:48.870Z
- 最新版本发布：2026-11-06T12:46:34.730Z
- 近 30 天下载量：270684（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 10 个）

## 中文简介

Claude Flow的自适应性神经结构(SONA)——适应性学习、轨迹跟踪、模式再利用、7个RL算法(PPO/A2C/DQN/Q-Llearning/SARSA/决定变换器/Curiosity),闪光注意、MOE路由、LORA、EWC++用于持续脱落

## 安装

```sh
npm install @claude-flow/neural
```

也可以使用：`pnpm add @claude-flow/neural`、`yarn add @claude-flow/neural`、`bun add @claude-flow/neural`

## README

# @ claude- flow/ 神经

[![npm version](https://img.shields.io/npm/v/@claude-flow/neural.svg)](https://www.npmjs.com/package/@claude-flow/neural) [![npm downloads](https://img.shields.io/npm/dm/@claude-flow/neural.svg)](https://www.npmjs.com/package/@claude-flow/neural) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)

> Claude Flow V3——适应性学习,轨迹跟踪,图案再用,以及7个RL算法的自优化神经架构(SONA)在一个单包中.

## 这是什么

一个自成一体的学习模块,记录了代理执行轨迹,将其分馏为可再用模式,为新任务取回匹配,并通过SONA + LORA + EWC++来适应. 被设计为克洛德·福林克(Claude Flow CLI)的智能层所构成的底物——包拥有算法,CLI拥有管弦乐.

## 安装

```bash
npm install @claude-flow/neural
```

> **注释(2026-05-16):** `@claude-flow/neural@3.0.0-alpha.9+` 针头 `@ruvector/sona` 到确切的已知善 `0.1.5` 因为 `@ruvector/sona@0.1.6` 作为空出版物(README +)发售 `package.json` 仅 -- -- 没有 `index.js`没有原生的垃圾桶). 先前的α.8 使用过的 `"latest"` 并打破了每一个新安装。 针会 一直停留到 `@ruvector/sona@0.1.7+` 有内容的船只.

## 独立使用(没有 Ruflo CLI)

```typescript
// route a task across 8 specialized experts (MoE) — no other deps
import { getMoERouter } from '@claude-flow/neural';

const router = getMoERouter();
await router.initialize();

const decision = await router.route(
  new Float32Array(384).fill(0.1),   // task embedding
  { task: 'optimize-query', complexity: 0.7 },
);
console.log(decision.expert, decision.confidence);
// → 'performance', 0.83  (or whichever expert wins)
```

## 快速启动( 建议)

`NeuralLearningSystem` 是高级的切入点——它连接 `SONAManager`, (中文(简体) ), `ReasoningBank`,以及 `PatternLearner` 所以来电者不必:

```typescript
import { createNeuralLearningSystem } from '@claude-flow/neural';

const sys = createNeuralLearningSystem('balanced');
await sys.initialize();

// Track a task
const id = sys.beginTask('Refactor auth middleware', 'code');

// Record steps as the agent works (Float32Array embeddings)
sys.recordStep(id, 'analyzed-imports', 0.8, embedding1);
sys.recordStep(id, 'extracted-helpers',  0.9, embedding2);

// Complete — fires distillation + pattern extraction automatically
await sys.completeTask(id, /* qualityScore */ 0.85);

// Retrieve relevant memories for the next similar task
const memories = await sys.retrieveMemories(queryEmbedding, /* k */ 3);
const patterns = await sys.findPatterns(queryEmbedding, 3);

// Periodic learning sweep (consolidation + EWC)
await sys.triggerLearning();

console.log(sys.getStats());
// → { sona: NeuralStats, reasoningBank: { ... }, patternLearner: { ... } }
```

## 下层 API: SONA 管理器

对于想要直接管理轨迹和模式的呼叫者:

```typescript
import { createSONAManager, type Trajectory } from '@claude-flow/neural';

const sona = createSONAManager('balanced');
await sona.initialize();

// domain ∈ 'code' | 'creative' | 'reasoning' | 'chat' | 'math' | 'general'
const trajectoryId = sona.beginTrajectory('code-review-task', 'code');

sona.recordStep(trajectoryId, 'analyze-code',     0.8, stateEmbedding);
sona.recordStep(trajectoryId, 'generate-feedback', 0.9, nextStateEmbedding);

const trajectory: Trajectory = sona.completeTrajectory(trajectoryId, 0.85);

// Query patterns
const matches = await sona.findSimilarPatterns(contextEmbedding, /* k */ 3);

// Trigger consolidation manually
await sona.triggerLearning('manual');
sona.consolidateEWC();
```

## 学习模式

| 模式 | 适应 | 质量 | 内存 | 使用大小写 |
| --- | --- | --- | --: | --- |
| **实时** | < 0. 5ms (单位:千美元) | 70%+ | 25 个 MB | 低纬度生产 |
| **平衡** (默认) | < 18ms \[1\] 时 | 第75条 | 50 MB (英语) | 一般用途 |
| **研究** | < 100 分钟 | 95%+ | 100 MB (百兆瓦) | 深入探索 |
| **边缘** | < 1 分钟 | 80%+ | 5 个 MB | 资源受限 |
| **批次** | < 50 分钟 | 第八十五条 | 75 MB (英语) | 高通量 |

```typescript
await sys.setMode('research'); // or directly: await sona.setMode('research')
```

## 理性银行+模式Learner(可单独访问)

`NeuralLearningSystem` 作曲;也可以单独使用:

```typescript
import {
  createReasoningBank,
  createPatternLearner,
  createSONALearningEngine,
} from '@claude-flow/neural';

const bank = createReasoningBank();
await bank.storeTrajectory(trajectory);
await bank.judge(trajectory);
const distilled = await bank.distill(trajectory);

const learner = createPatternLearner();
learner.extractPattern(trajectory, distilled);
const matches = await learner.findMatches(queryEmbedding, 5);

const engine = createSONALearningEngine();
const adapted = await engine.adapt(input, /* domain */ 'code');
```

## RL算法(包括7个)

导入使用 `Algorithm` 在适用的情况下,后缀:

```typescript
import {
  PPOAlgorithm,         createPPO,         DEFAULT_PPO_CONFIG,
  A2CAlgorithm,         createA2C,         DEFAULT_A2C_CONFIG,
  DQNAlgorithm,         createDQN,         DEFAULT_DQN_CONFIG,
  QLearning,            createQLearning,   DEFAULT_QLEARNING_CONFIG,
  SARSAAlgorithm,       createSARSA,       DEFAULT_SARSA_CONFIG,
  DecisionTransformer,  createDecisionTransformer, DEFAULT_DT_CONFIG,
  CuriosityModule,      createCuriosity,   DEFAULT_CURIOSITY_CONFIG,
} from '@claude-flow/neural';

const ppo = createPPO({ learningRate: 0.0003, epsilon: 0.2, valueCoef: 0.5 });
const dqn = createDQN({ learningRate: 0.001, gamma: 0.99, epsilon: 0.1, targetUpdateFreq: 100 });

// Generic factory — pick algorithm by name
import { createAlgorithm, getDefaultConfig } from '@claude-flow/neural';
const algo = createAlgorithm('ppo', getDefaultConfig('ppo'));
```

## LoRA 配置

```typescript
const config = sona.getLoRAConfig();
// { rank: 4, alpha: 8, dropout: 0.05, targetModules: ['q_proj','v_proj','k_proj','o_proj'], microLoRA: false }

const weights = sona.initializeLoRAWeights('code-generation');
```

## EWC++ (弹性重量合并)

防止在适应新领域时发生灾难性的遗忘:

```typescript
const config = sona.getEWCConfig();
// { lambda: 2000, decay: 0.9, fisherSamples: 100, minFisher: 1e-8, online: true }

// After learning a new task, consolidate before moving on
sona.consolidateEWC();
```

## 事件系统

```typescript
sys.addEventListener((event) => {
  switch (event.type) {
    case 'trajectory_started':  console.log(`Started: ${event.trajectoryId}`); break;
    case 'trajectory_completed': console.log(`Quality: ${event.qualityScore}`); break;
    case 'pattern_matched':     console.log(`Pattern ${event.patternId} matched`); break;
    case 'learning_triggered':  console.log(`Learning: ${event.reason}`); break;
    case 'mode_changed':        console.log(`${event.fromMode} → ${event.toMode}`); break;
  }
});
```

## 业绩指标

| 度量衡 | 目标 | 典型 |
| --- | --- | --- |
| 适应延迟 | < 0.05 毫秒(秒) | 0.02毫秒(分钟) |
| 模式检索 | < 1 分钟 | 0.5 毫秒( 分钟) |
| 学习步骤 | < 10 分钟 | 5分钟 |
| 质量改进 | +55% (单位:千美元) | +40 - 60% |
| 内存间接费用 | < 50 MB 设备 | 25-75甲基溴 |

## 类型脚本

```typescript
import type {
  // Core
  SONAMode, SONAModeConfig, ModeOptimizations,
  Trajectory, TrajectoryStep, TrajectoryVerdict, DistilledMemory,
  Pattern, PatternMatch, PatternEvolution,

  // RL
  RLAlgorithm, RLConfig,
  PPOConfig, DQNConfig, A2CConfig, QLearningConfig, SARSAConfig,
  DecisionTransformerConfig, CuriosityConfig,

  // Neural
  LoRAConfig, LoRAWeights, EWCConfig, EWCState,
  NeuralStats, NeuralEvent, NeuralEventListener,
} from '@claude-flow/neural';
```

## 与 `@claude-flow/cli`

CLI的情报层(`hooks_intelligence_*`, (中文(简体) ), `neural_*` MCP工具, `/intelligence` 仪表板)是主要的消费者. 汇合的第一阶段(# 1773) 在 `cli/src/memory/neural-package-bridge.ts` 那些懒惰的货 `NeuralLearningSystem` 所以Cli的智能处理器 可以调用到包表面 与现有的本地执行。 未来阶段迁移cli's `LocalSonaCoordinator` 财务报告和审定财务报表 `LocalReasoningBank` 来包装此软件包 `SONALearningEngine` 财务报告和审定财务报表 `ReasoningBankAdapter`。 。 。 .

如果你正在建造一个需要神经学习的Ruflo插件,取决于 `@claude-flow/neural` 而不是直接进入cli内部.

## 依赖关系

-   [`@claude-flow/memory`](https://npmcn.com/package/%40claude-flow/memory) ——图案的向量内存
-   `@ruvector/sona` - SONA学习引擎

## 相关软件包

-   [`@claude-flow/memory`](https://npmcn.com/package/%40claude-flow/memory) ——内存后端
-   [`@claude-flow/cli`](https://npmcn.com/package/%40claude-flow/cli) − 初级消费者+ MCP 工具表面
-   [`@claude-flow/cli-core`](https://npmcn.com/package/%40claude-flow/cli-core) —— lite 路径( 无神经; 对于插件脚本)

## 许可证

麻省理工学院

## 常见问题

### @claude-flow/neural 是什么？

Claude Flow的自适应性神经结构\(SONA\)——适应性学习、轨迹跟踪、模式再利用、7个RL算法\(PPO/A2C/DQN/Q-Llearning/SARSA/决定变换器/Curiosity\),闪光注意、MOE路由、LORA、EWC\+\+用于持续脱落

### 如何安装 @claude-flow/neural？

在项目目录运行 npm install @claude-flow/neural，或使用 pnpm add / yarn add / bun add。

### @claude-flow/neural 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @claude-flow/neural 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @claude-flow/neural 可以商用吗？

@claude-flow/neural 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @claude-flow/neural 的下载量有多少？

根据 npm 官方下载统计，@claude-flow/neural 在 2026/10/10 – 2026/11/08 这 30 天内被下载 270,684 次，日均约 9,023 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @claude-flow/neural 还在维护吗？

最新版本 3\.0\.3 发布于 2026/11/06（3 天前）；至今共发布 10 个版本，其中过去 12 个月发布了 10 个；首次发布于 2026/01/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

