yr.al

GitHub - lichuang/docq: Local document Q&A in your terminal — powered by on-device LLMs.

2026-08-23 · 原文 ↗ · 本页为存档备份
命令行工具本地大语言模型文档问答语义搜索检索增强生成
docq 是一款运行于终端的本地优先文档检索与问答工具,借助设备端大语言模型离线搜索内容并生成带来源引用的答案,所有索引、模型和查询数据均保留在本机。它支持 Markdown、纯文本、PDF 和 Word 文档,可用于笔记、技术文档及研究论文,并支持中英文提问、JSON 输出和搜索评分解析。用户可通过 Cargo 安装,依次执行初始化工作区、添加文档目录和构建索引后使用 search 与 ask 命令;首次运行会下载所需模型,此后可完全离线工作。该项目采用 MIT 或 Apache-2.0 许可证,目前仍处于早期开发阶段,1.0 版本前命令行接口和配置可能发生变化。

Local-first search and answers for your documents.

docq (short for document query) is a local, offline-ready tool that helps you find information in your personal document collections and get cited answers. Everything stays on your machine: indexes, models, and queries.

What it does

  • search — Find the most relevant passages across your files. Fast, offline, no API calls.
  • ask — Get a natural-language answer synthesized from the retrieved passages, with inline citations pointing back to the source files.

Use it for notes, documentation, research papers, or any text-heavy directory.

Supported document formats

docq can index plain text and common document formats:

  • Markdown (.md) and plain text (.txt)
  • PDF (.pdf) — enabled by default via the pdf feature
  • Microsoft Word (.docx) — enabled by default via the docx feature

You can disable optional format support at build time with --no-default-features.

Install

cargo install --path crates/docq

Or, once published:

cargo install docq

Quick start

# Create a workspace (uses ~/.config/docq by default)
docq init

# Add a directory of documents
docq add ~/notes --name notes

# Build the index
docq index

# Search for passages
docq search "quarterly revenue"

# Ask a question and get a cited answer
docq ask "What was the revenue in Q2?"

Run docq --help and docq <command> --help to discover all options.

Example with the bundled test data

The repository includes sample documents under testdata/. These excerpts are from the public tutorial Distributed System Illustrated by codedump.info. You can try the CLI without preparing your own files:

docq init
docq add testdata/ --name notes
docq index

# Search for passages
docq search "Multi-Paxos improvements"

# Ask a question and get a cited answer
docq ask "What are the improvements of Multi-Paxos over the Paxos algorithm?"

# See step-by-step timing
docq ask "What are the improvements of Multi-Paxos over the Paxos algorithm?" -v

you can ask the same question in Chinese because docq also support Chinese:

docq  ask "multi paxos 相比 paxos 算法的改进点?"

Global options

Every command accepts these flags:

  • --workspace <path> — Use a different workspace directory. The workspace stores the index database.
  • --config <path> / -c <path> — Use a custom configuration file instead of the default.
  • --model-cache <path> — Store downloaded models in a custom location.

Examples:

docq --workspace ./project-kb init
docq --workspace ./project-kb --config ./project-kb/docq.toml add ./docs --name docs
docq --workspace ./project-kb search "deployment checklist" --json

Output formats

search, ask, and status support --json for machine-readable output:

docq search "budget approval" --json
docq ask "Who approved the budget?" --json
docq status --json

Use --explain with search to see the score breakdown:

docq search "budget approval" --explain

Configuration

The global configuration file is located at:

  • macOS / Linux: ~/.config/docq/config.toml
  • Windows: %LOCALAPPDATA%\docq\config.toml

It is created automatically the first time you run docq. You can override it with --config.

First-use downloads

The first time you index, search, or ask, docq downloads the required local models to --model-cache (~/.cache/docq/models by default). After that, everything works offline.

Status

Early development. The CLI and configuration may change before 1.0.

License

MIT OR Apache-2.0