# citation-validator-lite **Repository Path**: perrylink/citation-validator-lite ## Basic Information - **Project Name**: citation-validator-lite - **Description**: A lightweight CLI tool to validate citations in RAG (Retrieval-Augmented Generation) model outputs. 一个轻量级的 CLI 工具,用于验证 RAG(检索增强生成)模型输出中的引用真实性。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-22 - **Last Updated**: 2026-08-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
# Citation-Validator-Lite **使用模糊匹配校验 RAG 模型输出中的引用是否与源文档一致、轻量级的命令行工具。** *已移植到 [dsh-library](https://github.com/PerryLink/dsh-library) —— PerryLink DSH 插件家族的一员。* [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE) [English](README.md) · [简体中文](README.zh.md)
--- ## 功能简介 Citation-Validator-Lite 从 AI 生成的答案中提取 `[1]`、`[2]` 等引用标记,并将每个标记与源文档字典逐一比对。它使用模糊字符串匹配对每个引用周围的句子与对应源文本打分,低于可配置阈值的引用会被标记为可疑。 ## 功能特性 - 使用正则表达式提取 `[1]`、`[2]` 等引用标记 - 模糊匹配(FuzzyWuzzy 部分比率),阈值可在 0–100 之间配置 - 终端中以红色删除线高亮无效引用 - 答案与源文档支持直接文本或文件输入 - 可选的 JSON 输出 - 可作为 Python 库导入使用 ## 快速开始 需要 Python 3.8+。 ```bash git clone https://github.com/PerryLink/Citation-Validator-Lite.git cd Citation-Validator-Lite pip install -e . ``` ## 使用方法 ```bash citation-validator-lite --answer-file answer.txt --sources-file sources.json ``` **answer.txt:** ```text According to [1], Python is a high-level programming language that emphasizes code readability. Python was created by Guido van Rossum and first released in [2], and it has become one of the most popular programming languages. However, [3] incorrectly states that Python was invented in 1995. ``` **sources.json:** ```json { "1": "Python is a high-level, interpreted programming language that emphasizes code readability and simplicity.", "2": "Guido van Rossum created Python and first released it in 1991.", "3": "Java was released in 1995 by Sun Microsystems." } ``` 其中引用 `[3]` 与其来源不匹配,因此会被标记为虚假引用。 | 参数 | 默认值 | 说明 | |------|--------|------| | `--answer` | — | 答案文本 | | `--answer-file` | — | 从文件读取答案 | | `--sources` | — | 源文档 JSON 对象 | | `--sources-file` | — | 从 JSON 文件读取源文档 | | `--threshold` | `80` | 匹配阈值(0–100) | | `--json` | 关 | 以 JSON 格式输出结果 | 作为库使用: ```python from citation_validator_lite import validate_citations result = validate_citations(answer, sources, threshold=80) ``` 基于 Click、FuzzyWuzzy + python-Levenshtein 与 Rich 构建;测试使用 pytest。 ## 开发 ```bash pip install -e ".[dev]" pytest tests/ -v ``` ## 相关项目 - [dsh-library](https://github.com/PerryLink/dsh-library) —— 本工具已移植进的 DSH 插件 - [PerryLink](https://github.com/PerryLink) —— PerryLink DSH 插件家族 ## 许可证 [Apache License 2.0](LICENSE) © 2026 PerryLink