LLM Model Selection Logic and Scenario-Based Implementation Practices
Choosing an LLM is not about finding the single best model, but about finding the best fit under specific constraints. This article breaks down model selection across four common scenarios—code generation, general instruction following, cost engineering, and long-document processing—and outlines a reusable evaluation workflow based on internal test sets, tiered routing, and retrieval augmentation to balance quality, cost, and stability.
1. The Core Issue: No “Best Model,” Only the “Best Fit”
When business teams ask “which model is the best,” the answer almost always depends on the constraints. Model capability is a multi-dimensional vector that includes at least code generation accuracy, effective long-context utilization, multi-step reasoning stability, instruction-following fidelity, structured output reliability, time-to-first-token latency, and cost per token. No single-dimension ranking can cover real business needs. The first step in selection is therefore to translate business requirements into quantifiable technical metrics, rather than looking for a universal winner.
A common mistake is copying leaderboard conclusions directly. Leaderboards are usually evaluated on general-purpose corpora and fixed prompt sets, which differ in distribution from your private codebase style, document layouts, and terminology. A more reliable engineering practice is to build an internal evaluation set, using real traffic samples to form a regression baseline.
2. Technical Breakdown of Four Typical Requirements
2.1 Code Generation and Understanding: Compilation Pass Rate Is Only the Starting Point
The core difficulty of code tasks lies in long-range dependencies and constraint satisfaction. It is recommended to design layered metrics during evaluation:
# Example: layered evaluation skeleton for code tasksmetrics = {"syntax_pass": 0.0, # syntax/compilation pass rate"unit_test_pass": 0.0, # unit test pass rate"static_check": 0.0, # number of static check warnings"diff_minimality": 0.0, # whether the change scope is minimal}
What really separates models is the last two items: whether they change only the necessary lines and whether they introduce irrelevant dependencies. In engineering, a two-stage approach of “repository context retrieval + model completion” can improve stability by injecting cross-file information as summaries into the prompt, rather than concatenating source code endlessly.
2.2 General Capabilities: Instruction Following and Structured Output
The hidden cost in general scenarios comes from rework. If a model cannot reliably output parseable structures, downstream pipelines add substantial validation and retry logic. It is recommended to enforce strict constraints on structured output and keep a fallback:
{"action": "query", "filters": {"status": "open"}, "limit": 20}
Combined with server-side schema validation and one automatic retry, this usually reduces the overall failure rate more effectively than switching models.
2.3 Cost Engineering: Cost-Effectiveness Is an Architecture Problem
The per-token price is only the nominal cost. Real cost = invocation fees + retry overhead + manual review + experience loss from latency. A practical strategy is tiered routing: small models handle high-frequency short tasks such as classification, extraction, and rewriting, while large models handle only complex reasoning and critical generation, complemented by caching, batching, and prompt compression. Example logic:
if task_type in {classify, extract, rewrite} and tokens < 2k:route -> lightweight modelelse:route -> high-capability model
2.4 Long-Document Processing: Effective Context, Not Window Length
A large nominal window does not mean information is fully utilized. Common long-context issues include mid-section recall decay, layout noise interference, and linearly increasing cost. In practice, a more robust approach is “retrieval + layered summarization + citation”: first perform structured parsing to obtain a section tree, then retrieve relevant fragments based on the question, and finally require the model to provide traceable sources to reduce hallucination probability.
3. A Reusable Selection Workflow
- Define the task list and hard constraints (data compliance, deployment form, latency limits).
- Sample and build an internal evaluation set of 100–300 entries, covering long-tail and adversarial samples.
- Set pass thresholds and cost ceilings, and run small-scale canary comparisons.
- After launch, continuously run regression and monitor the distribution of failure types rather than only looking at averages.
When elastic compute and unified governance are needed, you can rely on general capabilities provided by Baidu AI Cloud, such as model services, container platforms, object storage, and log monitoring, to complete canary releases, quota management, and full-link observability.
4. Conclusion
The right approach to selection is to rewrite “which is best” into “what is optimal under which constraints.” With the internal evaluation set as the benchmark and tiered routing plus retrieval augmentation as the means, you can achieve a sustainable balance among quality, cost, and stability.
