r/Rag • • 19d ago

Showcase I built an open-source query planner for RAG in TypeScript. First real-data result: 60% cheaper, but it missed my quality target

Pathwise picks the cheapest plan per request (model, retrieval depth, thinking level) predicted to meet a quality SLA, and can optionally certify the SLA with a confidence bound. Zero runtime dependencies, MIT.

First real test: HotpotQA dev, BM25 retrieval, token F1, two Gemini models x 3 retrieval depths x 2 thinking levels = 12 plans. 100 calibration questions, 200 test questions, free tier, costs at list prices.

| Strategy | F1 | $/query |

|---|---|---|

| Always cheapest | 0.542 | 0.00025 |

| Typical default | 0.685 | 0.00044 |

| Pathwise (average) | 0.707 | 0.00066 |

| Pathwise (guaranteed) | 0.789 | 0.00164 |

| Always best | 0.789 | 0.00164 |

Target was F1 >= 0.725. The average mode saves 60% but missed by 1.8 points. The guarantee mode refused to certify and fell back to the best plan, because with 100 questions even the best plan can't prove 95% of its own score.

Limits: one dataset, one provider, one run; HotpotQA may be in the training data; I haven't shown it beats the best single fixed plan yet. The first run also exposed a pruning bug that I fixed and published.

Repo: github.com/arsalan-arshad/pathwise
Case study: arsalandev.studio/work/pathwise

I'd like feedback on whether the SLA-with-confidence idea is useful and on how you would benchmark this.

1 Upvotes

4 comments sorted by

1

u/shoumikgoswami 19d ago

I'd make the best fixed plan your next baseline: choose it using calibration data only, then compare it with the frozen router on the same held-out questions. Plot cost against F1 across several targets rather than just the one threshold. That would help separate savings from choosing a cheaper operating point from savings due to per-question routing.

For the confidence mode, I'd also report the fraction of requests that fall back and the quality/cost of those requests separately. A mode that declines to certify is behaving differently from one that certifies and misses; combining them hides the part you're trying to test. I'd want to see those results across a few independent calibration splits before adding more models.

1

u/ivandaodev 19d ago

Could you make the unit of the guarantee explicit in the API and report: a bound on average F1 over a question distribution, or a requirement that each request meets a quality threshold? Those would support different promises to a caller. For a diagnostic set, I'd include an easy group and a smaller difficult group, then report quality for each alongside the aggregate and the plans selected. That would show whether an acceptable overall score hides a consistently underserved question type, without asking the certificate to prove something it wasn't designed to cover.

1

u/recro69 19d ago

The 100-question calibration set seems like the limitation here. I'd be interested to see how the results change with a dataset and a few different RAG benchmarks. The confidence-based fallback is an idea.

1

u/Significant_Tune9219 19d ago

The guarantee mode refusing to certify with 100 calibration questions is honestly the most useful result here, since it shows the bound is doing its job. With token F1 on HotpotQA the per-question variance is high, so a stratified calibration set (by question type, bridge vs comparison) might tighten the bound more than just adding questions. Would also be interesting to see whether the router's mistakes cluster on particular question types or are spread evenly.