anygrep 发布:在 CPU 上对笔记、PDF 和图片做语义搜索
Show HN: anygrep – semantic search over notes, PDFs and images, on the CPU
anygrep 是一个在终端运行的语义搜索工具,可对笔记、PDF 和截图按含义检索,全程在 CPU 上运行 EmbeddingGemma 2 的 int8 ONNX 模型并维护本地索引。
anygrep 从终端按语义搜索你的笔记、PDF 和截图。它在 CPU 上运行一个模型 (EmbeddingGemma 2,int8 ONNX),并维护一个 本地索引。
演示搜索的是一个已建立索引的文件夹,模型加载的等待时间被加速了。
安装
pipx install anygrep # or: uv tool install anygrep uvx anygrep "when is the tax return due" ~/notes # or try it without installing
需要 Python 3.10+。已在 Linux 上测试;CI 也会在 Windows 和 macOS(Apple 芯片)上运行测试。 模型在首次使用时下载:约 350 MB,索引图像后再增加 200 MB。关于 Intel Mac、Windows on ARM 和卸载,请参见 docs/usage.md。
用法
anygrep "wifi password reset" # search here (new files are indexed first) anygrep "when is the tax return due" ~/notes # search one folder anygrep --image whiteboard.jpg ~/Screenshots # find similar pictures anygrep -l "invoice from acme" # file names only; piped output is path:line:text anygrep -Q ~/notes # interactive: the model stays loaded anygrep index --background ~/Pictures # big folder: index in a low-priority process
结果最多为 10 个文件,按语义最接近排序(-m N 查看更多),并非所有匹配;查询不是
正则表达式。如果文件的文本或名称按原样包含 3 个或更多字符的查询(例如
发票号、错误代码),该文件会排在最前,并标记为 (exact);出现在许多文件中的词不会因此
被提升(详情)。查询和文档可以使用不同语言。
弱匹配会被隐藏(--weak 显示它们),近似重复的文件只显示一次。参见 anygrep -h
和 docs/usage.md。
在终端中,大文件夹里的首次搜索会先索引新文件,并显示进度条;按 Ctrl-C
会保留已完成的部分,下次运行会继续。index --background 会在你工作时进行(你的主
文件夹永远不会被自动索引,所以要指定其中的一个文件夹)。在脚本或 cron 任务中,搜索
仅当索引新文件耗时约 30 秒以内时才会进行;对于大
文件夹,请事先运行 anygrep index(详情)。
它会读取文本文件(.md .txt .html 及更多)、PDF 的文本层,以及 .jpg .png .webp .bmp .gif 图像。隐藏、被忽略和二进制文件会被跳过。
从 Python 使用
import anygrep with anygrep.Index() as idx: # the index the command uses idx.update("~/notes") # index new and changed files for hit in idx.search("when is the tax return due", k=5): print(hit.score, hit.path, hit.snippet)
在你的项目环境中用 pip 安装。它使用与命令行相同的索引、评分和过滤,并且不打印任何内容。API 在 1.0 之前可能变化;参见 docs/python-api.md。
性能
在 Ryzen 7 7700 上使用默认的 8 线程,文本索引速度约为 1,100 tokens/s,一张图像约需 1.2 秒。搜索命令约需 1.5 秒,主要是加载模型。更多内容见 docs/benchmarks.md。
限制
- 没有 OCR:图像中的小字常被遗漏,扫描版 PDF 会被跳过。
- 尚不支持音频、视频或 Office 文档(anygrep 会说明跳过了多少 Office 文件),也不支持
文件监视(从 cron 运行
anygrep index)。
许可证
MIT。模型单独下载: Google 的 EmbeddingGemma 2 的 int8 ONNX 转换版, 以 Apache License 2.0 发布(其模型卡还指向 Gemma 禁止使用政策)。anygrep 与 Google 无关联。
来源:Hacker News · github.com
