展示HN:便携式RAG(开源)
有一类文本,它的大小超出了上下文窗口的限制,但又不足以使用向量数据库。这包括代码库、笔记文件夹、Slack 导出等。我开发了一个小库——raglet,来解决这个问题。
你可以在 Python 中使用它,例如:
```python
from raglet import RAGlet
rag = RAGlet.from_files(["docs/", "notes.md"])
results = rag.search("我们对 API 设计的决定是什么?", top_k=5)
rag.save("my-notes")
```
可以在任何地方加载:
```python
rag = RAGlet.load("my-notes")
```
它使用本地嵌入(sentence-transformers,无需 API 密钥),并保存到一个可以进行 git 提交的普通目录。
基准测试的结果比我预期的更有趣:
- 1 MB (~262K tokens) | 构建时间 3.5 秒 | 搜索时间 3.7 毫秒
- 10 MB (~2.6M tokens) | 构建时间 35 秒 | 搜索时间 6.3 毫秒
- 100 MB (~26M tokens) | 构建时间 6 分钟 | 搜索时间 10.4 毫秒
限制:目前仅支持 .txt 和 .md 文件(PDF/DOCX 是下一个目标),没有文件更改检测,构建时间在 ~100 MB 时会变得不便。
这对你的工作流程有什么帮助呢?
查看原文
There's a class of text that's too big for a context window but too small to justify a vector database. A codebase, a folder of notes, a Slack export. I built a small library - raglet - to solve this problem raglet for it.<p>You can use it in Python
i.e<p>from raglet import RAGlet
rag = RAGlet.from_files(["docs/", "notes.md"])
results = rag.search("what did we decide about the API design?", top_k=5)
rag.save("my-notes")<p>Load it anywhere<p>rag = RAGlet.load("my-notes")<p>It uses local embeddings (sentence-transformers, no API keys), saves to a plain directory you can git commit.<p>The benchmark numbers were more interesting than I expected:<p>1 MB (~262K tokens) | 3.5s build | 3.7ms search 10 MB (~2.6M tokens) | 35s build | 6.3ms search 100 MB (~26M tokens) | 6min build | 10.4ms search<p>limitations: .txt and .md only right now (PDF/DOCX is next), no file change detection, ~100 MB practical ceiling before build time gets unwieldy.<p>What would make this useful for your workflow?