ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

xberg CLI 完整参考:文档智能提取、批量处理、OCR 与模型缓存的命令行全指南

xberg CLI 完整参考:文档智能提取、批量处理、OCR 与模型缓存的命令行全指南 后端AI 应用NLP【免费下载链接】xbergPolyglot document intelligence with a Rust core: extract text, metadata, images, tables, and structured data from 106 formats across 140 file extensions, plus code intelligence for 371 languages. Fifteen bindings, with CLI, REST API, and MCP server.项目地址https://gitcode.com/gh_mirrors/kr/xberg点击查看免费下载本篇技术指南以 xberg 官方 CLI Reference 为骨架结合 CLI 使用指南 与crates/xberg-cli源码系统讲解 xberg 命令行工具的全部命令、参数与实战用法。读者将掌握如何用xberg extract/xberg batch从 106 种格式、140 种扩展名的文档中提取文本与结构化数据如何配置 OCR、布局检测、分块、质量后处理如何管理缓存与预下载模型以及如何启动 REST API 与 MCP 服务。命令总览xberg CLI 是一个基于 Rust 与 clap 构建的单二进制工具入口定义于 crates/xberg-cli/src/main.rs。顶层命令结构如下命令用途xberg extract从单个文档提取文本与数据xberg batch批量提取多个文档xberg detect检测文件 MIME 类型xberg formats列出所有支持的文档格式xberg chunk对文本进行分块供 RAG/LLM 使用xberg embed生成文本向量嵌入xberg cache缓存管理clear / stats / manifest / warmxberg tree-sitter管理 tree-sitter 语法解析器xberg doctor诊断本机后端可执行性xberg serve启动 HTTP REST API 服务xberg mcp启动 Model Context Protocol 服务xberg api schema输出 OpenAPI 3.1 规范JSONxberg completions生成 shell 补全脚本xberg version输出版本信息部分命令依赖编译特性tree-sitter需要tree-sitterfeatureapi需要apifeatureembed需要embeddingsfeatureDocker 镜像内置Homebrew 安装不包含可从 crates/xberg-cli/Cargo.toml 中的 feature 定义确认。全局选项与日志xberg根命令提供一个全局选项--log-level类型为OptionString可设置为trace、debug、info、warn、error并会覆盖RUST_LOG环境变量。日志输出走tracing通道不混入标准输出源码中通过#![deny(clippy::print_stdout)]强制结果输出与诊断分离见 main.rs。# 调试排障debug 级日志 xberg --log-level debug extract document.pdf # 压制到仅错误信息 xberg --log-level error batch documents/*.pdf # 最大细节 xberg --log-level trace extract document.pdf有效级别trace、debug、info默认、warn、error。输出默认带颜色可通过NO_COLOR环境变量关闭NO_COLOR1 xberg extract document.pdf文档提取xberg extractxberg extract从单个文档提取内容位置参数uri接受本地路径与file://URI在启用了url-surface特性的构建中还支持--url指定 HTTP(S) 地址、--stdin从标准输入读取字节流三者互斥见 main.rs。# 提取文本到 stdout xberg extract document.pdf # 显式指定 MIME 类型默认自动检测 xberg extract document.pdf --mime-type application/pdf # 从 stdin 读取字节 cat scanned.pdf | xberg extract --stdin输出格式控制xberg 将“结果载体格式”与“正文渲染格式”分开设计--formatWireFormat控制整个响应的载体text、json以及 token 高效的toon。extract默认为textbatch默认为json见 main.rs。--content-format旧别名--output-format已弃用控制正文result.content的渲染plain默认、markdown、djot、html。# JSON 载体 Markdown 正文 xberg extract document.pdf --content-format markdown --format json # TOON 载体token 更省的 JSON 替代 xberg extract document.pdf --format toonJSON 输出的最小结构如下metadata中含mime_type等字段{ content: Extracted text content..., metadata: { mime_type: application/pdf } }OCR 相关选项extract与batch共享整套 OCR 覆盖参数源码中校验逻辑位于 crates/xberg-cli/src/commands/overrides/ocr.rs。参数说明--ocr true\|false启用/禁用 OCR为 true 时默认配置 tesseract 后端为 false 时硬性禁用并移除其配置--ocr-backend BACKENDtesseract、paddle-ocr、sceptre、vlm、candle-trocr、candle-paddleocr-vl、candle-paddleocr-vl-15、candle-glm-ocr、candle-deepseek-ocr--ocr-language LANGOCR 语言码Tesseract 用 ISO 639-3如eng、fra、deuPaddleOCR 用短码如en、ch、french、korean--force-ocr true\|false即使文本层提取成功也强制 OCR--ocr-scanned-pages仅对疑似扫描页执行 OCR其余页保留原生文本--scanned-min-confidence扫描判定置信度阈值默认 0.7取值 0.0–1.0--disable-ocr true\|false完全禁用 OCR包括图片--ocr-auto-rotate true\|false基于检测到的方向在 OCR 前自动旋转图片--ocr-no-cache本次运行绕过磁盘 OCR 结果缓存不读不写--ocr-backend-options JSON按后端的 JSON 选项对象如{layout_mode:whole_page}--vlm-model MODELVLM OCR 模型隐含--ocr-backend vlm使用 liter-llm 路由格式如openai/gpt-4o、anthropic/claude-sonnet-4-20250514--vlm-api-key KEYVLM OCR 的 API Key--vlm-prompt TPL自定义 VLM OCR 提示模板Jinja2--api-key KEY所有 LLM 功能共享的默认 API KeyVLM OCR、结构化提取、翻译、分类、描述生成、摘要、NER优先级低于--vlm-api-key与配置文件中的api_key高于XBERG_LLM_API_KEY环境变量OCR 后端语言码差异在源码中有明确处理默认语言为eng而 PaddleOCR 系列后端默认语言为en见 ocr.rs。# Tesseract 法语 OCR默认后端 xberg extract --ocr true --ocr-language fra document.pdf # PaddleOCR 中文 OCR xberg extract --ocr true --ocr-backend paddle-ocr --ocr-language ch document.pdf # 强制 OCR 自动旋转 xberg extract document.pdf --force-ocr true --ocr-auto-rotate trueCandle 系后端candle-trocr、candle-paddleocr-vl、candle-paddleocr-vl-15、candle-glm-ocr、candle-deepseek-ocr是纯 Rust 的 VLM/视觉 Transformer OCR 引擎无需 ONNX Runtime可在 macOSMetal与 LinuxCUDA上 GPU 加速模型权重首次使用时自动从 Hugging Face 下载。其余后端tesseract 等的校验规则见 ocr.rs例如--ocr false与--force-ocr true互斥、--vlm-api-key必须配合--vlm-model使用非法组合会直接报错退出。布局检测与模型推理选项参数说明--layout true\|false启用布局检测默认模型 RT-DETR v2--layout false显式禁用--layout-confidence FLOAT布局检测置信度阈值0.0–1.0--layout-strategy always\|auto布局模型运行的页面范围always默认每页或auto预筛页面跳过无帮助的页--layout-table-model MODEL表格结构模型tatr默认、slanet_wired、slanet_wireless、slanet_plus、slanet_auto、disabled--layout-formula-model MODEL公式识别模型latex_ocr--use-layout-for-markdown将布局区域喂入非 OCR 的 Markdown 管线以改进标题/表格/列表/图形结构需配合--layout--acceleration PROVIDERONNX Runtime 执行提供方auto、cpu、coreml、cuda、tensorrt# 启用布局检测并设置置信度 xberg extract document.pdf --layout --layout-confidence 0.7 # macOS 使用 CoreML GPU 加速 xberg extract document.pdf --acceleration coreml # Linux NVIDIA GPU xberg extract document.pdf --acceleration cuda分块、质量与语言检测参数说明--chunk true\|false启用/禁用文本分块--chunk-size N最大块大小字符默认 1000--chunk-overlap N相邻块重叠字符默认 200--chunking-tokenizer MODEL基于 token 的块大小计算模型如Xenova/gpt-4o隐含启用分块需chunking-tokenizersfeature--quality true\|false启用质量后处理--detect-language true\|false对提取文本启用语言检测xberg extract document.pdf --chunk true --chunk-size 512 --chunk-overlap 50 xberg extract document.pdf --chunking-tokenizer Xenova/gpt-4o xberg batch documents/*.pdf --quality true页面、图片与 PDF 专项选项参数说明--extract-pages true\|false将页面作为独立数组提取--page-markers true\|false在主内容字符串中插入页面标记注释--extract-images true\|false从文档提取图片--target-dpi N图片归一化目标 DPI如 150、300、600参考范围 36–2400--output-dir DIR提取图片的写出目录仅 text/toon 输出JSON 载体内嵌图片字节--pdf-password PASSWORD加密 PDF 密码可多次指定--pdf-extract-images true\|false提取 PDF 页面内嵌图片--pdf-extract-tables true\|false提取 PDF 表格原生引擎网格 启发式文本层回退默认 true--pdf-ocr-inline-images true\|false对提取的内联图片做 OCR 并注入结果--pdf-extract-metadata true\|false提取 PDF 元数据标题、作者等--pdf-backend native\|pdfiumPDF 提取后端默认native--token-reduction LEVELToken 缩减级别off、light、moderate、aggressive、maximum--msg-codepage NMSG 文件无码页元数据时的 Windows 码页回退1250中欧、1251西里尔、1252西欧xberg extract encrypted.pdf --pdf-password secret xberg extract document.pdf --pdf-extract-images true --pdf-extract-metadata true xberg extract document.pdf --extract-images true --target-dpi 300 xberg extract message.msg --msg-codepage 1251 xberg extract document.pdf --token-reduction aggressiveHTML 与 CSV 输出选项参数说明--html-theme THEME样式化 HTML 内置主题default、github、dark、light、unstyled隐含--content-format html--html-css CSS追加到主题样式表之后的内联 CSS--html-css-file PATH加载一次并追加的 CSS 文件路径--html-class-prefix PREFIX所有类名前缀默认kb---html-no-embed-css抑制样式化 HTML 中内嵌的style块--csv-delimiter DELIMCSV/TSV 字段分隔符单 ASCII 字符如;、\|、\t不设置时自动检测--csv-comment-prefix PREFIX整行跳过注释前缀如#可多次指定缓存与并发控制参数说明--no-cache true\|false禁用提取结果缓存--cache-namespace NS缓存命名空间租户隔离--cache-ttl-secs SECONDS每次请求缓存 TTL秒0 表示跳过缓存--max-concurrent N批量模式最大并发提取数--max-threads N统一封顶内部线程池Rayon、ONNX intra-op、批量信号量--max-concurrent-ocr N单独设置并发 Tesseract 识别会话按给定值生效、不受线程预算封顶进程内首次提取即固定该值xberg batch documents/*.pdf --max-concurrent 4 --max-threads 8逐文件配置覆盖batch还支持--file-configs JSON文件用一个 JSON 对象按文件路径映射逐文件提取配置覆盖例如xberg batch a.pdf b.pdf \ --file-configs {a.pdf: {force_ocr: true}, b.pdf: {output_format: markdown}}批量提取xberg batchxberg batch位置参数paths接受多个文档路径支持 glob并可配合--input指定 JSON/JSONL 清单用--input-format声明清单格式见 main.rs。# 多文件提取 xberg batch doc1.pdf doc2.docx doc3.txt # 目录下全部 PDF xberg batch documents/*.pdf # 递归提取 xberg batch documents/**/*.pdf # 多种类型 xberg batch documents/**/*.{pdf,docx,txt} # 从 JSON/JSONL 清单提取 xberg batch --input manifest.jsonl --input-format jsonlbatch与extract共享全部覆盖参数OCR、布局、分块、缓存、并发等均高于配置文件生效。默认输出 JSONxberg batch scanned/*.pdf --ocr true --format json xberg batch documents/*.pdf --content-format markdown --format json配置加载机制xberg 的配置优先级从高到低在 main.rs 中明确单个 CLI 参数--ocr、--content-format等内联 JSON 配置--config-json/--config-json-base64配置文件--config path.toml内置默认值配置发现规则未指定--config时自动在当前目录及父目录向上查找xberg.toml/xberg.yaml/xberg.json--no-config-discovery可跳过项目与用户级配置发现直接使用内置默认值该参数与--config互斥。# 自动发现 xberg.toml xberg extract document.pdf # 显式指定三种格式之一 xberg extract document.pdf --config my-config.toml xberg extract document.pdf --config xberg.yaml xberg extract document.pdf --config my-config.json # 内联 JSON在配置文件之后、单个参数之前合并 xberg extract document.pdf --config-json {ocr:{backend:tesseract},chunking:{max_chars:1000}} # Base64 编码 JSON规避 shell 引号问题 xberg extract document.pdf --config-json-base64 eyJvY3IiOnsiYmFja2VuZCI6InRlc3NlcmFjdCJ9fQ三种格式等价的最小配置示例# xberg.toml use_cache true enable_quality_processing true [ocr] backend tesseract language eng [chunking] max_characters 1000 overlap 100# xberg.yaml use_cache: true enable_quality_processing: true ocr: backend: tesseract language: eng chunking: max_characters: 1000 overlap: 100{ use_cache: true, enable_quality_processing: true, ocr: { backend: tesseract, language: eng }, chunking: { max_characters: 1000, overlap: 100 } }环境诊断xberg doctordoctor在跑第一个文档前探测配置中的后端在本机是否真的可执行每项检查输出 pass / warn / fail / skip 及一行原因警告不会导致命令失败只有 fail 才使退出码非零。探测范围包括Tesseract 按语言检查 tessdata、PaddleOCR 校验模型校验和、VLM 检查 API Key 与端点可达性不产生计费调用、布局检测执行一次真实 RT-DETR 推理。尚未下载的模型报告skip而非失败。当设置了XBERG_CACHE_DIR时缓存检查与--clean会被跳过该环境变量是裸路径xberg 无法确认目录归属。# 探测 xberg.toml 或自动发现配置中的后端 xberg doctor # JSON 输出便于提交 bug 报告 xberg doctor --format json # 探测后清理 xberg 自有缓存目录中的杂散文件 xberg doctor --clean缓存管理xberg cache缓存子系统包含四个子命令默认缓存目录为当前目录下.xberg平台默认位置与覆盖方式见 CLI 使用指南。清理与统计# 清理 xberg 管理的缓存不清共享的 Hugging Face 文件 xberg cache clear xberg cache clear --cache-dir /path/to/cache --format json # 查看缓存统计 xberg cache stats xberg cache stats --cache-dir /path/to/cache --format json模型清单与预下载xberg cache manifest输出预期模型文件的清单含 SHA256 校验和与体积用于缓存完整性校验或脚本化预置xberg cache manifest # 默认 JSON xberg cache manifest --format textxberg cache warm提前下载模型产物适合容器化部署离线运行# 下载全部 OCR 与布局模型 xberg cache warm # 指定缓存目录 xberg cache warm --cache-dir /path/to/cache # 下载全部 4 个嵌入模型预设fast、balanced、quality、multilingual xberg cache warm --all-embeddings xberg cache warm --embedding-model balanced # 下载全部表格结构模型含 SLANeXT 变体约 730MB xberg cache warm --all-table-models # 下载 tree-sitter 语法解析器 xberg cache warm --all-grammars xberg cache warm --grammar-groups web,systems,scripting xberg cache warm --grammars python,rust # 下载 GLiNER NER 模型 xberg cache warm --ner xberg cache warm --ner-model fast xberg cache warm --all-ner-models注意NER 预热下载的是xberg-io/gliner-models导出的 GLiNER 产物若该 Hugging Face 仓库不可公开读取需先配置hf-hub支持的凭据。tree-sitter 语法管理xberg tree-sitter代码智能所需的语法解析器缓存管理需tree-sitterfeature。语言分组为web、systems、scripting、data、jvm、functional。# 下载指定语言 xberg tree-sitter download python rust go # 下载全部 xberg tree-sitter download --all xberg tree-sitter download --groups web,systems # 按自动发现的配置 [tree_sitter] 段解析 cache_dir/languages/groups xberg tree-sitter download --from-config # 查看 / 清理 xberg tree-sitter list --downloaded xberg tree-sitter list --filter rust xberg tree-sitter cache-dir xberg tree-sitter clean--cache-dir命令行参数优先级高于配置文件中的tree_sitter.cache_dir。嵌入生成xberg embedxberg embed用预训练模型生成文本向量输入通过--text可多次或 stdin需要embeddingsfeatureDocker 镜像内置Homebrew 安装不包含。参数说明--preset PRESET嵌入预设fast、balanced默认、quality、multilingual与--provider local配合--provider PROVIDERlocal默认ONNX、llmliter-llm、plugin进程内注册的后端--model MODELLLM 托管嵌入模型如openai/text-embedding-3-small--provider llm时必填--api-key KEYLLM 提供方的 API Key--plugin NAME预注册的进程内嵌入后端名--provider plugin时必填需先经xberg::plugins::register_embedding_backend注册xberg embed --text hello world --preset balanced xberg embed --text first document --text second document --preset quality echo hello world | xberg embed --preset balanced xberg embed --text hello --preset balanced --format text独立分块命令xberg chunkxberg chunk用可配置的 size/overlap 切分文本输入通过--text或 stdin参数说明--chunker-type TYPEtext默认、markdown、yaml、semantic--chunk-size N块大小字符--chunk-overlap N块重叠字符--chunking-tokenizer MODEL基于 token 的块大小模型如Xenova/gpt-4o需chunking-tokenizersfeature--topic-threshold F语义分块的主题阈值0.0–1.0默认 0.75xberg chunk --text long text content to be split into chunks... xberg chunk --text # Heading\n\nParagraph... --chunker-type markdown cat document.txt | xberg chunk --chunk-size 1000 xberg chunk --text long text... --config xberg.toml服务命令serve与mcpHTTP API 服务xberg serve启动 REST API配置优先级为CLI 参数--host/--port 环境变量XBERG_HOST/XBERG_PORT 配置文件[server]段 内置默认127.0.0.1:8000见 main.rs。xberg serve xberg serve -H 0.0.0.0 -p 8000 xberg serve --config xberg.toml --host 0.0.0.0 --port 8000服务端点包括POST /extract、POST /batch、GET /detect、GET /health、GET /info、GET /cache/stats、POST /cache/clear。MCP 服务xberg mcp启动 Model Context Protocol 服务为 AI Agent 提供extract文件路径 / base64 字节、extract_batch等工具# stdio 传输默认适配 Claude Desktop 等客户端 xberg mcp # HTTP 传输 xberg mcp --transport http --host 0.0.0.0 --port 8001HTTP 传输默认仅接受回环 Hostlocalhost、127.0.0.1、::1反向代理/网关转发时用--allowed-host追加可接受的 Host 值可重复其优先级为该参数 XBERG_MCP_ALLOWED_HOSTS环境变量 配置[mcp] allowed_hosts仅在显式--config时生效 默认回环白名单。其他工具命令MIME 检测与格式清单# 检测 MIME 类型 xberg detect document.pdf xberg detect document.pdf --format json # 列出全部支持格式扩展名 MIME xberg formats xberg formats --format jsonOpenAPI 规范导出# 输出 OpenAPI 3.1 规范JSON便于代码生成与 API 客户端工具链 xberg api schema xberg api schema openapi.jsonShell 补全xberg completions bash xberg completions zsh xberg completions fish # 立即启用 bash 补全 eval $(xberg completions bash)版本与帮助xberg --version xberg version --format json xberg --help xberg extract --help # 每个子命令都有独立帮助错误处理与常见问题CLI 出错时返回非零退出码成功为 0错误详情在 stderrxberg extract document.pdf || echo Extraction failed # bash 循环中单文件失败不中断 for file in documents/*.pdf; do xberg batch $file || continue done常见问题排查Tesseract not found使用 OCR 需先安装 Tesseract。macOSbrew install tesseractUbuntusudo apt-get install tesseract-ocr。File not found确认路径存在且可读必要时使用绝对路径xberg extract /absolute/path/to/document.pdf。性能与内存调优# 关闭质量后处理换取速度 xberg extract large.pdf --quality false # 批量处理多个文件 xberg batch large_files/*.pdf --format json # 关闭缓存降低内存占用 xberg extract large_file.pdf --no-cache true # 输出压缩节省磁盘 xberg extract document.pdf | gzip output.txt.gzDocker 部署CLI 镜像为ghcr.io/xberg-io/xberg-cli:latest完整镜像含 CLI 与全部功能为ghcr.io/xberg-io/xberg:latestdocker run -v $(pwd):/data ghcr.io/xberg-io/xberg-cli:latest \ extract /data/document.pdf --ocr truedocker-compose 示例services: xberg: image: ghcr.io/xberg-io/xberg-cli:latest volumes: - ./documents:/input command: extract /input/document.pdf --ocr true深入阅读CLI 使用指南完整的安装方式、配置示例与实战命令CLI 源码命令结构、配置优先级与参数定义OCR 参数校验实现后端枚举、默认语言与参数互斥规则安装指南 与 快速上手从零开始体验 xberg赞分享后端AI 应用NLP【免费下载链接】xbergPolyglot document intelligence with a Rust core: extract text, metadata, images, tables, and structured data from 106 formats across 140 file extensions, plus code intelligence for 371 languages. Fifteen bindings, with CLI, REST API, and MCP server.项目地址https://gitcode.com/gh_mirrors/kr/xberg点击查看免费下载相关推荐xberg-cli 完全指南用 Rust 命令行工具玩转 Xberg 文档智能提取xberg cli 完全指南用 Rust 命令行工具玩转 Xberg 文档智能提取 本篇技术指南面向需要以命令行方式驱动 Xberg 文档智能库的开发者与运维后端AI 应用NLPAgent Zero _discovery 插件欢迎屏上下文感知插件发现卡片的设计与实现Agent Zero _discovery 插件欢迎屏上下文感知插件发现卡片的设计与实现 本文以 Agent Zero 仓库中的 plugins/_disco后端AI 应用NLPResticker pre-commands与post-commands应用定制完整备份流程的终极指南Resticker pre commands与post commands应用定制完整备份流程的终极指南 Resticker是一款基于Docker容器的自动化r后端AI 应用NLP上一篇Autovisor闪退问题从崩溃边缘到稳定运行的完全指南下一篇SublimePicker重复选项选择器的深度使用教程从基础到高级自定义创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表