forked from fangtianchen/algonotes_rag
2.0 KiB
2.0 KiB
📥 导入工具 (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 |
标签提取 |
注意事项
- 互斥参数:
path和url必须且只能提供一个 - 文件命名:导入后文件名即唯一标识,平铺存储在
data/files/下 - 网页清洗:从 URL 导入时自动执行 LLM 清洗;本地导入默认不清洗
- 打 tag:需要调用 LLM,会增加处理时间,可设
tag: false跳过