Skip to main content
Glama

CUMCM Optimization RAG

这是一个面向全国大学生数学建模竞赛优化与决策类问题的非官方、可审计 RAG 工程。项目提供 Python 查询核心、受 manifest 约束的入库器、命令行工具和只读 MCP 服务;不包含竞赛题面、附件、优秀论文、扫描件、压缩包或其他未获明确公开再分发许可的材料。

本项目与案例建模仓库相互独立。案例仓库可以选择通过 MCP 调用本项目,但两者不共享源码、语料、索引或虚拟环境;案例复现也不以本项目为运行前提。

协作者

Related MCP server: rag-mcp

当前公开数据状态

迁移前基线 manifest 有 399 条:L0 119、L1 193、L2 87。许可审计没有发现任何具备肯定公开再分发许可的记录,因此:

  • data/manifest/corpus_manifest.csv:0 条公开原文记录,仅保留表头;

  • data/manifest/sources.csv:399 条来源与权利元数据;

  • data/manifest/exclusions.csv:399 条排除记录及理由;

  • data/corpus/:不包含原语料;

  • artifacts/index/:不包含生成索引。

这意味着仓库可以安装、校验、启动 CLI 和 MCP,但在添加并审核合法语料、构建本地索引之前不能执行真实检索。该状态是版权门禁的预期结果,不是数据丢失或程序故障。

其中 199 条迁移记录没有公开 URL,已明确标为 source_locator_status=local_record_no_public_url。这些记录只是本地来源台账,不能被描述为外部可独立复核的在线来源。rag_list_sources 会返回元数据总账并用 available_for_index 区分是否存在于公开 manifest;rag_get_document 仍严格只允许读取公开 manifest 登记的原文。

目录结构

.
├─ src/cumcm_rag/          # 核心、入库、CLI、MCP
├─ config/                 # 相对路径配置与 Codex 示例
├─ scripts/                # manifest 迁移、校验工具
├─ tests/                  # 单元与 MCP stdio 集成测试
├─ data/
│  ├─ manifest/            # 公开清单、来源元数据、排除登记
│  ├─ corpus/              # 仅放已核验可再分发文本
│  └─ incoming/            # 本地待审材料;默认忽略
├─ artifacts/index/        # 可重建索引;默认忽略
├─ docs/                   # 架构、治理、接入、验证与迁移说明
└─ docker/                 # 容器镜像和 Compose 配置

环境与安装

要求 Python 3.11 或更高版本。推荐在项目外或项目根下自建虚拟环境;虚拟环境不会进入版本控制。

python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

只运行状态、manifest 和 MCP 元数据接口不需要模型依赖。构建索引和检索时安装:

python -m pip install -e ".[runtime]"

OCR/PDF 抽取工具属于本地语料准备能力,不会赋予材料再分发权:

python -m pip install -e ".[corpus]"

最小可运行示例

源码模式:

$env:PYTHONPATH = "$PWD\src"
python -m cumcm_rag.cli status
python -m cumcm_rag.cli health
python scripts\verify_manifest.py

可编辑安装后:

cumcm-rag status
cumcm-rag sources --all --limit 5
cumcm-rag-mcp

普通安装或从仓库外运行时必须设置 CUMCM_RAG_ROOT 指向包含 config/rag.yamldata/manifest 的项目/数据根目录;程序不会再把 site-packages 的父目录误判为项目根。

当前 health 会明确报告“索引缺失”,因为索引是本地生成物且公开语料白名单为空。MCP 仍可正常完成初始化、列出工具、查询状态和执行浅层健康检查。

添加合法语料与构建索引

只有同时满足以下条件的文本文件才能进入 corpus_manifest.csv

  1. permission_status=public_redistribution_verified

  2. redistribution_allowed=yes

  3. 有有效 SPDX 许可证或覆盖再分发的书面授权;

  4. 来源、权利人、上游派生关系和人工复核状态完整;

  5. 文件存在且 SHA-256 与登记值一致;

  6. 文件位于 data/corpus/ 内,且是允许的文本格式。

完成登记后先运行:

python scripts\verify_manifest.py

再构建本地索引:

cumcm-rag build-index
cumcm-rag health --deep
cumcm-rag search "MILP 不可行时如何诊断" --limit 5

索引器只读取 manifest 中 index_default=yes 的文件;未登记文件会使校验失败,不会被静默收录。

MCP 与 Codex

MCP 服务暴露六个只读工具:

  • rag_search

  • rag_get_case_context

  • rag_get_document

  • rag_list_sources

  • rag_get_status

  • rag_health

服务入口:

python -m cumcm_rag.mcp_server

示例配置见 config/codex_config.example.toml,详细说明见 docs/codex-mcp.md。示例不包含个人机器绝对路径;推荐先在目标 Python 环境中安装本项目,再让 Codex 运行模块入口。

Docker

解析 Compose 配置:

docker compose -f docker\compose.yaml config

构建并启动:

docker compose -f docker\compose.yaml build
docker compose -f docker\compose.yaml run --rm cumcm-rag-mcp

容器只读挂载 data/corpusartifacts/index。模型缓存在命名卷中;语料和索引不会写入镜像。

测试与验证

python -m compileall -q src scripts tests
python -m pytest -q --basetemp .pytest-tmp
python scripts\verify_manifest.py
docker compose -f docker\compose.yaml config

完整的静态检查、MCP 验证、旧路径扫描、敏感信息扫描和环境限制见 docs/validation.md

常见故障

  • 索引不存在或不完整:当前仓库不分发索引。先合法添加语料、通过 manifest 校验,再执行 build-index

  • 缺少 txtaijieba:安装 .[runtime]。浅层状态和 manifest 校验不要求它们。

  • 模型无法下载:在可联网环境预先填充模型缓存,或设置 HF_HOME 指向合规的本地缓存;不要提交缓存。

  • MCP 能启动但检索失败:先调用 rag_get_statusrag_health。索引缺失是最常见原因。

  • Windows 临时目录拒绝访问:给 pytest 指定项目内临时目录,如 --basetemp .pytest-tmp,测试后删除该目录。

  • FAISS AVX2 警告:若随后成功回退到普通 FAISS,通常只是性能提示;仍应以真实检索结果判断功能是否正常。

许可、贡献与引用

原创代码和原创文档采用 Apache License 2.0。该许可证不覆盖语料元数据所指向的题面、论文、附件、网页、仓库或其他第三方材料。详见 DATA_LICENSE.mdNOTICETHIRD_PARTY_NOTICES.md

提交贡献前请阅读 CONTRIBUTING.md;安全问题按 SECURITY.md 私下报告;引用信息见 CITATION.cff

已知限制

  • 当前公开语料为 0,无法开箱执行语义检索;

  • 旧基线中有 3 条来源记录的实际 SHA-256 与登记值不符,已保留为排除元数据,不能作为已验证证据;

  • 未联网复核官方网页条款或取得第三方书面授权;

  • 真实检索依赖较大的模型与 FAISS/txtai 环境,跨平台表现可能不同;

  • 本项目只提供方法与检索支持,不能替代题面原文、用户数据、实际求解结果或人工版权判断。

Available Tools

6 tools
rag_get_case_contextC

按题号取得案例卡与通用方法卡组成的上下文。

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
queryNo建模决策、约束、求解与验证
case_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

C2.7/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but does not disclose any side effects, permissions, read-only nature, error behavior, or rate limits. For a retrieval tool, it omits whether it modifies any state or if it requires authentication. This is a significant gap given zero annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the primary purpose. It avoids redundancy and is appropriately terse. However, its brevity comes at the cost of missing essential context, so it is not a 5, but it is still well-structured and concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With three parameters, an output schema, and no annotations, the description is incomplete. It does not explain what '案例卡' and '通用方法卡' are, what the context is used for, or how the returned data is structured (though output schema exists, the description doesn't orient the agent). An agent cannot fully assess whether this is the correct tool without additional context about the domain or use case.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate by explaining the parameters. It indirectly references case_id via '按题号' but does not explain the meaning or format of case_id, limit, or query. The query parameter has a default that suggests a use case, but the description does not elaborate. The description adds little value beyond the bare schema names.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a clear verb '取得' (get/retrieve) and a specific resource: '案例卡与通用方法卡组成的上下文' (context composed of case card and general method card). It also specifies the key selector '按题号' (by question number), which maps to case_id. While it does not explicitly distinguish from siblings, the resource is unique and the tool name reinforces the purpose, so it is clearly differentiated from generic search or document retrieval.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings (rag_search, rag_get_document, etc.). It does not mention alternatives, prerequisites, or conditions under which this tool is preferred. The only hint is the specific resource it returns, but that is implicit and not explicitly stated as a selection criterion.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

rag_get_documentB

读取 manifest 已登记的文本型公开语料,拒绝未登记路径。

ParametersJSON Schema
NameRequiredDescriptionDefault
max_charsNo
source_fileYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

B3.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It does disclose the key constraint of rejecting unregistered paths, which is useful. However, it does not mention any other behaviors such as output format, error handling, or side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no wasted words. It front-loads the action and includes the critical constraint, making it concise and well-structured for the information it conveys.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the absence of parameter semantics and usage guidance, the description is incomplete. It does not clarify how to use the parameters or when to choose this tool over siblings, leaving the agent without essential context for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for missing parameter documentation. It does not explain what source_file represents or what max_chars does, leaving both parameters entirely undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool reads text-type public corpus registered in the manifest, with an explicit constraint that unregistered paths are rejected. This specific verb+resource combination distinguishes it from siblings like rag_search or rag_list_sources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It implies the user should have a specific source_file path, but does not mention alternatives or conditions for using rag_search or rag_get_case_context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

rag_get_statusA

返回语料、manifest 与本地生成索引的状态。

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It conveys that the tool returns status information, implying a read-only operation, but it does not explain whether local indexes are refreshed, whether state may be stale, or whether any side effects occur.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that names the three types of status returned. It contains no filler, repetition, or irrelevant details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a parameterless status-check tool with an output schema defined, the description is largely complete. It names the domains whose status is returned; the only minor gap is a lack of elaboration on what '本地生成索引' specifically covers, but this is not critical given the tool's simplicity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool takes zero parameters, so there is no parameter ambiguity to resolve. The baseline of 4 applies because no parameter descriptions are needed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific action (返回/returns) and a clear scope: status of corpus, manifest, and locally generated indexes. This clearly differentiates it from sibling tools like rag_search or rag_get_document, which perform different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to call this tool instead of alternatives such as rag_health or rag_list_sources. The agent must infer its role from the name and description alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

rag_healthB

检查路径与索引;deep=true 时额外执行真实检索探针。

ParametersJSON Schema
NameRequiredDescriptionDefault
deepNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

B3.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of disclosure. It usefully reveals that deep=true executes a real retrieval probe, which implies potential cost or side effects. However, it does not describe the output format, whether the probe mutates state, or any failure behavior — gaps that matter more given zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

One compact sentence (split by a semicolon) that front-loads the core purpose and appends the parameter behavior. Zero wasted words; appropriately sized for a simple one-parameter health-check tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has an output schema, so return values need no description, and complexity is low with a single optional parameter. The main gap is the unresolved overlap with sibling rag_get_status, which the description does nothing to clarify. Adequate but not complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, and it does: it explains that deep=true triggers an additional real retrieval probe, adding meaning beyond the bare boolean schema entry. This satisfies the compensation requirement for the single parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: checking paths and indexes of the RAG system. It is not a tautology and adds the deep-mode behavior. However, it does not differentiate from the sibling rag_get_status, which likely overlaps in health/status checking, so it misses the chance to distinguish itself.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus rag_get_status or the other siblings. The deep=true explanation describes a mode of this tool, not a routing decision. There are no when/when-not conditions or alternative mentions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

rag_list_sourcesC

列出 manifest 中的来源、许可、层级、题号、URL 与哈希。

ParametersJSON Schema
NameRequiredDescriptionDefault
layerNo
limitNo
case_idNo
index_defaultNoyes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It implies a read-only operation ('list') but does not explicitly state that it has no side effects, requires no special permissions, or how it behaves with edge cases (e.g., empty manifest, large result sets). It adds minimal behavioral context beyond the verb.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and lists the output fields. It contains no filler or redundancy, making it appropriately concise for a straightforward listing tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 4 optional parameters and no schema-level descriptions, the description is insufficient. It does not explain parameter semantics, return format (though output schema exists, its details are not shown), or any usage constraints. An agent would struggle to correctly invoke this tool without additional context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage for parameters, and the description does not explain any of the four parameters (layer, limit, case_id, index_default). It does not clarify their purpose, valid values, or how they filter or paginate results. The description fails to compensate for the schema's lack of parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific verb ('list') and resource ('sources in the manifest') with attributes (licenses, layers, question numbers, URLs, hashes). It distinguishes itself from sibling tools like rag_search (search) and rag_get_document (get single document) by indicating a listing operation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool vs alternatives. It does not mention prerequisites, typical use cases, or cases where another sibling (e.g., rag_search) would be more appropriate. The description is purely functional, leaving usage to the agent's inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv0.1.0
    • First observedrag_get_case_context
    • First observedrag_get_document
    • First observedrag_get_status
    • First observedrag_health
    • First observedrag_list_sources
    • First observedrag_search

TDQS

B3.4/5.0

Scored across 6 tools

Disambiguation4/5

Most tools have clearly distinct roles: search, document retrieval, source listing, and case-context assembly are well separated. However, rag_get_status and rag_health overlap in purpose, both probing system/index health, which could cause occasional misselection.

Naming Consistency5/5

All tools share the rag_ prefix and use consistent snake_case with action-oriented verbs like get, search, list, and health. The naming pattern is predictable and easy to extend.

Tool Count5/5

Six tools form a tight, well-scoped surface for a RAG retrieval server: search, document access, source metadata, context assembly, and health/status checks. No tool feels redundant or unnecessary.

Completeness4/5

The retrieval side is well covered: search, document reading, source listing, case context, and health checks. Minor gaps exist around index management or ingestion, but the apparent read-only RAG purpose is largely satisfied.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers