# DocSummarizer Part 2 - 使用工具

<!--category-- AI, LLM, RAG, C#, Docling, Ollama, Qdrant, Tools -->
<datetime class="hidden">2025-12-21T11:00</datetime>

[![释放GitHub](https://img.shields.io/github/v/release/scottgal/mostlylucidweb?filter=docsummarizer*&label=docsummarizer)](https://github.com/scottgal/mostlylucidweb/releases?q=docsummarizer)
[![网 网 网](https://img.shields.io/badge/.NET-9.0-512BD4)](https://dotnet.microsoft.com/)
[![版本版本版本版本版本](https://img.shields.io/badge/version-3.1.0-blue)](https://github.com/scottgal/mostlylucidweb/releases?q=docsummarizer)

这是 **第二部分 第二部分** DocSummerizer 系列中的文档合成器序列。请参见 [第一部分 第一部分](/blog/building-a-document-summarizer-with-rag) 用于构建和模式,或 [第三部分 第三部分](/blog/docsummarizer-advanced-concepts) 深层技术潜入嵌入和检索。

> **将文档或 URL 转换成有证据依据的摘要 -- -- 供人类或AI 代理商使用 -- -- 而不向云中发送任何信息。**

每一个索赔要求都是可追踪的,每个事实都引证了它的来源。自成一体的二进制,完全在你的机器上运行。

```bash
# Human-readable summary
docsummarizer -f contract.pdf

# JSON for agents/pipelines
docsummarizer tool -u "https://docs.example.com"
```

**本条所包括的内容**:安装、关键模式(自动/自动/自动拉格/贝特)、模板和通用案例。

**所不包含的**: 完全命令参考、 配置选项、 排除故障、 架构细节 。

完整文件见 [读读](https://github.com/scottgal/mostlylucidweb/blob/main/Mostlylucid.DocSummarizer/README.md)如何在内部运行,请看 [第三部分 第三部分](/blog/docsummarizer-advanced-concepts).

[TOC]

## 为何存在

大部分总结者都给你文本。这给了你 *证据证据证据*.

- **每项索赔包括 `[chunk-N]` 引用引用** 返回源材料
- **信任度** 基于佐证证据的(高/中/中/低)
- **结构化 JSON 输出** 用于代理集成、CI管道或MCP服务器
- **质量指标** 趁他们逃跑前 捕捉幻觉

需要时 *信任信任信任* 一份重要摘要,或将其输入另一个系统。

## 特征特征

- **伯特拉格输油管**:生产级BERT提取 检索 LLM合成
- **自动模式**:基于文档和查询的智能模式选择
- **伯特模式**:纯采掘总结-不需要LLM,在离线工作(~3-5s)
- **实证四舍实产出**:引用、信任度、可追踪的索赔
- **多个模式**自动、BertRag、Bert、BertHybrid、MapReduce、Rag、迭代
- **工具工具模式**:为LLM代理商、MCP服务器、CI检查提供干净的JSON JSON
- **13个模板**:违约、写作、简短、单条、子弹、执行、详细、技术、学术、引文、书报、会议、严格
- **大型文件**:处理500页以上的分级处理页数
- **Web 获取中**安全强化(SSRF保护、HTML净化)
- **laywright 模式**: JavaScript 发送页面( SPAs, React Apps) 无头浏览器
- **ONNX 嵌入装置**: 零配置本地嵌入器 - 模型自动下载首次使用时自动下载
- **质量分析**:幻觉探测、实体抽取
- **具有弹性的LLM**: 以 Polly 为基础重试, 使用 jitter 后端 + 断路器
- **仅本地**:没有东西离开你的机器

## 用作 LLM 工具

缩略 `tool` 其产出结构为JSON, 带有证据确凿的主张, 最适合建造RAG管道或代理工具。

### 基本工具使用工具

```bash
# Summarize a URL and get JSON output
docsummarizer tool --url "https://example.com/docs.html"

# Summarize a local file
docsummarizer tool -f document.pdf

# With a focus query
docsummarizer tool -f contract.pdf -q "payment terms and conditions"

# Pipe to jq for processing
docsummarizer tool -f doc.pdf | jq '.summary.keyFacts'
```

### 工具输出结构

工具指令返回结构化的JSON, 附有证据追踪:

```json
{
  "success": true,
  "source": "https://example.com/docs.html",
  "contentType": "text/html",
  "summary": {
    "executive": "Brief summary of the document.",
    "keyFacts": [
      {
        "claim": "The system supports 10,000 TPS.",
        "confidence": "high",
        "evidence": ["chunk-3", "chunk-7"],
        "type": "fact"
      }
    ],
    "topics": [
      {
        "name": "Architecture",
        "summary": "The system uses microservices...",
        "evidence": ["chunk-1", "chunk-2"]
      }
    ],
    "entities": {
      "people": ["John Smith"],
      "organizations": ["Acme Corp"],
      "concepts": ["OAuth 2.0", "REST API"]
    },
    "openQuestions": ["What is the disaster recovery plan?"]
  },
  "metadata": {
    "processingSeconds": 12.5,
    "chunksProcessed": 15,
    "model": "qwen2.5:1.5b",
    "mode": "MapReduce",
    "coverageScore": 0.95,
    "citationRate": 1.2,
    "fetchedAt": "2025-01-15T10:30:00Z"
  }
}
```

### 工具命令选项

```bash
docsummarizer tool [options]
```


|--------|-------|-------------|
| `--url` | `-u` 获取和总结的 URL @ URL @ label
| `--file` | `-f` 
| `--query` | `-q` 可选焦点查询 {
| `--mode` | `-m` 总结模式(自动、BertRag、Bert、BertHybrid、MapReduce、Rag、迭代)
| `--model` 使用奥拉马模式的奥拉马模式
| `--config` | `-c` 配置文件路径

### 关键设计原则

- **证据依据**:每项索赔包括 `evidence` 引用源块的 ID
- **信任度**:对索赔进行评级 `high`, `medium`,或 `low` 基于佐证证据
- **清洁输出**: 变化: `executive` 摘要中没有用于轻松显示的引用标记
- **元元元元元数据**:处理统计数据有助于调试和质量评估
- **错误处理错误处理**:失败返回 `success: false` 具有 a 和 `error` 消息消息

### 整合实例

**Python 脚本 :**

```python
import subprocess
import json

result = subprocess.run(
    ["docsummarizer", "tool", "-u", "https://example.com/api-docs"],
    capture_output=True, text=True
)
data = json.loads(result.stdout)

if data["success"]:
    for fact in data["summary"]["keyFacts"]:
        if fact["confidence"] == "high":
            print(f"- {fact['claim']}")
```

**壳牌输油管:**

```bash
# Extract high-confidence facts only
docsummarizer tool -f doc.pdf | jq '[.summary.keyFacts[] | select(.confidence == "high")]'

# Get just the executive summary
docsummarizer tool -u "https://example.com" | jq -r '.summary.executive'
```

## 快速启动

### 下载预建的二进制

预建本地可执行文件 [GitHub 释放](https://github.com/scottgal/mostlylucidweb/releases?q=docsummarizer):

平台 建筑 下载 下载
|----------|--------------|----------|
窗口  x64 `docsummarizer-win-x64.zip` |
* Windows * ARM64 * 視窗 * * 視窗 * ARM64 * `docsummarizer-win-arm64.zip` |
* Linux * * x64 * * Linux * * * X64 * * Linux * * Linux * * * X64 * * Linux * * Linux * * * Linux * * * * X64 * * * Linux * * Linux * * Linux * * * * * Linux * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * `docsummarizer-linux-x64.tar.gz` |
* Linux * ARM64 * * Linux * ARM64 * * Linux * RAR64 * `docsummarizer-linux-arm64.tar.gz` |
* MacOS  X64 (英特尔) * * * * MacOS  * * x64 (英特尔) * * * * maceOS  * * * intel * * * * * macOS * *% * * x64 (intel) * * * * * macOS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * `docsummarizer-osx-x64.tar.gz` |
马可斯 ARM64 (苹果硅) * * * 苹果硅 * * 马可斯 ARM64 (Apple Silicon) * * * * 马可斯 ARM64 (Apple Silicon) * * * 马可斯 * 马可斯 * ARM64 (Apple Silicon) * * * * 马可斯 * 马可斯 * ARM64 (Apple Silicon) * * * * `docsummarizer-osx-arm64.tar.gz` |

```bash
# Download and extract (Linux/macOS)
curl -L -o docsummarizer.tar.gz https://github.com/scottgal/mostlylucidweb/releases/download/docsummarizer-v3.1.0/docsummarizer-linux-x64.tar.gz
tar -xzf docsummarizer.tar.gz
chmod +x docsummarizer

# Download and extract (Windows PowerShell)
Invoke-WebRequest -Uri "https://github.com/scottgal/mostlylucidweb/releases/download/docsummarizer-v3.1.0/docsummarizer-win-x64.zip" -OutFile "docsummarizer.zip"
Expand-Archive -Path "docsummarizer.zip" -DestinationPath "."
```

### 先决条件

#### Bert 模式( 无外部服务)

对于纯粹的采掘总结, **不需要外部服务**:

```bash
docsummarizer -f document.md -m Bert
```

ONNX 模型在第一次使用时从 Hugging Face 自动卸载(~ 23MB) 。 返回时间为~ 3-5 秒 。

#### LLM 模式(自动、BertRag、MapReduce等)

对于LLM-电力总和,Ollama需要:

```bash
# Install Ollama from https://ollama.ai
ollama pull llama3.2:3b        # Default model - good balance of speed/quality
ollama serve
```

> **速度提示**:用于快速摘要(~3s 和~15s),使用 `--model qwen2.5:1.5b`

#### 可选: 备注( 硬格式)

PDF、DOCX、XLSX、PPTX、HTML、图像(PNG/JPG/TIFF)、CSV、VTT和AsciiDoc文件所需的文件。 **直接读取 Markdown 和 普通文本文件 - 不需要 docling 。**

```bash
docker run -d -p 5001:5001 quay.io/docling-project/docling-serve
```

#### 可选: Qdrant (活性矢量存储)

默认不需要 - BertRag 使用模拟矢量。 启用 Qdrant 用于持久性存储, 以避免以后运行时重新组合文档 :

```bash
docker run -d -p 6333:6333 -p 6334:6334 qdrant/qdrant
```

然后配置 `docsummarizer.json`:

```json
{
  "bertRag": {
    "vectorStore": "Qdrant",
    "collectionName": "docsummarizer",
    "persistVectors": true
  }
}
```

#### 可选:Ollama嵌入式

如果您更喜欢 Ollama 嵌入, 而不是 ONNX :

```bash
ollama pull nomic-embed-text   # Or mxbai-embed-large
# Then use: --embedding-backend Ollama
```

### 核查依赖性

```bash
docsummarizer check --verbose
```

预期输出显示格式化表格 :

```
              Dependency Status              
╭─────────┬────────┬────────────────────────╮
│ Service │ Status │ Endpoint               │
├─────────┼────────┼────────────────────────┤
│ Ollama  │   OK   │ http://localhost:11434 │
│ Docling │ Optional │ http://localhost:5001 │
│ Qdrant  │ Optional │ localhost:6333        │
╰─────────┴────────┴────────────────────────╯

        Default Model Info         
╭────────────────┬────────────────╮
│ Property       │ Value          │
├────────────────┼────────────────┤
│ Name           │ llama3.2:3b    │
│ Family         │ llama          │
│ Parameters     │ 3.2B           │
│ Context Window │ 128,000 tokens │
╰────────────────┴────────────────╯

Ready to summarize! Ollama is available.
```

> **注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注的注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注注**: docling 和 Qdrant 显示 

## 用法

### 默认行为行为

运行中 `docsummarizer` 没有论据将:

1. 查找 `README.md` 在当前目录中
2. 使用 **自动自动模式** (智能模式选择)
3. 用一个漂亮的面板 UI 打印到控制台的概要
4. 自动保存到 `readme.summary.md`

```bash
# Summarize README.md in current directory
docsummarizer

# Shows a formatted panel with:
# - Document info table (file, mode, model)
# - Progress indicators during processing
# - Summary panel with the result
# - Topics tree if available
# - Saved: readme.summary.md
```

### 基本概况

```bash
# Just run it - Auto mode picks the best approach
docsummarizer -f document.pdf

# Fast mode - no LLM, pure extraction (~3-5s)
docsummarizer -f document.pdf -m Bert

# Production mode - best quality with validated citations
docsummarizer -f document.pdf -m BertRag

# Focused on specific topic
docsummarizer -f manual.pdf -m BertRag --focus "installation steps"

# Verbose progress
docsummarizer -f document.pdf -v
```

## 总结模式

该工具从“ 仅图解” 进化为完整管道。 以下是每个模式的实际作用 :

### 自动( 默认)

根据你的要求选择正确的模式。使用这个模式,除非你有理由不这样做。

```bash
docsummarizer -f doc.pdf
```

### BertRag(生产)

这是你生产时想要的,三阶段输油管:

1. **解压缩** - 将文件分析成片段, 将其嵌入 BERT
2. **检索** - 寻找相关部分(语义搜索+显著评分)
3. **同步合成** - 法学硕士从这些部分编写流利的摘要。

```bash
docsummarizer -f doc.pdf -m BertRag
docsummarizer -f doc.pdf -m BertRag --focus "payment terms"
```

**为什么使用它:** 每个索赔都追溯到源段。 没有幻觉。 缩放到任何文件大小 。 LLM 只在结尾处运行( cheap ) 。

### 贝尔特(快速,无法学硕士)

利用当地ONNX模型进行纯采掘,完全没有LLM呼叫。

```bash
docsummarizer -f doc.pdf -m Bert
```

**为什么使用它:** 脱机工作。 返回时间为~ 3-5 秒。 确定性( 相同的输入 = 相同的输出) , 足够快速扫描 。

### 贝尔赫布里德

BERT提取,LLM抛光,Bert和BertRag之间的中间地带

```bash
docsummarizer -f doc.pdf -m BertHybrid
```

### 地图 减/ 减 减 / 减 减 / 迭代

原始模式。 仍然有效, 但 BertRag 取代了大多数使用过的模式 。

- **下图地图**: 平行加块, 有利于100%的覆盖
- **鼠角**矢量搜索, 用于有重点的查询( 遗产 - BertRag 做得更好) 。
- **迭替**: 序列处理,仅用于小文件

```bash
docsummarizer -f doc.pdf -m MapReduce  # Full coverage
docsummarizer -f doc.pdf -m Rag --focus "query"  # Legacy focused mode
```

### 查询模式

与其总结,不如就文件提出问题:

```bash
docsummarizer -f manual.pdf --query "How do I install the software?"
```

### 网络 URL 抓取中

直接总结网页而不下载:

```bash
# Summarize a web article
docsummarizer --url "https://example.com/article.html" --web-enabled

# Summarize a remote PDF
docsummarizer --url "https://example.com/document.pdf" --web-enabled

# With structured JSON extraction
docsummarizer --url "https://example.com/api-docs.html" --web-enabled --structured
```

**支持内容**HTML(保密)、PDF、Markdown、图像(OCR)、办公室文档。大型图像自动调整大小。

**安全安全安全安全安全安全安全安全**苏维埃社会主义联邦共和国保护、 DNS 约束性保护、 内容型加固、 消压炸弹保护、 HTML 净化。

**JavaScript 发送页面**:使用 `--web-mode Playwright` 用于 SPA 和 React apps(首次使用时自动安装铬)。

### 结构模式

抽取机器可读 JSON 而非文章 :

```bash
docsummarizer -f document.pdf --structured -o Json
```

摘录:实体、职能、关键流量、事实(具有信心水平)、不确定性、可配额的段落。

### 摘要模板

```bash
# Use a template
docsummarizer -f doc.pdf --template executive
docsummarizer -f doc.pdf -t bullets

# Specify custom word count with template:wordcount syntax
docsummarizer -f doc.pdf -t bookreport:500
docsummarizer -f doc.pdf -t executive:100

# Or use --words to override any template's default
docsummarizer -f doc.pdf -t detailed --words 300
```


|----------|-------|----------|
| `default` 300
| `prose` ~~400 ~ 清除多段简讯 - 没有元数据 ~ ~
| `brief` ~ ~ 50 ~ Quick 2-3 句子摘要 ~
| `oneliner` =~25 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
| `bullets` * 自动 * 弹点列表 (5-7 项) * * * 自动 * * 弹点列表 (5-7 项) *
| `executive` ~150 ~ ~ ~ ~ ~ 执行简报,附带建议 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 执行简报,附有建议 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 落实简报,带有建议 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 落实简报,带有建议 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
| `detailed` ~~ 1 000 ~ 全面讨论全部议题 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 全面讨论全部议题 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 全面讨论全部议题 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
| `technical` -=YTET -伊甸园字幕组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=- 翻译组=-
| `academic` -=YTET -伊甸园字幕组=- 翻译:
| `citations` Outo {Outo {Z} 关键引号,仅引文来源{
| `bookreport` ~500 ~ ~ 书报告(设置、字符、绘图、主题) ~ ~ ~ ~ ~ ~ ~ ~ 书报告(设置、 字符、 情节、 主题) ~ ~ ~ ~ ~ ~ ~ ~
| `meeting` 会议说明(决定、行动、问题)
| `strict` ~60 ~ ~ ~ ~ ~ ~ ~ 节能, 3发子弹, 最大 3 子弹, 没有套套 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

要查看所有可用的模板, 包括说明 :

```bash
docsummarizer templates
```

### 示范基准制定

比较同一文档中使用 `benchmark` 子命令 :

```bash
docsummarizer benchmark -f doc.pdf -m "qwen2.5:1.5b,llama3.2:3b,ministral-3:3b"
```

基准命令切换文档一次, 然后在相同的块上运行每个模型, 以便公平比较。 输出显示每个模型的时间、 字数和单词/ 秒 。

### 批次处理

处理整个目录 :

```bash
# Use BertRag for quality
docsummarizer -d ./documents -m BertRag -v

# Fast offline batch (no LLM needed)
docsummarizer -d ./documents -m Bert -o Json --output-dir ./summaries

# Process only PDFs recursively
docsummarizer -d ./documents -e .pdf --recursive -v
```

### 命令行选项


|--------|-------|-------------|---------|
| `--file` | `-f` 文档路径( DOCX、PDF、MD)  -
| `--directory` | `-d` 批量处理目录路径 *
| `--url` | `-u` 获取和总结的网络 URL
| `--web-enabled` 启用 Web 获取( 需要 -- url) {} { `false` |
| `--mode` | `-m` * 总结模式:自动、伯特拉格、伯特、伯特赫布里德、地图、拉格、迭代 * `Auto` |
| `--structured` | `-s` 使用结构化的 JSON 提取模式 `false` |
| `--focus` 
| `--query` | `-q` * 查询模式,而不是总结 * 无 *
| `--model` 使用奥拉马模式的奥拉马模式 `llama3.2:3b` |
| `--verbose` | `-v` 使用 Live UI 显示详细进度 `false` |
| `--config` | `-c` 配置文件  自动发现  的路径
| `--output-format` | `-o` 输出格式: 控制台、 文本、 标记、 Json `Console` |
| `--output-dir` 文件输出输出输出目录  当前 dir
| `--extensions` | `-e` 批量模式 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
| `--recursive` | `-r` 进程目录递归 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ `false` |
| `--template` | `-t` * 摘要模板(默认、简要、子弹、执行等) `default` |
| `--words` | `-w` 目标字数( 覆盖模板) 

| `--embedding-backend` 嵌入后端: Onnx, Ollama `Onnx` |
| `--embedding-model` * ONNX 型号名称 (RAG 模式) * `AllMiniLmL6V2` |
| `--web-mode` `Simple` |
| `--analyze` | `-a` * 运行关于摘要的质量分析 * * * `false` |

## 总结模式

### 减少(建议)

全面摘要最好,包括全部文件。

```bash
docsummarizer -f document.pdf -m MapReduce -v
```

**如何运作**:

1. 将文档分割成结构块(按标题分列)
2. 使用 LLM 以平行方式汇总每个块块
3. 用引文将摘要减少为内容提要
4. 校验所有引用引用引用参考真实块

**长期文件的等级裁减**:

对于组合块摘要超过模型上下文窗口的非常长的文档,MapRduce自动使用降级:

1. **条纹**:按适合背景的批次分组摘要
2. **中间削减**:将每批减少为压缩摘要
3. **最终削减**:将中间摘要合并到最终产出中
4. **递递递递**:如果中间体仍然太大,则增加更多的水平

```
100 chunks → 100 summaries → 5 batches → 5 intermediate summaries → final
```

这保留了文件的完整覆盖度,无论长度 - 每个块都为最终摘要贡献力量。 工具估算符号( ~ 4 字符/ 吨) , 目标为每个降压通行证60% 的上下文窗口利用率 。

**Pros 专业**:快速、完整覆盖、平行处理、处理任何文件长度
**共**: 可能错失跨部门连接, 较长文件速度慢

### RAG( 聚焦查询的最大目标)

最好在需要关注特定专题或有针对性问题时。

```bash
docsummarizer -f document.pdf -m Rag --focus "pricing and payment terms" -v
```

**如何运作**:

1. 在 Qdrant 中作为矢量嵌入的矢量, 以索引为文件块索引
2. 从文件标题中提取关键主题
3. 使用语义搜索获取每个专题的相关块块
4. 用引文合成重点突出的概要

**何时在 MapRedduce 上使用 RAG 时**:

假想 最佳模式
|----------|-----------|

"这上面写着什么安全?"
500页的手册,需要一切 地图(等级)
500页手册,需要具体章节
需要快速的结果, 没有Qdrant  MapReduce

RAG 是 **否** 处理长文档时处理长文档 - MapReduce 处理, 并降低级别。 RAG 是大约 **相关相关过滤过滤**:当您想要忽略文件的90% 并关注与您特定问题相关的内容时。

**Pros 专业**以专题为重点、对语义的理解、再利用指数、对重点查询更快
**共**: 可能错过重点领域以外的内容, 需要 Qdrant, 慢速的初始索引

### 迭替

对于叙述性文件而言,情况依次流动的最佳方式是叙述性文件。

```bash
docsummarizer -f story.pdf -m Iterative -v
```

**警告警告警告警告**:在长文档(>10块)上变慢并可能丢失上下文。

## 大文件指南

### 选择正确模式

* 文件类型 * * 目标 * 模式 * * 为什么 * * * * * * * 文件类型 * 目标 * 模式 * * * 为何 * * * * 文件类型 * 目标 * * 目标 * 模式 * * * * * * 为何 * * * * 文件类型 * 目标 * 目标 * 目标 * 模式 * * * * * * * * 目标 * * * * * 目标 * * * * * * * 目标 * * * 模式 * * * * * * * * * * 文件类型 * * * * * * 目标 * * * * * * * * 目标 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *文件类型,目标 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|---------------|------|------|-----|
* 技术规格(50页以上) * * 全部摘要 * * 地图* * 全部覆盖 * *

法律合同 完整摘要 地图 无法错过条款
* 法律合同 * * 付款条件 * * RAG * 关注具体章节 *
API docs (200页) * “如何进行鉴定? * * * RAG * 查询特定专题 * * *
研究论文 完整摘要 地图 结构 需要一切

### 视频对非视频

* 内容类型 * 最佳模式 * 说明 *
|--------------|-----------|-------|
| **编织/叙述** 
| **技术文件** * 概览的地图图集和具体细节的RAG *
| **法律/合同** 每一个条款都重要
| **手册手册手册手册** 通常询问具体细节

### 业绩 业绩业绩 业绩业绩

文件大小 * 地图 * * RAG * 注 *
|---------------|-----------|-----|-------|
10页 15页 20页 两个都快
* 50页 * 45页 * 30页 * 如果集中的话更快 *
* 200页 * * 3-5 分钟 * 1-2 分钟 * 降级 *
* 500+页 * 10-15 分钟 * 2-3 分钟 * 考虑多个RAG查询 *

## 配置配置配置

### 生成默认配置

```bash
docsummarizer config --output myconfig.json
```

### 配置文件

自动发现配置来自 :

1. `--config` 选项选项选项
2. `docsummarizer.json` 在当前目录中
3. `.docsummarizer.json` (隐藏文件)
4. `~/.docsummarizer.json` (用户主机)

示例示例示例示例 `docsummarizer.json`:

```json
{
  "embeddingBackend": "Onnx",
  "onnx": {
    "embeddingModel": "AllMiniLmL6V2"
  },
  "ollama": {
    "model": "llama3.2:3b",
    "embedModel": "mxbai-embed-large",
    "baseUrl": "http://localhost:11434",
    "temperature": 0.3,
    "timeoutSeconds": 1200
  },
  "docling": {
    "baseUrl": "http://localhost:5001",
    "timeoutSeconds": 1200,
    "pdfBackend": "pypdfium2",
    "pagesPerChunk": 10,
    "maxConcurrentChunks": 4,
    "enableSplitProcessing": true
  },
  "qdrant": {
    "host": "localhost",
    "port": 6333,
    "collectionName": "documents"
  },
  "processing": {
    "maxHeadingLevel": 2,
    "targetChunkTokens": 1500,
    "minChunkTokens": 200,
    "maxLlmParallelism": 2
  },
  "output": {
    "format": "Console",
    "verbose": false,
    "includeTrace": false
  },
  "webFetch": {
    "enabled": false,
    "mode": "Simple",
    "timeoutSeconds": 30,
    "userAgent": "Mozilla/5.0 DocSummarizer/1.0"
  },
  "batch": {
    "fileExtensions": [".pdf", ".docx", ".md", ".txt", ".html"],
    "recursive": false,
    "continueOnError": true
  }
}
```

### 处理备选方案


|--------|---------|-------------|
| `maxLlmParallelism` 8  同时的LLM 请求 (Ollama 队列, 如此高的值仅是队列)
| `maxHeadingLevel` 21111H1/H2。 33312222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
| `targetChunkTokens` 0 (自动)  目标块大小 。 0 = 自动计算 (~ 25% 的上下文窗口)  目标块大小 。 0 = 自动计算 (~ 25% 的上下文窗口)
| `minChunkTokens` 0 (自动) * 合并前的最低值。 0 = 1/8 目标 *

## 输出格式

### 简表结构

```C:\Blog\mostlylucidweb\Mostlylucid\Markdown\docsummarizer-tool.md
## Executive Summary
- Key finding 1 with specific details [chunk-0]
- Important point 2 with numbers and dates [chunk-3]
- Critical requirement 3 [chunk-5]

## Section Highlights
- Introduction: Overview of the system architecture [chunk-0]
- Requirements: Technical specifications detailed [chunk-3]
...

## Open Questions
- What is the timeline for Phase 2?
- How does the fallback mechanism work?

### Trace

- Document: document.pdf
- Chunks: 12 total, 12 processed
- Topics: 5
- Time: 21.4s
- Coverage: 100%
- Citation rate: 1.20
```

**追踪指标**覆盖率(包括百分比部分)、引用率(引文/插件)、处理的块数(RAG可能跳过部分)。

## 示范建议建议

е  使用
|-------|------|-------|---------|----------|
| `qwen2.5:1.5b` -=YTET -伊甸园字幕组=- 翻译:
| `gemma3:1b` 815MB 快速 (~ 10s) * 公平 * 替代性小型模型 * * * * 快速 (~ 10s) * 公平 *
| `llama3.2:3b` 中度 (~15s) 非常好 **默认默认** - 良好平衡 * 
| `ministral-3:3b` 2.9GB  中等 (~20s)  非常好  注重质量
| `llama3.1:8b` *4.7GB * 慢(~45s) * 出色* * 高质量摘要 * * *

> **提示提示**:用于快速摘要(~3s 和~15s),使用 `--model qwen2.5:1.5b`对于质量更重要的关键文件,使用 `--model llama3.1:8b`.

## 从源代码构建

```bash
# Clone the repository
git clone https://github.com/scottgal/mostlylucidweb.git
cd mostlylucidweb/Mostlylucid.DocSummarizer

# Build
dotnet build

# Run
dotnet run -- --help
```

### 自我实现的建设

用于在不需要.NET运行时间安装的情况下进行生产部署:

```bash
# Build self-contained executable (Windows x64)
dotnet publish -c Release -r win-x64 --self-contained

# Build for Linux
dotnet publish -c Release -r linux-x64 --self-contained

# Build for macOS
dotnet publish -c Release -r osx-x64 --self-contained
```

产出: `bin/Release/net9.0/<runtime>/publish/docsummarizer`

## 排除故障

### "无法连接到奥拉玛"

- 确保 Ollama 运行 : `ollama serve`
- 抽取检查模型: `ollama list`

### “没有可用的语言服务”

- 这是 **仅需要 PDF/ DOCX 文件**
- 对于 Markdown 文件, 您可以忽略此错误
- 要修正 : `docker run -p 5001:5001 quay.io/docling-project/docling-serve`

### “ Qdrant 连接失败 ”

- 这是 **仅对 RAG 模式所需** (`--mode Rag`)
- 对于 MapRduce 模式( 默认) , 您可以忽略此错误
- 要修正 : `docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant`

### "断路机开着"

- Ollama超载或坠毁
- 等待断路器重置或重新启动 Ollama 30 秒
- 该工具使用Polly抗御政策,并将自动再处理

### “ wsarecv” 或连接错误 (窗口)

- 这是 Windows 上已知的 Ollama 问题( GitHub #13340)
- 该工具自动处理此工具, 并重试逻辑和连接恢复
- 如果持续的话, 重新启动 Ollama 并再试一次

### "LLM 一代超时"

- 增加配置的超时超时
- 拆分非常大的文件
- 检查 Ollama 没有超载其它请求

### 重复或低质量摘要

**症状**而不是总结内容。 校对:Soup

**原因原因原因原因原因**:与快速或内容斗争的模型过长。

**修整**: 默认 `qwen2.5:1.5b` 大多数文件处理良好。对于有问题的文件,请尝试 `--model llama3.2:3b`见 [示范建议建议](#model-recommendations).

### 摘要忽略文档内容

如果摘要似乎是笼统的或没有提及具体内容:

- 模型可能是幻觉-检查 `Citation rate` 跟踪输出
- 尝试 RAG 模式 ()`--mode Rag`以回收的块块作为基础摘要
- 使用使用 `--verbose` 查看哪些块正在处理中

### 失踪或无效

如果缺少摘要 `[chunk-N]` 引用:

- 小型模式将内容优先排在内容而不是引证格式格式化之上
- 火速优化,以加快速度,而不是严格遵守引证规定
- 对于严格引用,使用较大的模型,例如 `llama3.2:3b`
- 支票支票支票支票 `Citation rate` 在追踪中 - 数值较高表明可追踪性更好

## 绩效提示

- **下图地图** 速度( 平行块)
- **`qwen2.5:1.5b`** 速度, **`llama3.2:3b`** 余额, **`llama3.1:8b`** 质量
- **ONNX 嵌入** 在 RAG 模式下比 Olama 速度快( 默认)
- 下 **`maxLlmParallelism`** 如果发生超时

## 资源资源资源 资源资源资源 资源资源 资源资源

- [源代码](https://github.com/scottgal/mostlylucidweb/tree/main/Mostlylucid.DocSummarizer)
- [GitHub 释放](https://github.com/scottgal/mostlylucidweb/releases?q=docsummarizer)
- [停 停 停 停 停 停 停 停 停 停 停 停](https://github.com/docling-project/docling) / [文档服务](https://github.com/docling-project/docling-serve)
- [解冻](https://qdrant.tech/) - 本地矢量数据库
- [奥拉马](https://ollama.ai/) / [奥利亚马沙尔普](https://github.com/awaescher/OllamaSharp)
- [波利](https://github.com/App-vNext/Polly) - 网络复原力和瞬时过失处理
- [频谱。 Console](https://spectreconsole.net/) - 美美的终端UI

## 系列导航

- **[第1部分:用RAG制成文件摘要](/blog/building-a-document-summarizer-with-rag)** - 结构和模式
- **[第2部分:使用工具](/blog/docsummarizer-tool)** (本条) - 《快速启动指南》
- **[第3部分:先进概念](/blog/docsummarizer-advanced-concepts)** - 深入潜入BERT、ONNX、嵌入和混合搜索

### 相关

- [CSV 与本地LLMs分析](/blog/analysing-large-csv-files-with-local-llms)
- [LLMM 网络内容](/blog/fetching-and-analysing-web-content-with-llms)