원클릭으로
hai-datapipe
使用 @h-ai/datapipe 进行文本清洗(HTML/URL/空白移除)、多模式分块(句子/段落/Markdown/字符/自定义)和管线组合;当需求涉及文本预处理、文档分块、数据清洗或 RAG 入库前处理时使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
使用 @h-ai/datapipe 进行文本清洗(HTML/URL/空白移除)、多模式分块(句子/段落/Markdown/字符/自定义)和管线组合;当需求涉及文本预处理、文档分块、数据清洗或 RAG 入库前处理时使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Use when: using @h-ai/ai, LLM calls, chat completion, tool calling, function calling, MCP server, streaming, memory management, context compression, summarization, token estimation, RAG, knowledge base, AI client, embeddings, reasoning, rerank, file parsing, speech recognition ASR, speech synthesis TTS, audio, A2A agent-to-agent. 使用 @h-ai/ai 进行 LLM 调用、工具定义、MCP 服务器、流式处理、记忆管理、上下文压缩、知识库、推理引擎、Rerank、文件解析、语音识别与合成、A2A 与会话持久化。
Use when: using @h-ai/ai for LLM calls, tools, MCP, streaming, memory/context, RAG, audio, A2A, or the AI client. 当需求涉及 AI 对话、工具、Audio、会话、知识库或 AI 客户端时使用。
Use when: creating or extending apps in hai-framework, adding routes, pages, API endpoints, service workspaces, mobile app, H5 app, admin console. 在 hai-framework 中创建或扩展应用或 API service workspace,包含路由、API 端点、typed contract、服务层与 UI 脚手架代码。
Use when: creating a new module, new package, scaffold, add sub-feature, add provider, create repository, module structure, tsup config, error codes, NotInitializedKit pattern. 在 hai-framework 中创建新模块(package)。
Use when: reviewing app code in hai-framework, auditing app quality, checking app conventions, reviewing routes, reviewing API service workspaces, app security, app i18n review. 对 hai-framework 应用层代码进行审查:路由安全 → 认证授权 → i18n → 组件使用 → API 端点 / service workspace → 服务层 → 性能。
Use when: reviewing code, code review, auditing module quality, checking hai-framework conventions, verifying HaiResult<T> usage, reviewing module structure, PR review, checking naming consistency, verifying NotInitializedKit pattern, auditing performance, security, distributed systems. 对 hai-framework 模块进行全维度代码审查:架构 → 命名 → 类型 → 注释 → 性能 → 分布式 → 安全 → 日志 → 测试 → 文档。
| name | hai-datapipe |
| description | 使用 @h-ai/datapipe 进行文本清洗(HTML/URL/空白移除)、多模式分块(句子/段落/Markdown/字符/自定义)和管线组合;当需求涉及文本预处理、文档分块、数据清洗或 RAG 入库前处理时使用。 |
| 项目 | 契约 |
|---|---|
| 能力 | 使用 @h-ai/datapipe 进行文本清洗(HTML/URL/空白移除)、多模式分块(句子/段落/Markdown/字符/自定义)和管线组合;当需求涉及文本预处理、文档分块、数据清洗或 RAG 入库前处理时使用。 |
| 适用场景 | 当任务与 hai-datapipe 的能力描述匹配,并且需要遵循本 Skill 的流程和边界时 |
| 输入 | 模块配置、类型化业务参数、依赖初始化状态和目标运行环境 |
| 输出 | 符合模块公共 API 的实现或示例;业务结果使用 HaiResult,并同步必要测试与文档 |
| 限制 | 遵守 init → use → close 生命周期与运行环境边界;不绕过类型、授权、输入校验或敏感信息保护 |
@h-ai/datapipe提供文本清洗(clean)、多模式分块(chunk)和可组合管线(pipeline),纯函数模块,无需初始化。
服务端模块(Node.js only)。 通常在 AI 知识库入库或文档预处理场景中使用,由
@h-ai/ai内部调用或在服务端显式调用。
import { datapipe } from '@h-ai/datapipe'
// 清洗
const cleaned = datapipe.clean(htmlText, { removeHtml: true, removeUrls: true })
// 分块
const chunks = datapipe.chunk(cleaned.data, { mode: 'markdown', maxSize: 2000, overlap: 200 })
const result = await datapipe.pipeline()
.clean({ removeHtml: true, removeUrls: true })
.transform(text => text.toLowerCase())
.chunk({ mode: 'paragraph', maxSize: 1000, overlap: 100 })
.chunkTransform(chunks => chunks.filter(c => c.content.length > 50))
.run(rawText)
if (result.success) {
// result.data => { text: string, chunks: DataChunk[] }
}
datapipe.cleandatapipe.clean(text: string, options?: CleanOptionsInput): HaiResult<string>
CleanOptionsInput:
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
removeHtml | boolean | true | 移除 HTML 标签 |
removeUrls | boolean | false | 移除 URL |
removeEmails | boolean | false | 移除 Email 地址 |
normalizeWhitespace | boolean | true | 多空格→单空格、去多余空行 |
trim | boolean | true | 去除首尾空白 |
customReplacements | { pattern, replacement }[] | — | 自定义正则替换规则 |
datapipe.chunkdatapipe.chunk(text: string, options: ChunkOptionsInput): HaiResult<DataChunk[]>
ChunkOptionsInput:
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
mode | ChunkMode | — | 分块模式(必填) |
maxSize | number | 1000 | 分块最大大小 |
overlap | number | 0 | 重叠大小(上下文衔接) |
separator | string | — | 自定义分隔符正则(mode=custom) |
markdownMinLevel | number | 2 | Markdown 最低标题级别(1-6) |
markdownKeepTitle | boolean | true | 分块中保留 Markdown 标题 |
分块模式:
| 模式 | 说明 |
|---|---|
sentence | 按句子(中英文句号/问号/感叹号) |
paragraph | 按段落(双换行) |
markdown | 按 Markdown 标题层级 |
page | 按分页符(\f) |
word | 按字数 |
character | 按字符数 |
custom | 自定义正则分隔符 |
DataChunk:
interface DataChunk {
index: number // 分块索引(从 0 开始)
content: string // 分块内容
metadata?: Record<string, unknown> // 元数据(Markdown 模式含 title、level)
}
datapipe.pipeline()datapipe.pipeline()
.clean(options?) // 添加清洗步骤
.transform(fn) // 添加文本转换步骤(同步/异步)
.chunk(options) // 添加分块步骤
.chunkTransform(fn) // 添加分块后处理步骤
.run(text) // 执行管线 → Promise<HaiResult<PipelineResult>>
PipelineResult:
interface PipelineResult {
text: string // 处理后的文本(分块前的最终文本)
chunks: DataChunk[] // 分块列表(如果管线包含 chunk 步骤)
}
HaiDatapipeError| 错误码 | code | 说明 |
|---|---|---|
HaiDatapipeError.CLEAN_FAILED | hai:datapipe:001 | 清洗失败 |
HaiDatapipeError.CHUNK_FAILED | hai:datapipe:002 | 分块失败 |
HaiDatapipeError.TRANSFORM_FAILED | hai:datapipe:003 | 转换失败 |
HaiDatapipeError.PIPELINE_FAILED | hai:datapipe:004 | 管线执行失败 |
HaiDatapipeError.CONFIG_ERROR | hai:datapipe:005 | 配置错误 |
HaiDatapipeError.MISSING_SEPARATOR | hai:datapipe:006 | 自定义分隔符缺失 |
import { datapipe } from '@h-ai/datapipe'
import { ai } from '@h-ai/ai'
import { vecdb } from '@h-ai/vecdb'
// 清洗 + Markdown 分块
const result = await datapipe.pipeline()
.clean({ removeHtml: true, removeUrls: true })
.chunk({ mode: 'markdown', maxSize: 1000, overlap: 100 })
.run(rawDocument)
if (!result.success) return result
// 生成嵌入
const embeddings = await ai.embedding.embedBatch(
result.data.chunks.map(c => c.content),
)
if (!embeddings.success) return embeddings
// 入库
const docs = result.data.chunks.map((chunk, i) => ({
id: `chunk-${i}`,
vector: embeddings.data[i],
content: chunk.content,
metadata: chunk.metadata,
}))
await vecdb.vector.insert('knowledge', docs)
const result = await datapipe.pipeline()
.clean({ removeHtml: true, removeEmails: true })
.transform(text => text.replace(/\[.*?\]/g, '')) // 移除 [注释]
.transform(text => text.replace(/\(https?:.*?\)/g, '')) // 移除 Markdown 链接 URL
.chunk({ mode: 'paragraph', maxSize: 800 })
.chunkTransform(chunks => chunks.filter(c => c.content.length > 20)) // 过滤过短分块
.run(rawText)
import { datapipe, HaiDatapipeError } from '@h-ai/datapipe'
const result = datapipe.chunk(text, { mode: 'custom' })
if (!result.success) {
switch (result.error.code) {
case HaiDatapipeError.MISSING_SEPARATOR.code:
// mode='custom' 时需提供 separator
break
case HaiDatapipeError.CONFIG_ERROR.code:
// 配置参数校验失败
break
}
}
hai-vecdb:向量数据库存储(分块后入库)hai-ai:LLM 与 Embedding 能力hai-core:HaiResult 模型