ntc-cdmx-mcp
RAG · NTC CDMX(2004 / 2017 / 2023)エキスパートチャットボット
メキシコシティ建築規制の補足技術基準に関するRetrieval-Augmented Generationシステム。ハイブリッド検索(BM25 + 多言語埋め込み + RRF)と、版および条項番号による引用を備えています。
構造
RAG/
├── src/
│ ├── config.py # rutas y mapeo PDF → (edición, norma)
│ ├── extract.py # PDF → páginas de texto por norma (temp/extracted_text/)
│ ├── structure.py # páginas → secciones X.Y.Z (data/corpus/*.json)
│ ├── index_build.py # secciones → catálogo + BM25 + embeddings (data/index/)
│ ├── retrieve.py # retriever híbrido (BM25 + embeddings + RRF + numeral)
│ ├── answer.py # generador de respuestas con LLM (DeepSeek V4 Flash)
│ ├── calc.py # cálculos validados (viento, sismo, combinaciones)
│ ├── evaluate.py # evaluación recall@k con el dataset de 21k Q&A
│ └── finetune_gen.py # genera dataset RAG-formateado para fine-tune del generador
├── app/app.py # interfaz web (Streamlit)
└── scripts/run_all.py # orquesta el pipeline completoRelated MCP server: RAG Anything MCP Server
MCPサーバー(opencode、codex、Claude Desktopなど向け)
このプロジェクトは、3つのツールを持つMCPサーバーとして公開されています。
Tool | 説明 |
| RAG + LLM(DeepSeek V4 Flash)で回答し、版・基準・条項番号を引用します。検証済みの計算も解決します。 |
| 関連するセクションを生のまま返します。 |
| 特定の条項番号の完全なテキストを返します。 |
自動インストール(opencode または codex にサーバーを登録します):
.venv\Scripts\python.exe scripts\install_mcp.py # opencode + codex
.venv\Scripts\python.exe scripts\install_mcp.py --opencode # solo opencode
.venv\Scripts\python.exe scripts\install_mcp.py --codex # solo codexopencode/codex を再起動すると、RAG がツール(answer_ntc など)として利用可能になります。サーバーは RAG/.env のプロバイダーのAPIキー、対応する環境変数、または ~/.config/ntc-cdmx/.env を読み取ります。
単一コマンドでのインストール(GitHub + uv)
uvx --from git+https://github.com/Sobrio25/ntc-cdmx-mcp ntc-cdmx-installこのコマンドは、MCP を opencode、Codex、Command Code、Kilo Code にインストールして登録します。クライアントを再起動すると、answer_ntc、search_ntc、get_section が利用可能になります。インデックス(BM25 + embeddings)はパッケージ内に同梱されています。プロバイダーのAPIキーは ~/.config/ntc-cdmx/.env で設定します。
実行可能ファイルのみをインストールする場合:
uv tool install git+https://github.com/Sobrio25/ntc-cdmx-mcpサーバーを手動でテストする:
ntc-cdmx # stdio (modo instalado)
.venv\Scripts\python.exe src\mcp_server.py # stdio (modo desarrollo)パイプライン
# 1) Extraer y estructurar e indexar
.venv/Scripts/python.exe scripts/run_all.py --steps extract structure index
# 2) Evaluar recall del retriever (muestra 400 preguntas del dataset de 21k)
.venv/Scripts/python.exe scripts/run_all.py --steps eval
# 3) Interfaz web
.venv/Scripts/python.exe -m streamlit run app/app.pyLLM の設定
回答には DeepSeek V4 Flash を使用します。プロバイダー/APIキーは src/answer.py(LLM_MODEL、LLM_BASE_URL)で設定します。キーがない場合、チャットボットは取得されたセクションを(LLMなしで)返します。デバッグに便利です。
検証済みの計算(src/calc.py)
質問が計算を求める場合(例:「Vz=35 m/s の風圧を計算して」)、エンジンはそれを検出し、LLM を介さずに、基準のテキストに対して検証済みの式を使用します。含まれる計算機:
計算 | 式 | 出典 |
風の動圧 | qz = 0.52·Vz² (m/s → Pa) | NTC-Viento 2023, §5.1.3 |
風による設計圧力 | pz = 0.47·Cp·VD² | NTC-Viento 2017/2004, §3.2 |
風の抗力 | F = 0.47·CD·VD²·A | NTC-Viento 2017/2004, §3.3 |
地震時最小基底せん断力 | Vo,min = amin·Wo | NTC-Sismo 2023, §7.5 |
荷重の組み合わせ | Grupo B: 1.3·CM+1.5·CV · Grupo A: 1.5·CM+1.7·CV | NTC-Criterios 2023, §3.4.1 |
データが不足している場合、チャットボットは明示的にそれを尋ねます。
生成器のファインチューニング(src/finetune_gen.py)
各例に取得されたコンテキストを含むチャット形式のデータセットを生成します(生成器が規範を暗記するのではなく、コンテキストから回答することを学習するため):
.venv/Scripts/python.exe src/finetune_gen.py --max 2000 --top_k 8 --require_all「gold」回答が取得されたコンテキストによって裏付けられていない例を自動的にフィルタリングします(引用された条項番号が存在しない場合 → 破棄されます)。
評価
evaluate.py モジュールは Documents\Fine_Tunning\NTC_CDMX\dataset.jsonl のデータセットを使用します。「gold」回答に引用された条項番号を持つ各質問について、その条項番号が取得されたセクションに含まれているかを検証します。
参考結果(引用付き質問164件のサンプル、top-6):recall@q ≈ 0.58。データセットによって引用された条項番号の約18%は、その版のコーパスに存在しません(データセットの引用誤りまたは抽出の欠落の可能性)。
技術的注記
2004年版と2017年版は官報(各PDFに複数文書)に収録されています。各基準の境界は
src/config.pyにマッピングされています。分割は番号付きセクション単位で行われ(段落単位では決してありません)、数式/表を保持します。
各セクションには、正確に引用するためのメタデータ
{edición, norma, numeral, página}が付いています。2023年のPDFはディスク上で文字化けしたファイル名を持ちます。抽出器は数字のプレフィックスでそれらを解決します。
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server giving Claude AI access to 22+ NYC public-record databases for real estate due diligence
Token-free MCP server for structured RevoGrid Core, Pro, and Enterprise knowledge retrieval.
MCP server for querying Forkast documentation
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAI-powered MCP server that enables Claude and other LLMs to interact directly with construction documents, drawings, and specifications through advanced RAG and hybrid search capabilities.9MIT
- AlicenseNot gradedqualityFmaintenanceAn MCP server that provides comprehensive multimodal Retrieval-Augmented Generation (RAG) capabilities for processing and querying document directories, supporting text, images, tables, and equations.37MIT
- FlicenseNot gradedqualityCmaintenanceMCP server for a modular RAG system that enables natural language question answering over enterprise documents with intent-aware routing, adaptive retrieval, and citation-backed responses.-
- AlicenseNot gradedqualityAmaintenanceMCP server for local RAG over personal notes, PDFs, and documents, enabling plain-English querying and hybrid search with multi-hop context expansion.MIT