algonotes_rag/docs/cli/ingest.md

157 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 📥 导入命令 (`ingest`)
> [返回目录](README.md)
---
## 功能
从本地文件/目录或 URL 导入笔记到三层存储。
## 参数
| 参数 | 缩写 | 说明 | 默认值 |
| ------ | ------ | ------ | ----- |
| `--path` | `-i` | 本地文件或目录路径 | 与 `--url` 二选一 |
| `--url` | `-u` | 网页 URL 地址 | 与 `--path` 二选一 |
| `--no-tag` | - | 跳过打 tag | `False` |
| `--verbose` | `-v` | 详细输出 | `False` |
| `--json` | - | 输出到 JSON 文件 | stdout使用时须指定文件路径 |
## 使用示例
```bash
# 全流程导入
algonotes ingest -i ./my_notes/
# 从 URL 导入(默认自动清洗)
algonotes ingest -u https://cnblogs.com/xxx
# 跳过打 tag
algonotes ingest -i ./my_notes/ --no-tag
# 详细输出(显示每个文件的处理细节)
algonotes ingest -i ./my_notes/ -v
# 输出到 JSON 文件
algonotes ingest -i ./my_notes/ --json result.json
```
## 输出示例
**单文件/URL 默认**
```text
✅ fenwick.md (13 chunks, tags: 树状数组,数据结构)
```
**目录导入默认**
```text
[1/3] fenwick.md
[2/3] segment-tree.md
[3/3] dijkstra.md
导入完成: 3 个文件
```
**verbose含清洗**
```text
[1/3] fenwick.md
清洗:
> 树状数组Binary Indexed Tree是一种用于处理前缀和查询的数据结构...
标题: 树状数组
分块: 8 块
打tag: 树状数组,模板
[2/3] segment-tree.md
清洗:
> 线段树支持区间查询和修改操作...
标题: 线段树
分块: 6 块
打tag: 线段树,数据结构
[3/3] dijkstra.md
清洗:
> Dijkstra 算法用于求解单源最短路径问题...
标题: Dijkstra 最短路
分块: 5 块
打tag: 图论,最短路
导入完成: 3 个文件,耗时 12.3s
```
> 💡 verbose 模式下,清洗内容会实时流式输出(网页导入默认启用清洗,本地导入默认不启用)
## 流程
```mermaid
graph TD
A[输入源] -->|-i / -u| B{文件类型}
B -->|本地 .md| C[Loader]
B -->|网页 URL| D[WebLoader]
C --> F[Splitter]
D -.->|默认清洗| E[Cleaner]
E --> F
F -->|--no-tag| G[跳过]
F -->|默认| H[Tagger]
H --> I[存储到三层]
G --> I
I --> J[data/files/]
I --> K[data/sql_db/]
I --> L[data/chroma_db/]
```
## 依赖模块
| 模块 | 职责 |
| ------ | ------ |
| `src/ingestion/loader.py` | 文件加载(本地/URL |
| `src/ingestion/cleaner.py` | LLM 文本清洗 |
| `src/ingestion/splitter.py` | Markdown 分块 |
| `src/ingestion/tagger.py` | 标签提取 |
| `src/store/file_store.py` | 文件存储 |
| `src/store/sql_store.py` | SQL 存储 |
| `src/store/vector_store.py` | 向量存储 |
## JSON 输出格式
使用 `--json <file>` 参数将结果保存到 JSON 文件。
**单文件导入**
```json
{
"file_name": "fenwick.md",
"chunk_count": 13,
"tags": "树状数组, 数据结构",
"title": "树状数组",
"note_id": 5
}
```
**目录导入**(数组):
```json
[
{
"file_name": "fenwick.md",
"chunk_count": 13,
"tags": "树状数组, 数据结构",
"title": "树状数组",
"note_id": 5
},
{
"file_name": "sgt1.md",
"chunk_count": 8,
"tags": "线段树, 数据结构",
"title": "线段树",
"note_id": 6
}
]
```
## 注意事项
1. **文件命名**:导入后文件名即唯一标识,平铺存储在 `data/files/`
2. **文件名冲突**:同名文件会自动添加时间戳后缀(如 `fenwick_20260616_143022.md`
3. **网页清洗**:从 URL 导入时,默认自动执行 LLM 清洗以去除网页噪声;本地导入默认不启用
4. **打 tag**:需要调用 LLM会增加处理时间可用 `--no-tag` 跳过