Files
yvgude--lean-ctx/docs/contracts/attention-layout-driver-v1.md
T
wehub-resource-sync 26382a7ac6
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
JetBrains Plugin / Actionlint (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (rust) (push) Has been cancelled
JetBrains Plugin / Validation (push) Has been cancelled
JetBrains Plugin / Build (push) Has been cancelled
JetBrains Plugin / Test (push) Has been cancelled
Security Check / Security Scan (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:30 +08:00

1.8 KiB
Raw Blame History

Attention-aware Layout Driver v1 (AttentionLayoutDriverV1)

GitLab: #2311

LeanCTX kann Context nicht nur komprimieren, sondern auch re-layouten, damit relevante Teile an Positionen landen, die LLMs tatsächlich stärker beachten (“Lost in the Middle” → empirisch eher LCurve als UCurve).

Ziele

  • Deterministisch: gleicher Input + gleiche Keywords + gleiche Policy ⇒ gleiche Reihenfolge.
  • Semantic-first: bei größeren Inhalten zuerst ChunkReordering (Imports/Types/Fns), danach line-level fallback.
  • Policy-gated: reordering ist opt-in pro Profile.
  • Verifier-safe: Reorder darf keinen Content “verlieren”, nur umsortieren.
  • Bounded: kleine Inhalte werden nicht re-ordered (Edge Cases).

Aktivierung (Policy)

Per Profile:

  • profile.layout.enabled = true|false
  • profile.layout.min_lines = <n>

Default: enabled=false.

Semantik (v1)

  • Small files: wenn lines <= 5 (oder < min_lines) ⇒ keine Änderung.
  • Large content: ab lines >= 15 wird Chunking versucht:
    1. detect_chunks(content)
    2. order_for_attention(chunks, task_keywords)
    3. render_with_bridges(ordered)
  • Fallback: sonst line-level scoring + stable tie-break (original index).

Keywords

Keywords stammen aus dem Task/Intent Kontext (z.B. task Argument), extrahiert via task_relevance::parse_task_hints.

Determinism Guarantees

  • Sorts haben stabile Tie-breaks (z.B. start_line, original_index), damit gleiche Scores nicht zu nondeterministic reorder führen.

Relevanter Code

  • Driver: rust/src/core/attention_layout_driver.rs
  • Chunk reorder: rust/src/core/semantic_chunks.rs
  • Line-level reorder: rust/src/core/neural/context_reorder.rs
  • Learned attention curve: rust/src/core/neural/attention_learned.rs