feat(demo): Rewrite Theater β query normalization, step by step - #11
Merged
Conversation
Adds a seventh flagship surface (/rewrite) showing kyro's real query-rewrite
pipeline β the deterministic, LLM-free normalizer that runs before every cache
lookup so differently-phrased questions share one canonical key.
- demo/rewriting.py β RewriteEngine wraps konjoai.cache.rewriter.QueryRewriter
unmodified: trace() exposes the real explain() per-step before/after trace,
and scenario() runs curated paraphrase clusters through the real rewrite() to
measure the cache-key collapse (keys saved β cache hits gained). No stubs.
- demo/rewrite.html β cinematic step pipeline (each of the 6 steps shows
changed vs no-op with beforeβafter diff and the final canonical key) plus a
paraphrase-collapse panel (phrasings β unique keys β hits gained). Ships
reduced-motion, focus-visible, view-transition and responsive layout.
- demo/server.py β GET /rewrite + GET /api/rewrite/{trace,scenario}.
- Rewrite linked in the nav across all surfaces (now: Playground Β· Observatory
Β· Pipeline Β· Agent Β· Security Β· HyDE Β· Rewrite).
- tests/unit/test_demo_rewrite.py β 8 contract tests (per-step trace matches
the real rewrite(), real step pipeline, paraphrase collapse arithmetic).
51 demo tests pass (stable across PYTHONHASHSEED); ruff clean repo-wide.
https://claude.ai/code/session_01WWWgV1NwxaaNdPfy4PHN1K
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A seventh flagship demo surface (
/rewrite) showing kyro's real query-rewrite pipeline β the deterministic, LLM-free normalizer that runs before every semantic-cache lookup so differently-phrased questions share one canonical key (would-be misses β hits).What's new
demo/rewriting.pyβRewriteEnginewrapskonjoai.cache.rewriter.QueryRewriterunmodified.trace()exposes the realexplain()per-step before/after trace;scenario()runs curated paraphrase clusters through the realrewrite()to measure the cache-key collapse (keys saved β cache hits gained). No stubs β this is the exact transform on the live lookup path.demo/rewrite.htmlβ cinematic step pipeline: each of the 6 real steps (lowercase β expand contractions β strip fillers β strip punctuation β normalize whitespace β strip trailing?) shows changed-vs-no-op with a beforeβafter diff and the final canonical key, plus a paraphrase-collapse panel (phrasings β unique keys β hits gained). Ships reduced-motion, focus-visible, View Transitions, and responsive layout.demo/server.pyβGET /rewrite+GET /api/rewrite/{trace,scenario}.tests/unit/test_demo_rewrite.pyβ 8 contract tests (per-step trace equals the realrewrite(), the real 6-step pipeline, paraphrase-collapse arithmetic).The payoff (real numbers)
The curated clusters: 10 phrasings β 3 unique cache keys β 7 keys saved / +7 cache hits gained β each case/whitespace/punctuation/contraction variant canonicalizes to one key.
Honesty notes
QueryRewriter.explainand the canonical key isQueryRewriter.rewrite, the same code kyro runs before a cache lookup. The UI shows partial collapse faithfully (no-op steps are labelled).Verification
PYTHONHASHSEEDvalues;ruff check .clean repo-wide.200; the scenario endpoint returns the measured collapse.demo/*+ a new test changed β no productionkonjoai/code touched.Run it:
python3 demo/server.py # http://localhost:8766/rewritehttps://claude.ai/code/session_01WWWgV1NwxaaNdPfy4PHN1K
Generated by Claude Code