Add hybrid analyzer combining heuristic and LLM judgment - #1
Merged
Conversation
Implement the LLM Analyzer Enhancement spec with: 1. Few-shot prompting (§3.1): Replaced zero-shot classification with 6 worked examples spread across all categories and non-round complexity values (0.05, 0.12, 0.22, 0.38, 0.64, 0.93). This fixes the round-number clustering problem where the LLM was selecting only the 3 anchor values (0, 0.5, 1) from the zero-shot instruction. 2. HybridAnalyzer (§3.2-3.5): New analyzer that blends heuristic signals with LLM judgment. The heuristic runs unconditionally (cheap, <1ms), and LLM output refines complexity via weighted blend and overrides category only when heuristic fell back to "general" (low confidence). On any LLM failure, returns heuristic result unchanged for reliable degradation. 3. Config & factory updates: Added analyzer.llm.hybrid_weight config (default 0.5), ModeHybrid constant, and factory wiring. 4. Exported LLMAnalyzer.Classify() for HybridAnalyzer to use without triggering LLMAnalyzer's own fallback logic. 5. Comprehensive unit tests covering blending behavior, weight extremes (0 and 1), LLM failures, and avoidance of round-number clustering. 6. Updated llm_ollama_test.go tolerance for the longer few-shot preamble. This fixes all four findings from the test cycle: - Few-shot eliminates round-number clustering (finding #3) - Hybrid mode adds explainability back via heuristic signals (finding #4) - LLM failure handling is now explicit in hybrid mode (finding #1) - Few-shot with JSON format improves parse reliability (finding #2) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AatiioR5QBGq6NPvHYbLHj
…w-shot - docs/analyzer.md: - Update analyzer comparison table to mention few-shot for llm mode - Add hybrid analyzer section with blend formula, category override rules, signals - Explain how hybrid mode fixes round-number clustering and explainability issues - Update config example to show hybrid_weight - docs/config.md: - Add 'hybrid' to analyzer.mode enum - Add hybrid_weight field documentation (0..1, default 0.5) - Update llm.model validation to note it's required for both llm and hybrid modes - Add ROUTE42_ANALYZER_LLM_HYBRID_WEIGHT to environment variables table - README.md: - Update analyzer table to add hybrid mode - Update analyzer configuration example with hybrid_weight Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AatiioR5QBGq6NPvHYbLHj
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.
Summary
Introduces a new
hybridanalyzer mode that blends deterministic heuristic signals with LLM judgment, combining the explainability and reliability of heuristic analysis with the accuracy of LLM classification on ambiguous prompts.Key Changes
New HybridAnalyzer (
internal/analyzer/hybrid.go):w * llm_score + (1-w) * heuristic_scorewherewis configurable (default 0.5)general)LLMAnalyzer improvements:
Classify()method (was privateclassify()) for use by HybridAnalyzerConfiguration:
analyzer.llm.hybrid_weightconfig field (0..1, default 0.5)ModeHybridconstant and validation for new modellmandhybridmodesROUTE42_ANALYZER_LLM_HYBRID_WEIGHTFactory pattern:
New()to instantiate HybridAnalyzer when mode ishybridType definitions:
NameHybridconstant for analyzer identificationComprehensive test suite (
internal/analyzer/hybrid_test.go):generalDocumentation:
analyzer.md,config.md, andREADME.mdwith hybrid mode explanationNotable Implementation Details
https://claude.ai/code/session_01AatiioR5QBGq6NPvHYbLHj