Skip to content

feat(demo): Rewrite Theater β€” query normalization, step by step - #11

Merged
wesleyscholl merged 1 commit into
mainfrom
claude/focused-faraday-lykfyz
Jun 14, 2026
Merged

feat(demo): Rewrite Theater β€” query normalization, step by step#11
wesleyscholl merged 1 commit into
mainfrom
claude/focused-faraday-lykfyz

Conversation

@konjoinfinity

Copy link
Copy Markdown
Contributor

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 β€” RewriteEngine wraps konjoai.cache.rewriter.QueryRewriter unmodified. trace() exposes the real explain() per-step before/after trace; scenario() runs curated paraphrase clusters through the real rewrite() 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}.
  • 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 equals the real rewrite(), 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

  • 100% real, offline, deterministic β€” the trace is QueryRewriter.explain and the canonical key is QueryRewriter.rewrite, the same code kyro runs before a cache lookup. The UI shows partial collapse faithfully (no-op steps are labelled).

Verification

  • 51 demo tests pass, stable across multiple PYTHONHASHSEED values; ruff check . clean repo-wide.
  • All seven surfaces serve 200; the scenario endpoint returns the measured collapse.
  • Rendered & screenshotted headless against the live server.
  • Only demo/* + a new test changed β€” no production konjoai/ code touched.

Run it:

python3 demo/server.py        # http://localhost:8766/rewrite

https://claude.ai/code/session_01WWWgV1NwxaaNdPfy4PHN1K


Generated by Claude Code

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
@wesleyscholl
wesleyscholl marked this pull request as ready for review June 14, 2026 00:27
@wesleyscholl
wesleyscholl merged commit 8b80bc1 into main Jun 14, 2026
7 checks passed
@wesleyscholl
wesleyscholl deleted the claude/focused-faraday-lykfyz branch June 14, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants