ragdial-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ragdial_mcp-0.1.0/.gitignore +12 -0
- ragdial_mcp-0.1.0/Dockerfile +28 -0
- ragdial_mcp-0.1.0/LICENSE +21 -0
- ragdial_mcp-0.1.0/PKG-INFO +364 -0
- ragdial_mcp-0.1.0/README.md +322 -0
- ragdial_mcp-0.1.0/pyproject.toml +80 -0
- ragdial_mcp-0.1.0/sample_data/corpus/api_reference.md +77 -0
- ragdial_mcp-0.1.0/sample_data/corpus/architecture.md +27 -0
- ragdial_mcp-0.1.0/sample_data/corpus/changelog.md +51 -0
- ragdial_mcp-0.1.0/sample_data/corpus/config_reference.md +88 -0
- ragdial_mcp-0.1.0/sample_data/corpus/deployment_runbook.md +74 -0
- ragdial_mcp-0.1.0/sample_data/corpus/error_codes.md +57 -0
- ragdial_mcp-0.1.0/sample_data/corpus/faq.txt +28 -0
- ragdial_mcp-0.1.0/sample_data/corpus/incident_postmortem_2026_09.md +38 -0
- ragdial_mcp-0.1.0/sample_data/corpus/migration_v2_to_v3.md +56 -0
- ragdial_mcp-0.1.0/sample_data/corpus/pricing_plans.md +45 -0
- ragdial_mcp-0.1.0/sample_data/corpus/python_sdk.md +122 -0
- ragdial_mcp-0.1.0/sample_data/corpus/rate_limits.md +51 -0
- ragdial_mcp-0.1.0/sample_data/corpus/security_policy.md +35 -0
- ragdial_mcp-0.1.0/sample_data/golden_qa.jsonl +30 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/__init__.py +3 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/chunking/__init__.py +0 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/chunking/boundary_audit.py +140 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/chunking/strategies.py +335 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/demo.py +73 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/ingestion/__init__.py +0 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/ingestion/parser.py +251 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/lab.py +485 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/models.py +141 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/py.typed +0 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/retrieval/__init__.py +0 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/retrieval/embedders.py +136 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/retrieval/hybrid.py +203 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/retrieval/metrics.py +62 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/samples.py +30 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/server.py +205 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/storage/__init__.py +0 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/storage/db.py +160 -0
- ragdial_mcp-0.1.0/src/ragdial_mcp/tokens.py +67 -0
- ragdial_mcp-0.1.0/tests/__init__.py +0 -0
- ragdial_mcp-0.1.0/tests/conftest.py +32 -0
- ragdial_mcp-0.1.0/tests/test_chunkers.py +153 -0
- ragdial_mcp-0.1.0/tests/test_mcp_tools.py +112 -0
- ragdial_mcp-0.1.0/tests/test_metrics.py +80 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# RAGDial MCP: reproducible image, served over Streamable HTTP on :8000/mcp
|
|
2
|
+
#
|
|
3
|
+
# docker build -t ragdial-mcp . # core (offline hash embedder, BM25, RRF)
|
|
4
|
+
# docker build -t ragdial-mcp:ml --build-arg EXTRAS=ml . # + bge-small, bge-reranker-base, ChromaDB
|
|
5
|
+
# docker run --rm -p 8000:8000 -v ragdial:/data ragdial-mcp
|
|
6
|
+
FROM python:3.11-slim
|
|
7
|
+
|
|
8
|
+
ARG EXTRAS=""
|
|
9
|
+
ENV UV_COMPILE_BYTECODE=1 \
|
|
10
|
+
UV_LINK_MODE=copy \
|
|
11
|
+
RAGDIAL_HOME=/data \
|
|
12
|
+
TIKTOKEN_CACHE_DIR=/opt/tiktoken \
|
|
13
|
+
PATH="/app/.venv/bin:$PATH"
|
|
14
|
+
|
|
15
|
+
COPY --from=ghcr.io/astral-sh/uv:0.13 /uv /uvx /bin/
|
|
16
|
+
WORKDIR /app
|
|
17
|
+
|
|
18
|
+
COPY pyproject.toml uv.lock README.md ./
|
|
19
|
+
RUN uv sync --frozen --no-dev --no-install-project $( [ -n "$EXTRAS" ] && echo "--extra $EXTRAS" )
|
|
20
|
+
|
|
21
|
+
COPY src ./src
|
|
22
|
+
COPY sample_data ./sample_data
|
|
23
|
+
RUN uv sync --frozen --no-dev $( [ -n "$EXTRAS" ] && echo "--extra $EXTRAS" ) \
|
|
24
|
+
&& python -c "from ragdial_mcp.tokens import get_tokenizer; print(get_tokenizer().name)"
|
|
25
|
+
|
|
26
|
+
VOLUME ["/data"]
|
|
27
|
+
EXPOSE 8000
|
|
28
|
+
CMD ["ragdial-mcp", "--transport", "streamable-http", "--host", "0.0.0.0", "--port", "8000"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RAGDial MCP contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ragdial-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RAGDial MCP: an MCP server for RAG chunking & retrieval ablations. Boundary-damage audits, Recall@k / MRR / nDCG@k, hybrid BM25 + dense (RRF), reranking. Local-first.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Salman-khann/RAGDial-MCP
|
|
6
|
+
Project-URL: Repository, https://github.com/Salman-khann/RAGDial-MCP
|
|
7
|
+
Project-URL: Issues, https://github.com/Salman-khann/RAGDial-MCP/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Salman-khann/RAGDial-MCP/releases
|
|
9
|
+
Author: Salman Khan
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: benchmark,bm25,chunking,embeddings,evaluation,hybrid-search,llm,mcp,model-context-protocol,rag,reranking,retrieval
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
24
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: mcp<3,>=2.3
|
|
28
|
+
Requires-Dist: numpy>=1.26
|
|
29
|
+
Requires-Dist: pydantic>=2.7
|
|
30
|
+
Requires-Dist: rank-bm25>=0.2.2
|
|
31
|
+
Requires-Dist: tiktoken>=0.7
|
|
32
|
+
Provides-Extra: all
|
|
33
|
+
Requires-Dist: chromadb>=0.5; extra == 'all'
|
|
34
|
+
Requires-Dist: pymupdf4llm>=0.0.17; extra == 'all'
|
|
35
|
+
Requires-Dist: sentence-transformers>=3.0; extra == 'all'
|
|
36
|
+
Provides-Extra: ml
|
|
37
|
+
Requires-Dist: chromadb>=0.5; extra == 'ml'
|
|
38
|
+
Requires-Dist: sentence-transformers>=3.0; extra == 'ml'
|
|
39
|
+
Provides-Extra: pdf
|
|
40
|
+
Requires-Dist: pymupdf4llm>=0.0.17; extra == 'pdf'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# RAGDial MCP
|
|
44
|
+
|
|
45
|
+
[](https://github.com/Salman-khann/RAGDial-MCP/actions/workflows/ci.yml)
|
|
46
|
+
[](https://pypi.org/project/ragdial-mcp/)
|
|
47
|
+

|
|
48
|
+

|
|
49
|
+
[](LICENSE)
|
|
50
|
+
|
|
51
|
+
**RAGDial MCP is a RAG retrieval ablation & chunking lab, packaged as an MCP server.** It turns an AI coding assistant (Claude Code, Cursor, Claude Desktop) into a systematic retrieval tuner. Instead of guessing chunk sizes and overlaps, the agent runs controlled experiments, looks at exactly which tables and code blocks got cut in half, and picks a pipeline using Recall@k, MRR, nDCG@k and p95 latency.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
ingest_corpus → run_chunking_ablation → inspect_boundary_splits → benchmark_retrieval → diff_experiment_runs
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Everything runs locally: no API keys and no paid services. On the bundled benchmark pack, the full loop takes about 4 seconds on a laptop.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quick start (under 2 minutes)
|
|
62
|
+
|
|
63
|
+
You need [uv](https://docs.astral.sh/uv/getting-started/installation/) and nothing else; uv fetches Python 3.11+ if it's missing.
|
|
64
|
+
|
|
65
|
+
**Add it to Claude Code:**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
claude mcp add ragdial -- uvx ragdial-mcp
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then ask: *"Ingest @sample, ablate fixed vs markdown chunking at 256/512 tokens, show me which tables got split, and benchmark against @sample."* The `@sample` shortcut points the tools at the bundled 13-document benchmark pack and its 30 golden questions. Point `ingest_corpus` at your own docs folder when you're ready.
|
|
72
|
+
|
|
73
|
+
**See the whole loop in your terminal, no agent needed:**
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uvx --from ragdial-mcp ragdial-demo
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Work on the code:**
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
git clone https://github.com/Salman-khann/RAGDial-MCP.git
|
|
83
|
+
cd RAGDial-MCP
|
|
84
|
+
uv sync # core deps: MCP SDK, tiktoken, rank-bm25, numpy
|
|
85
|
+
uv run ragdial-demo # full before/after loop on sample_data/ (about 4 s)
|
|
86
|
+
uv run pytest # 32 deterministic tests, no downloads
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To run the latest unreleased `main` instead of the PyPI release, use `uvx --from git+https://github.com/Salman-khann/RAGDial-MCP ragdial-mcp`.
|
|
90
|
+
|
|
91
|
+
The real output of `uv run ragdial-demo`, abridged:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
[2] chunking ablation
|
|
95
|
+
config chunks p50 tok p95 tok damage tables cut
|
|
96
|
+
fixed-256-o0 45 256.0 256.0 0.302 12/14
|
|
97
|
+
markdown-256-o0 91 111.0 243.5 0.0371 5/14 ← cut tables keep a replicated header row
|
|
98
|
+
|
|
99
|
+
[3] boundary splits in fixed-256-o0
|
|
100
|
+
- config_reference#storage-keys (table) cut between config_reference::0001 | config_reference::0002
|
|
101
|
+
...'Directories that hold partition segments. Spread across disks' <CUT> ' for throughput. |\n| `storage.segment_bytes` | size | 512MiB |'
|
|
102
|
+
|
|
103
|
+
[4] retrieval benchmark (30 queries, embedder=hash-2048, store=numpy)
|
|
104
|
+
variant R@5 MRR nDCG@5
|
|
105
|
+
markdown-256-o0|bm25|none 0.983 0.911 0.926
|
|
106
|
+
markdown-256-o0|hybrid|none 0.917 0.786 0.803
|
|
107
|
+
fixed-256-o0|bm25|none 0.817 0.728 0.742
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
[5] diff fixed-256-o0|bm25|none -> markdown-256-o0|bm25|none
|
|
111
|
+
recall_at_k 0.8167 -> 0.9833 (+0.1667)
|
|
112
|
+
ndcg_at_k 0.742 -> 0.926 (+0.184)
|
|
113
|
+
fixed: ['q01', 'q06', 'q10', 'q12', 'q19']
|
|
114
|
+
regressed: []
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
To use real models (`BAAI/bge-small-en-v1.5`, the `BAAI/bge-reranker-base` cross-encoder, and ChromaDB):
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
uvx --from "ragdial-mcp[ml]" ragdial-demo --embedder bge-small --reranker bge-reranker-base
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The same before/after comparison with real models (measured on a laptop CPU, no GPU):
|
|
124
|
+
|
|
125
|
+
| Variant | Recall@5 | MRR | nDCG@5 | p95 per query |
|
|
126
|
+
|---|---|---|---|---|
|
|
127
|
+
| markdown-256, dense + bge reranker | 0.983 | 0.950 | **0.950** | 13.2 s |
|
|
128
|
+
| fixed-256, dense + bge reranker | 0.833 | 0.767 | 0.779 | 16.8 s |
|
|
129
|
+
|
|
130
|
+
Five queries flip from miss to hit and none regress. Note the latency: the cross-encoder reranker is very slow on CPU. That's exactly the trade-off `generate_rag_spec` weighs against a latency budget.
|
|
131
|
+
|
|
132
|
+
## Connect it to an agent
|
|
133
|
+
|
|
134
|
+
**Claude Code:**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
claude mcp add ragdial -- uvx ragdial-mcp
|
|
138
|
+
# with real models:
|
|
139
|
+
claude mcp add ragdial -- uvx --from "ragdial-mcp[ml]" ragdial-mcp
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Inside a clone, the project-scoped [`.mcp.json`](.mcp.json) also offers the `ragdial` server automatically, running your local checkout.
|
|
143
|
+
|
|
144
|
+
**Cursor / Claude Desktop** (`mcpServers` entry):
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{ "ragdial": { "command": "uvx", "args": ["ragdial-mcp"] } }
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Remote / container** (Streamable HTTP on `http://localhost:8000/mcp`):
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
uv run ragdial-mcp --transport streamable-http --port 8000
|
|
154
|
+
# or
|
|
155
|
+
docker build -t ragdial-mcp . && docker run --rm -p 8000:8000 -v ragdial:/data ragdial-mcp
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Inspect the schemas** with the MCP Inspector:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npx @modelcontextprotocol/inspector uv run ragdial-mcp
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Then ask the agent something like: *"Ingest sample_data/corpus, ablate fixed/recursive/markdown/semantic at 128/256/512 with 0 and 64 overlap, show me the worst table splits, benchmark against sample_data/golden_qa.jsonl and tell me which config to ship."*
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Local or hosted?
|
|
169
|
+
|
|
170
|
+
RAGDial does its work (parsing, chunking, embedding, ranking) in its own process, so whoever runs that process supplies the CPU, RAM and disk. The AI model only receives the compact JSON results.
|
|
171
|
+
|
|
172
|
+
**Run it locally (the default, recommended for most people).** Your MCP client starts `ragdial-mcp` on your machine over stdio, as set up in [`.mcp.json`](.mcp.json) and the quick start.
|
|
173
|
+
|
|
174
|
+
- Your documents never leave your machine. Only metric summaries and short excerpts reach the model.
|
|
175
|
+
- `ingest_corpus` reads any folder on your disk directly, with no upload step.
|
|
176
|
+
- There's no server to pay for and no account or API key to manage.
|
|
177
|
+
- The core mode is light: the full sample loop runs in seconds. Expect real CPU and RAM use only with the `ml` extra. Its models total about 1.3 GB on disk, and the cross-encoder reranker is slow on CPU but uses an NVIDIA GPU automatically if PyTorch finds one.
|
|
178
|
+
|
|
179
|
+
**Host it as a shared server** when one of these applies:
|
|
180
|
+
|
|
181
|
+
- **Heavy models on weak laptops:** a GPU server runs `bge-reranker-base` many times faster than a laptop CPU.
|
|
182
|
+
- **Teams:** everyone shares one experiment history and can diff each other's runs.
|
|
183
|
+
- **Large corpora:** tens of thousands of documents need more memory and time than a laptop comfortably gives.
|
|
184
|
+
- **Zero install for users:** people connect with a URL instead of installing uv and Python.
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
docker build -t ragdial-mcp:ml --build-arg EXTRAS=ml .
|
|
188
|
+
docker run -d -p 8000:8000 --gpus all \
|
|
189
|
+
-v ragdial:/data \
|
|
190
|
+
-v /srv/corpora:/corpora:ro \
|
|
191
|
+
ragdial-mcp:ml
|
|
192
|
+
# clients connect to http://<host>:8000/mcp and ingest e.g. folder_path="/corpora/my-docs"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Drop `--gpus all` on a machine without an NVIDIA GPU.
|
|
196
|
+
|
|
197
|
+
Keep in mind when hosting:
|
|
198
|
+
|
|
199
|
+
- **Paths are server paths.** `ingest_corpus` reads folders on the *server*, so mount the document folders into the container (read-only, as above).
|
|
200
|
+
- **There is no built-in authentication.** Anyone who can reach the port can run experiments and read any folder the container can see. Keep it on a private network or behind a reverse proxy that handles auth and TLS. Never expose it directly to the internet.
|
|
201
|
+
- **Data in `/data` is shared** by all users of that server: corpora, runs and reports.
|
|
202
|
+
|
|
203
|
+
| | Local (stdio) | Hosted (Streamable HTTP) |
|
|
204
|
+
|---|---|---|
|
|
205
|
+
| Who pays for compute | Each user's machine | The server |
|
|
206
|
+
| Where documents live | User's disk | Mounted on the server |
|
|
207
|
+
| Setup per user | Install uv, clone or `uvx` | Paste a URL |
|
|
208
|
+
| Experiment history | Per user (`~/.ragdial`) | Shared (`/data`) |
|
|
209
|
+
| GPU for reranking | Only if the user has one | Provision once on the server |
|
|
210
|
+
| Access control | Your OS account | Your network or reverse proxy (none built in) |
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## MCP surface
|
|
215
|
+
|
|
216
|
+
### Tools (model-driven actions)
|
|
217
|
+
|
|
218
|
+
| Tool | Key parameters | Returns |
|
|
219
|
+
|---|---|---|
|
|
220
|
+
| `ingest_corpus` | `folder_path`, `corpus_id` | File count, total tokens, detected headers/tables/nested tables/code/lists, document IDs |
|
|
221
|
+
| `run_chunking_ablation` | `corpus_id`, `strategies[]`, `chunk_sizes[]`, `overlaps[]`, `embedder` | Per config: chunk count, token p50/p95/max, **boundary-damage score**, severed/total per structure kind |
|
|
222
|
+
| `inspect_boundary_splits` | `run_id`, `limit=5`, `config_id`, `kinds[]` | Excerpts of about 110 characters on each side of every cut through a table, code fence, list or paragraph |
|
|
223
|
+
| `benchmark_retrieval` | `run_id`, `dataset_path`, `retrievers[]`, `reranker`, `top_k`, `configs[]`, `embedder`, `vector_store` | Recall@k, MRR, nDCG@k, hit rate, p50/p95 latency per *chunk config × retriever*, plus the 3 worst queries |
|
|
224
|
+
| `diff_experiment_runs` | `run_a`, `run_b`, `variant_a`, `variant_b` | Metric deltas (B − A), query IDs that flipped miss→hit or regressed, and rank-movement counts |
|
|
225
|
+
|
|
226
|
+
### Resources (read-only context)
|
|
227
|
+
|
|
228
|
+
| URI | Content |
|
|
229
|
+
|---|---|
|
|
230
|
+
| `ragdial://experiments` | Index of corpora and runs with configs, timestamps and headline metrics |
|
|
231
|
+
| `ragdial://experiments/{run_id}/report` | Full JSON: every variant and the per-query hit/miss table with top chunk IDs |
|
|
232
|
+
| `ragdial://corpus/{corpus_id}/stats` | Document metadata, token counts and structural breakdown |
|
|
233
|
+
|
|
234
|
+
### Prompts (user-triggered workflows)
|
|
235
|
+
|
|
236
|
+
| Prompt | What it makes the agent do |
|
|
237
|
+
|---|---|
|
|
238
|
+
| `diagnose_retrieval_failures(run_id)` | Pull the worst queries from the report, run `inspect_boundary_splits`, classify each miss (boundary damage / ranking / vocabulary / dilution), test **one** targeted fix and confirm it with `diff_experiment_runs` |
|
|
239
|
+
| `generate_rag_spec(corpus_id, latency_budget_ms)` | Drop variants over the p95 budget, rank the rest by nDCG → recall → damage → latency, and emit a YAML production spec that cites the supporting run IDs |
|
|
240
|
+
|
|
241
|
+
### Context-window discipline, by design
|
|
242
|
+
|
|
243
|
+
Each tool returns a **typed Pydantic model** (exposed as an MCP `outputSchema` with `structuredContent`) holding metric tables, IDs and a `next_step` hint. **No tool returns chunk text.** The only text that reaches the model is the clipped excerpts from `inspect_boundary_splits`, at most 25 of them. Full per-query detail sits behind `ragdial://experiments/{run_id}/report`, and the agent reads it only for the queries it is investigating. A 48-config ablation costs a few KB of context, not a few MB.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## How it measures things
|
|
248
|
+
|
|
249
|
+
### Chunkers ([`chunking/strategies.py`](src/ragdial_mcp/chunking/strategies.py))
|
|
250
|
+
|
|
251
|
+
Each chunker records the exact source span (`start`/`end` character offsets) of every chunk, which is what makes the boundary audit exact.
|
|
252
|
+
|
|
253
|
+
| Strategy | Behaviour |
|
|
254
|
+
|---|---|
|
|
255
|
+
| `fixed` | Sliding windows of exactly `size` tiktoken tokens, `overlap` tokens shared |
|
|
256
|
+
| `recursive` | Recursive splitting on paragraph → line → sentence → clause → word, greedily merged up to `size` |
|
|
257
|
+
| `markdown` | Header-aware: never crosses a section, keeps tables/code/lists atomic when they fit, splits oversized tables by rows **with the header row replicated**, prefixes every chunk with its breadcrumb (`Doc > Section > Subsection`) |
|
|
258
|
+
| `semantic` | Embeds sentences/blocks and breaks where adjacent similarity falls in the bottom quartile, capped at `size` |
|
|
259
|
+
|
|
260
|
+
### Boundary damage ([`chunking/boundary_audit.py`](src/ragdial_mcp/chunking/boundary_audit.py))
|
|
261
|
+
|
|
262
|
+
A structure is **severed** when no single chunk contains it whole, so overlap that keeps a full copy somewhere rescues it. The damage score is the weighted share of severed structures (tables and code ×3, lists ×1.5, paragraphs ×1). A severed table whose pieces all carry the header row counts as **mitigated** at half weight. Every severed item also records whether it was *oversized*, meaning bigger than the chunk size and so impossible to keep intact.
|
|
263
|
+
|
|
264
|
+
### Retrieval ([`retrieval/hybrid.py`](src/ragdial_mcp/retrieval/hybrid.py))
|
|
265
|
+
|
|
266
|
+
* `bm25`: Okapi BM25 via `rank-bm25`
|
|
267
|
+
* `dense`: cosine similarity in an **ephemeral ChromaDB collection per experiment** (or an in-memory NumPy index without the `ml` extra)
|
|
268
|
+
* `hybrid`: **Reciprocal Rank Fusion** (k = 60) of the top 50 from BM25 and the top 50 from dense
|
|
269
|
+
* optional cross-encoder reranking (`bge-reranker-base`) of the top 20 fused candidates
|
|
270
|
+
|
|
271
|
+
Latency is measured per query (query embedding + search + rerank) after a warm-up query, and reported as p50/p95.
|
|
272
|
+
|
|
273
|
+
### Ground truth that can't be fooled by chunking ([`retrieval/metrics.py`](src/ragdial_mcp/retrieval/metrics.py))
|
|
274
|
+
|
|
275
|
+
Golden queries reference **evidence snippets quoted verbatim from the corpus**, not chunk IDs. Chunk IDs change with every config, so they can't serve as ground truth. A chunk is relevant only if it contains *every* snippet of an evidence group:
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{"id": "q09", "question": "What does extra storage cost per GB-month on the Business plan?",
|
|
279
|
+
"evidence": ["| Feature | Developer | Starter | Growth | Business | Enterprise |",
|
|
280
|
+
"| Storage overage per GB-month | n/a | $0.10 | $0.08 | $0.05 | custom |"]}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
A chunk holding the price row without the column header can't say which plan `$0.05` belongs to, and the metric scores it as a miss. Splitting a table therefore shows up as a measurable retrieval failure. Queries can also carry several `evidence_groups`, for answers that span documents. Recall@k is then the share of groups covered.
|
|
284
|
+
|
|
285
|
+
* **Recall@k**: share of evidence groups found in the top k ("found somewhere")
|
|
286
|
+
* **MRR**: 1 / rank of the first relevant chunk, ranked at least 10 deep
|
|
287
|
+
* **nDCG@k**: binary gain where each evidence group counts once, so a duplicate overlapping chunk can't inflate it and "ranked #1" beats "ranked #5"
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Benchmark pack
|
|
292
|
+
|
|
293
|
+
[`sample_data/corpus/`](sample_data/corpus) holds 13 documents for a fictional event-streaming platform: about 10k tokens, 14 tables (two nested inside numbered list items), 16 code fences in Python/Bash/TOML/JSON/diff, and Markdown plus plain text. They include a config reference with 4 wide tables, a rate-limit and quota guide, an error catalogue, an SDK guide, a Kubernetes runbook, pricing, security, a migration guide, a changelog, a postmortem and a plain-text FAQ.
|
|
294
|
+
|
|
295
|
+
[`sample_data/golden_qa.jsonl`](sample_data/golden_qa.jsonl) holds 30 questions: 14 about tables (header + row must co-occur), 5 about code (two lines of the same block), 9 about prose or lists, and 2 cross-document questions. A test checks that every evidence snippet exists verbatim in the corpus.
|
|
296
|
+
|
|
297
|
+
To use your own data, point `ingest_corpus` at any folder of `.md` / `.txt` / `.pdf` files (PDFs need `uv sync --extra pdf`, which converts them with `pymupdf4llm` and keeps tables) and write a JSONL file in the same format.
|
|
298
|
+
|
|
299
|
+
## Embedders
|
|
300
|
+
|
|
301
|
+
| `embedder=` | What it is | When |
|
|
302
|
+
|---|---|---|
|
|
303
|
+
| `hash` | Deterministic feature hashing of unigrams + bigrams (2048-d, sublinear TF) | Tests, CI, offline demo: identical numbers on every machine |
|
|
304
|
+
| `bge-small` | `BAAI/bge-small-en-v1.5` via sentence-transformers, with the BGE query instruction | Real dense retrieval (`ml` extra) |
|
|
305
|
+
| any HF id | Any sentence-transformers model | Your own comparisons |
|
|
306
|
+
| `auto` (default) | `bge-small` if the `ml` extra is installed, otherwise `hash` | |
|
|
307
|
+
|
|
308
|
+
The `hash` embedder is a lexical proxy, so on it "dense" is close to BM25 and usually weaker. Draw conclusions about dense vs hybrid from `bge-small` runs. Every run records the embedder and vector store it used.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Project layout
|
|
313
|
+
|
|
314
|
+
```text
|
|
315
|
+
RAGDial-MCP/
|
|
316
|
+
├── pyproject.toml # uv project, extras: ml, pdf; entry points
|
|
317
|
+
├── Dockerfile # Streamable HTTP server on :8000/mcp
|
|
318
|
+
├── .mcp.json # Claude Code project config
|
|
319
|
+
├── .github/workflows/
|
|
320
|
+
│ ├── ci.yml # tests on Linux/Windows/macOS, wheel check, Docker HTTP smoke test
|
|
321
|
+
│ └── release.yml # GitHub release -> build, verify, publish to PyPI
|
|
322
|
+
├── sample_data/
|
|
323
|
+
│ ├── corpus/ # 13 technical docs (tables, nested tables, code)
|
|
324
|
+
│ └── golden_qa.jsonl # 30 Q&A pairs with verbatim evidence
|
|
325
|
+
├── src/ragdial_mcp/
|
|
326
|
+
│ ├── server.py # MCP tools, resources, prompts (thin adapter)
|
|
327
|
+
│ ├── lab.py # evaluation engine: no MCP imports
|
|
328
|
+
│ ├── models.py # compact Pydantic tool outputs
|
|
329
|
+
│ ├── demo.py # `ragdial-demo` CLI
|
|
330
|
+
│ ├── samples.py # locates the bundled pack ("@sample")
|
|
331
|
+
│ ├── tokens.py # tiktoken spans (regex fallback offline)
|
|
332
|
+
│ ├── ingestion/parser.py # MD/TXT/PDF → sections, blocks, structures w/ offsets
|
|
333
|
+
│ ├── chunking/strategies.py # fixed, recursive, markdown, semantic
|
|
334
|
+
│ ├── chunking/boundary_audit.py
|
|
335
|
+
│ ├── retrieval/embedders.py # hash / sentence-transformers
|
|
336
|
+
│ ├── retrieval/hybrid.py # BM25, Chroma/NumPy dense, RRF, cross-encoder
|
|
337
|
+
│ ├── retrieval/metrics.py # Recall@k, MRR, nDCG@k, percentiles
|
|
338
|
+
│ └── storage/db.py # SQLite run registry
|
|
339
|
+
└── tests/
|
|
340
|
+
├── test_chunkers.py # offsets, size caps, header replication, audit, golden validity
|
|
341
|
+
├── test_metrics.py # metric edge cases, RRF, searcher
|
|
342
|
+
└── test_mcp_tools.py # end-to-end through a real MCP client session
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**The engine is decoupled from the server.** `lab.Lab` is plain Python that returns Pydantic models, and `server.py` is a thin layer of decorators over it. The same engine already drives the `ragdial-demo` CLI and could back a side-by-side web dashboard without duplicating logic.
|
|
346
|
+
|
|
347
|
+
Runs persist in SQLite at `$RAGDIAL_HOME/ragdial.db` (default `~/.ragdial`), so experiments survive restarts and `diff_experiment_runs` works across sessions.
|
|
348
|
+
|
|
349
|
+
## Notes and limits
|
|
350
|
+
|
|
351
|
+
* Built on the official Python MCP SDK **v2** (`mcp.server.mcpserver.MCPServer`, the successor to v1's `FastMCP`).
|
|
352
|
+
* Token counts use tiktoken `cl100k_base`. If its BPE file can't be downloaded on first run, a regex tokenizer takes over and the backend name is reported in every result.
|
|
353
|
+
* The semantic chunker's quality depends on the embedder. With `hash`, it mostly finds lexical topic shifts.
|
|
354
|
+
* The sample pack is Markdown and plain text only. PDF ingestion works through the `pdf` extra, but multi-column PDF layouts depend on `pymupdf4llm`'s reconstruction.
|
|
355
|
+
|
|
356
|
+
## Releasing
|
|
357
|
+
|
|
358
|
+
1. Bump `__version__` in [`src/ragdial_mcp/__init__.py`](src/ragdial_mcp/__init__.py) and push.
|
|
359
|
+
2. Publish a GitHub release tagged `v<version>` (for example `v0.1.0`).
|
|
360
|
+
3. [`release.yml`](.github/workflows/release.yml) checks that the tag matches the version, runs the tests, builds the sdist and wheel, runs the wheel in isolation, and uploads it to PyPI with trusted publishing (no API token stored).
|
|
361
|
+
|
|
362
|
+
## License
|
|
363
|
+
|
|
364
|
+
MIT
|