algonotes_rag/docs/mcp/ingest.md

2.0 KiB
Raw Permalink Blame History

📥 导入工具 (ingest)

返回目录


功能

从本地文件/目录或 URL 导入笔记到三层存储。

参数

参数 类型 说明 默认值
path string | null 本地文件或目录路径 url 二选一
url string | null 网页 URL 地址 path 二选一
tag bool 提取标签 true
type string 笔记类型note/solution/template note
author string | null 笔记作者

使用示例

// 导入本地文件
{"path": "./my_notes/fenwick.md"}

// 导入整个目录
{"path": "./my_notes/"}

// 从 URL 导入
{"url": "https://cnblogs.com/xxx"}

// 跳过打 tag
{"path": "./my_notes/", "tag": false}

返回格式

单文件导入

{
  "file_name": "fenwick.md",
  "chunk_count": 13,
  "tags": "树状数组, 数据结构",
  "title": "树状数组",
  "note_id": 5
}

目录导入(数组):

[
  {
    "file_name": "fenwick.md",
    "chunk_count": 13,
    "tags": "树状数组, 数据结构",
    "title": "树状数组",
    "note_id": 5
  },
  {
    "file_name": "sgt1.md",
    "chunk_count": 8,
    "tags": "线段树, 数据结构",
    "title": "线段树",
    "note_id": 6
  }
]

错误

{"success": false, "error": "Must provide either path or url"}

依赖模块

模块 职责
scripts/ingest.py 导入逻辑
src/ingestion/loader.py 文件加载(本地/URL
src/ingestion/cleaner.py LLM 文本清洗
src/ingestion/splitter.py Markdown 分块
src/ingestion/tagger.py 标签提取

注意事项

  1. 互斥参数pathurl 必须且只能提供一个
  2. 文件命名:导入后文件名即唯一标识,平铺存储在 data/files/
  3. 网页清洗:从 URL 导入时自动执行 LLM 清洗;本地导入默认不清洗
  4. 打 tag:需要调用 LLM会增加处理时间可设 tag: false 跳过