algonotes_rag/docs/cli/delete.md

101 lines
2.0 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.

# 🗑️ 删除命令 (`delete`)
> [返回目录](README.md)
---
## 功能
从三层存储中删除笔记。
## 参数
| 参数 | 缩写 | 说明 | 默认值 |
|------|------|------|--------|
| `filename` | - | 笔记文件名(位置参数) | 必填 |
| `--force` | - | 跳过确认提示 | `False` |
| `--json` | - | 输出到 JSON 文件 | stdout使用时须指定文件路径 |
## 使用示例
```bash
# 删除单个笔记(需确认)
algonotes delete fenwick.md
# 强制删除(不确认)
algonotes delete fenwick.md --force
# 输出到 JSON 文件
algonotes delete fenwick.md --json result.json
```
## 输出示例
**默认**
```text
请确认删除 fenwick.md键入 stop 以撤销操作):
成功删除 fenwick.md
```
**强制删除**
```text
成功删除 fenwick.md
```
**文件不存在**
```text
fenwick.md 文件不存在,无法进行删除
```
## 删除逻辑
删除顺序:向量层 → 文件层 → 关系层
1. 删除所有分块向量Chroma
2. 删除原始文件FileStore
3. 删除元数据记录SQLite
## 流程
```mermaid
graph TD
A[输入 filename] --> B{笔记是否存在?}
B -->|否| C[返回错误]
B -->|是| D{--force?}
D -->|否| E[等待用户确认]
E -->|stop| F[退出]
E -->|继续| G[删除向量]
D -->|是| G
G --> H[删除文件]
H --> I[删除 SQL 记录]
I --> J[返回成功]
```
## 依赖模块
| 模块 | 职责 |
|------|------|
| `src/store/vector_store.py` | 向量存储 |
| `src/store/file_store.py` | 文件存储 |
| `src/store/sql_store.py` | SQL 存储 |
## JSON 输出格式
使用 `--json <file>` 参数将结果保存到 JSON 文件。
```json
{
"file_name": "fenwick.md",
"success": true
}
```
## 注意事项
1. **删除顺序**:按照向量层 → 文件层 → 关系层的顺序删除,确保数据一致性
2. **确认提示**:默认需要用户确认,使用 `--force` 可跳过确认
3. **文件不存在**:如果笔记不存在,会返回错误信息