Large Language Model Selection and Scenario-Based Practices: A Practical Guide

    This guide explains how to select large language models based on task requirements rather than chasing a single "best" model. It breaks down four key evaluation dimensions—context capacity and long-context stability, reasoning depth and code correctness, tool calling and freshness, and cost and throughput—and maps them to four task categories: coding and refactoring, general Q&A and summarization, real-time information lookup, and deep research. It also covers building reproducible evaluation sets, engineering essentials such as a unified gateway, structured output, caching, fallback strategies, and observability, plus common pitfalls to avoid. Readers will gain a practical framework for balancing quality, cost, and stability in production.

    1. The Real Problem: Not “Which Model Is Best,” but “Which Capability Fits Which Task”

    In real engineering work, a common mistake is treating model selection as a one-time ranking question, hoping for a universal winner. Actual workloads are highly heterogeneous: code generation that requires long chains of logical reasoning, real-time information queries that are extremely sensitive to freshness, and deep research that synthesizes multiple sources. Forcing all three onto a single model usually forces trade-offs among cost, latency, and quality.

    A more rigorous approach is to profile the task first, then match capabilities. Task profiling means decomposing business requests into measurable dimensions; capability matching means choosing the inference engine and invocation pattern based on those dimensions. The sections below first define the evaluation dimensions, then apply them to concrete scenarios.

    2. Four Key Evaluation Dimensions

    1. Context capacity and long-context stability
      The context window determines how much material the model can “see” in one pass. But more important than the nominal window size is the ability to retain information in the middle of long inputs—the “lost in the middle” problem. Evaluate with questions that require reasoning across large spans of material, not just the advertised length.

    2. Reasoning depth and code correctness
      Code tasks test multi-step constraint satisfaction: types, edge cases, exception paths, and dependencies must all hold at once. Evaluation should include executable checks, such as unit test pass rates, rather than subjective impressions.

    3. Tool calling and freshness
      When up-to-date information is required, the model’s knowledge cutoff is unreliable, so retrieval or web tools are necessary. The evaluation focus here is the stability of tool calls, the accuracy of parameter extraction, and faithful citation of returned results (avoiding unsupported fabrication).

    4. Cost and throughput
      Account for per-call cost, concurrent throughput, and retry rates together. Many solutions look good in demos but lose control of costs under high concurrency due to rate limiting and amplified retries.

    3. Scenario-Based Routing: Matching Logic for Four Task Types

    • Coding and refactoring: Prefer engines with strong code ability, support for longer context, and stable structured patch output, paired with compilation and testing for closed-loop validation.
    • General Q&A and summarization: Prioritize low latency and high throughput; a moderate parameter size is sufficient. Focus on optimizing prompt templates and cache hit rates.
    • Real-time information queries: Must follow a “retrieval-first” pipeline. The model only summarizes and cites retrieved snippets and is prohibited from freely generating without sources.
    • Deep research: Use a multi-stage pipeline—decompose the question, retrieve in parallel, then cross-verify and compose the final draft—typically handled by a long-context, strong-reasoning engine for the final synthesis.

    A practical sketch of a routing layer is shown below (pseudocode, structure only):

    1. def route(task):
    2. if task.type == "code":
    3. return engine_long_context_code, {"temperature": 0.1, "max_tokens": 4096}
    4. if task.type == "realtime":
    5. return engine_with_search, {"require_citation": True, "temperature": 0.2}
    6. if task.type == "research":
    7. return engine_deep_reasoning, {"pipeline": "decompose_retrieve_verify", "max_tokens": 8192}
    8. return engine_general_fast, {"temperature": 0.3, "cache": True}

    4. Use Free Quotas for Experiments, Not for Production

    Many teams use free tiers across platforms for side-by-side comparisons. This is reasonable during exploration, but the boundaries must be clear: free tiers usually come with rate limits, differing data retention policies, and no SLA, making them suitable only for offline evaluation and prototype validation. Production pipelines should be built on resources with explicit service levels that are monitorable and auditable.

    In related practices at Baidu AI Cloud, the common approach is to first use a small offline evaluation set to shortlist candidates, then connect them through a unified model gateway, with logging, monitoring and alerting, and quota management—turning “selection” into a sustainable operational capability rather than a one-time decision.

    5. How to Build an Evaluation Set: Reproducibility Beats “It Feels Good”

    Build a three-tier evaluation set:

    1. Unit tier: single-point capability items, such as edge-case code, terminology explanations, and numeric extraction, for fast regression.
    2. Scenario tier: desensitized real business samples covering the high-frequency request distribution, to validate online performance.
    3. Adversarial tier: samples with ambiguity, extra-long material, and cases that require refusal, to test robustness and hallucination rate.

    Evaluation metrics should include at least: accuracy, citation accuracy, average latency P95, cost per request, and retry rate. Run the full set every time you change the engine or prompt version to produce comparable curves.

    6. Engineering Essentials

    • Unified gateway: Abstract away underlying differences to ease canary releases and rollbacks.
    • Structured output: Enforce JSON mode with schema validation to reduce downstream parsing failures.
    • Caching and batching: Apply semantic caching to high-frequency repeated requests for significant cost savings.
    • Fallback strategy: Automatically switch to a backup engine or return a retrieval summary when the primary engine exceeds limits.
    • Observability: Log prompt versions, retrieved snippet IDs, and token consumption for accountability and optimization.

    7. Common Pitfalls

    First, looking only at the advertised context length while ignoring mid-context information retention. Second, treating free quotas as production resources and overlooking rate limits and compliance. Third, lacking executable checks, which makes code tasks “look correct.” Fourth, missing citation constraints in the retrieval pipeline, which amplifies hallucinations. Fifth, letting the evaluation set go stale, so metrics become distorted after online distribution drift.

    8. Conclusion

    The right approach to model selection is “task-driven + reproducible evaluation + unified gateway operations.” Match coding, general Q&A, real-time retrieval, and deep research to the appropriate capability combinations, and close the loop with offline evaluation sets and online monitoring. Only then can you achieve a sustainable balance among quality, cost, and stability.