Spaces:
Build error
Build error
|
Download docs/adr/ADR-004-context-optimizer-assembler.md from anwarkxc/trackademi: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/anwarkxc/trackademi/resolve/main/docs/adr/ADR-004-context-optimizer-assembler.md
- Command line
-
hf download hf://spaces/anwarkxc/trackademi/docs/adr/ADR-004-context-optimizer-assembler.md
-
curl -L -o ADR-004-context-optimizer-assembler.md https://huggingface.co/spaces/anwarkxc/trackademi/resolve/main/docs/adr/ADR-004-context-optimizer-assembler.md
1.61 kB
ADR-004: Context Optimizer + Context Assembler as their own services
Status
Accepted
Context
Turning a set of retrieved chunks plus their expanded graph elements into a final LLM prompt involves several distinct decisions: deduplicating elements reached via multiple paths, picking a token budget, deciding which images are worth attaching, choosing a table format, and ordering the content. Left inline in gateway.py, this logic tends to grow into a single large function branching on question type.
Decision
Split this into two services:
context_optimizer.pyβ strategy-agnostic: deduplication and noise reduction only, run once regardless of question type.context_assembler.pyβ a smallAssemblyStrategybase class with one subclass per generation mode (McqStrategy,EssayStrategy,BlueprintStrategy,ChatStrategy,DiagramQuestionStrategy), each owning only its token budget and image-selection threshold.
Alternatives considered
- One function with
if question_type == ...branches (the natural default): rejected β this is exactly the shape that turns into an unmaintainable file after a few more question types are added. - Folding deduplication into each strategy: rejected β deduplication has nothing to do with question type; every strategy needing to reimplement it is pure duplication.
Reasoning
gateway.py should only need to resolve the right strategy and call it β adding a new question type or supporting a new model tier's context needs should mean adding one new strategy class, not modifying a shared branching function.