algonotes_rag/docs/cli/update.md

4.1 KiB
Raw Permalink Blame History

✏️ 更新命令 (update)

返回目录


功能

更新笔记内容或元数据。

子命令

子命令 用途
content 更新笔记内容(重新处理文件)
metadata 更新笔记元数据(不修改内容)

content — 更新笔记内容

参数

参数 缩写 说明 默认值
filename - 笔记文件名(位置参数) 必填
--file - 新的本地文件路径
--no-tag - 跳过打 tag False
--verbose -v 详细输出 False
--json - 输出到 JSON 文件 stdout

使用示例

# 更新本地笔记
algonotes update content fenwick.md --file ./updated_fenwick.md

# 更新 URL 笔记(从原页面重新爬取)
algonotes update content cnblogs_xxx.md

# 输出到 JSON 文件
algonotes update content fenwick.md --file ./new.md --json result.json

输出示例

Update success: fenwick.md (13 chunks)

更新逻辑

  • 本地笔记:必须指定 --file,根据新文件更新三层存储(默认不启用清洗)
  • URL 笔记:无需额外参数,从数据库调取原 URL → 重新爬取 → 更新三层存储(默认启用清洗)

metadata — 更新笔记元数据

参数

参数 缩写 说明 默认值
filename - 笔记文件名(位置参数) 必填
--title - 新标题 不修改
--tags - 新标签(逗号分隔) 不修改
--author - 新作者 不修改
--type - 笔记类型note/solution/template 不修改
--json - 输出到 JSON 文件 stdout

使用示例

# 更新作者
algonotes update metadata fenwick.md --author fangtianchen

# 更新标签和类型
algonotes update metadata fenwick.md --tags "树状数组,BIT" --type template

# 同时更新多个字段
algonotes update metadata fenwick.md --title "树状数组模板" --author fangtianchen --type template

# 输出到 JSON 文件
algonotes update metadata fenwick.md --author fangtianchen --json result.json

输出示例

Metadata updated: fenwick.md (author, type)

更新逻辑

  • 轻量更新:只修改 SQL 和 vector metadata不重新处理文件内容
  • 不重算 hashcontent_hash 保持不变
  • vector 更新tags 会同步到向量库(原地更新,无需重新 embedding

流程

graph TD
    A[输入] -->|filename| B{笔记是否存在}
    B -->|否| C[返回错误]
    B -->|是| D{有 --file 参数?}
    D -->|是| E[Loader 加载新文件]
    D -->|否| F{有 source_url?}
    F -->|否| C
    F -->|是| G[WebLoader 重新爬取]
    G -.->|默认清洗| H[Cleaner]
    E --> I[删除旧向量]
    H --> I
    I --> J[Splitter 分块]
    J -->|--no-tag| K[跳过]
    J -->|默认| L[Tagger 提取标签]
    L --> M[更新三层存储]
    K --> M
    M --> N[data/files/]
    M --> O[data/sql_db/]
    M --> P[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 文件。

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

注意事项

  1. 笔记必须存在:更新前会检查笔记是否存在,不存在则返回错误
  2. 本地笔记:必须指定 --file 参数提供新文件路径
  3. URL 笔记:无需 --file,从数据库调取原 URL 重新爬取
  4. 覆写原文件:更新操作直接覆写 data/files/ 中的原文件,不会创建新文件
  5. 打 tag:需要调用 LLM会增加处理时间可用 --no-tag 跳过