Skip to content

Live Demo: Adaptive Context Package for LLM Prompts

iw index context-pack builds a single, token-budgeted RAG bundle — ranked files, symbols, architecture rules, cross-layer connections, rationale, and doc drift — in one call, so you can hand an LLM real context instead of letting it guess. The adaptive ranking layer reorders that bundle using signals CARI already has: your import graph and directory shape.

The example below is a real run against IntentWeave’s own .iw/index.db — same query, same anchor file, two adaptive modes. Toggle between them to see the ranking change.

query: "context-pack ranking noise" anchor: packages/index/src/queries/contextPack.ts live self-analysis · 2026-07-11

Raw FTS + annotation ranking. Notice the zero-score files near the bottom — generic term matches with no real relevance (PR templates, unrelated ADRs, skill files).

  1. #1 docs/PLAN-ADAPTIVITY-CONTEXT-PACKAGE.md 3.93 annotation match
  2. #2 CHANGELOG.md 3.39 annotation match
  3. #3 packages/core/src/errors.ts 2.25 annotated symbol: context
  4. #4 packages/core/src/interfaces.ts 2.25 annotated symbol: index
  5. #5 packages/index/src/queries/contextPack.ts 1.20 annotated symbol: contextPack
  6. #6 docs/LIBRARY-API.md 1.06 annotation + co-occurrence
  7. #7 docs/LAYERED-GRAPH-ARCHITECTURE.md 0.94 annotation + co-occurrence
  8. #8 docs/PRODUCT-CONCEPT.md 0.94 annotation: "noise reduction strategy"
  9. #9 packages/core/src/types/kwg.ts 0.75 annotated symbol: mentions
  10. #10 packages/index/src/export/prescriptiveReport.ts 0.75 annotated symbol: documentation
  11. #11 packages/core/src/types/hooks.ts 0.75 annotated symbol: strategy
  12. #12 packages/index/src/__tests__/topology.test.ts 0.12 annotation: "Ranking"
  13. #13 packages/index/src/queries/surprises.ts 0.12 annotation: "Ranking"
  14. #14 .github/pull_request_template.md 0.00 FTS fallback — co-occurs with "added"
  15. #15 docs/ADR-001-INTENT-ENGINE.md 0.00 FTS fallback
  16. #16 .github/copilot-instructions.md 0.00 FTS fallback
  17. #17 .github/prompts/focused-architecture.prompt.md 0.00 FTS fallback
  18. #18 .github/skills/iw-drift-detection/SKILL.md 0.00 FTS fallback
  19. #19 README.md 0.00 FTS fallback
Eval results across 3 repos (iw index eval, real M2 validation reports)
Repo Noisy-path share (off → conservative) Anchor hit rate (off → conservative) Latency p50 / p95 (conservative)
intentweave 0% 0% 100% 100% 7.5ms / 17.9ms
backstage 21% 0% 0% 88.9% 35.9ms / 113.6ms
codegraphchat-v2 14% 3.7% 70% 90% 111.3ms / 523.2ms

IntentWeave’s own repo already sits at 0% noise / 100% hit rate without adaptation — it’s small and well-curated, so there’s little for adaptive ranking to fix. The real gains show up on larger, messier repos like Backstage and codegraphchat-v2. codegraphchat-v2’s p95 latency (523ms) is higher than the sub-100ms figure quoted elsewhere on this site for a single iw index retrieve query — that’s expected: context-pack composes multiple sections (files, rules, connections, rationale, doc drift) in one call, not a single ranked-retrieval query.

The eval methodology, target thresholds, and boost algorithm are documented in the adaptivity rollout plan — the same spec these numbers were measured against. The raw per-repo query sets (.iw/eval/queries.json) are currently local fixtures, not yet published; if you want to reproduce the Backstage/codegraphchat-v2 numbers independently, open an issue and we’ll publish the fixture.

  1. Baseline (--adaptive=off) ranks files by annotation match, FTS relevance, and co-occurrence only — the same scoring iw index retrieve has always used.
  2. Repo-shape adaptation (Phase B) downweights low-signal and “meta” directories (.changeset/, .specstory/, archive/, node_modules/, etc.) using per-directory annotation density computed straight from the annotations table — no config needed, though .iw/config.yaml lets you pin exceptions for paths you always want surfaced.
  3. Anchor-aware adaptation (Phase C) boosts files that are actually connected to the file(s) you pass via --files: exact anchor (1.5×), same folder (1.2×), same package (1.1×), 1-hop import-neighbor (1.05×) — all read directly from the imports table CARI already builds. In the demo above, check.ts, connections.ts, retrieve.ts, shared.ts, and types.ts all get promoted because they’re real imports of the anchor file, contextPack.ts.

Both are shipped and on by default (conservative mode). Intent classification, per-section confidence budgeting, and a feedback-loop cache are specced in the roadmap but not yet implemented — see Adaptive Context Package for the full rollout plan.

Terminal window
# Reproduce this locally, on your own repo
iw index build
iw index context-pack \
--query "context-pack ranking noise" \
--files packages/index/src/queries/contextPack.ts \
--adaptive conservative --adaptive-explain \
--sections files --format json
# Measure it on a fixed query set
iw index eval --queries .iw/eval/queries.json --adaptive conservative