快速上手
构建一个示例索引,再通过 AI Agent 或终端完成检索。
准备示例书架
下载两本公版书,并使用英文检索模型建立索引:
mkdir zg-mystery && cd zg-mystery
curl --retry 3 --retry-all-errors --progress-bar -fL \
-o alice-in-wonderland.txt https://raw.githubusercontent.com/GITenberg/Alice-s-Adventures-in-Wonderland_11/master/11.txt \
-o sherlock-holmes.txt https://raw.githubusercontent.com/GITenberg/The-Memoirs-of-Sherlock-Holmes_834/master/834.txt
zg index --embedding local/potion-retrieval-32m示例工作区是英文小说,因此这里显式覆盖了面向代码的默认模型。
检索
面向 Agent:通过 OpenCode 提问
安装 OpenCode 后运行:
zg install --target opencode --yes
opencode run --model opencode/deepseek-v4-flash-free \
"An unseen creature left a few marks. What did the detective infer? Cite local evidence."OpenCode 会自行选择 Zvec-Grep,提示词无需指定工具。
Agent 返回示例
⚙ zvec_grep_zvec_grep_search {"root":".../zg-mystery","query":"An unseen creature left a few marks. What did the detective infer?","fts":["marks","unseen creature","inferred","detective"],"fuse":true}
→ Read sherlock-holmes.txt [offset=5440, limit=120]
回答:
侦探是《驼背人》中的 Sherlock Holmes。他从动物留下的痕迹判断:
- 它不是常见动物,脚印有五个肉垫和长指甲;
- 它身体很长,但腿很短;
- 它爬向金丝雀笼,因此属于食肉动物;
- 它很可能是体型异常巨大的鼬或白鼬。
证据:sherlock-holmes.txt:5479-5516不同 Agent 和模型的措辞可能不同,但引用的证据应基本一致。
面向用户:直接使用 CLI 检索
用户可以通过 CLI 直接检索同一个书架:
zg query --human \
"An unseen creature left a few marks. What did the detective infer?" \
--limit 3Zvec-Grep 应优先返回 sherlock-holmes.txt 中的相关段落,并附带可核验的来源位置。