LLM Model Selection and Engineering Practices: A Scenario-Based Guide

    This guide explains how to select large language models from an engineering perspective rather than relying on general-purpose leaderboards. It covers abstracting model capabilities into tiers, matching them to four common scenarios, building a three-layer evaluation system, controlling token cost and latency, and addressing security and observability. It also outlines a four-step rollout path and the cloud infrastructure needed to support it.

    1. Why Model Comparison Must Start from an Engineering Perspective

    In real projects, selection often fails not because a weak model was chosen, but because a general-purpose capability leaderboard was treated as the business acceptance standard. Model capabilities can be roughly divided into four layers: language understanding and generation, structured reasoning and tool calling, long-context information integration, and multimodal perception. Different businesses place very different weights on these four layers. The right way to compare models is therefore to define the task first, define the metrics second, and only then discuss the models.

    A practical approach is to abstract candidate models into several capability tiers rather than specific model names. A common engineering practice is to build a capability matrix where rows are capability dimensions, columns are candidate tiers, and each cell holds measured results from your own business samples rather than publicly advertised claims.

    1. # Example: capability matrix and weighted scoring
    2. weights = {"understanding": 0.25, "reasoning": 0.30, "long_context": 0.20, "multimodal": 0.10, "cost": 0.15}
    3. scores = {
    4. "Tier A": {"understanding": 0.9, "reasoning": 0.85, "long_context": 0.7, "multimodal": 0.6, "cost": 0.5},
    5. "Tier B": {"understanding": 0.8, "reasoning": 0.8, "long_context": 0.9, "multimodal": 0.5, "cost": 0.7},
    6. }
    7. rank = {k: sum(v[d] * weights[d] for d in weights) for k, v in scores.items()}
    8. print(sorted(rank.items(), key=lambda x: -x[1]))

    2. Four Typical Scenarios and How to Match Them

    The first scenario is content generation and rewriting. The core requirements are controllable style, stable instruction following, and long-form structure that does not collapse. Evaluation should focus on how much semantic drift occurs after multiple rounds of revision, not on how impressive the first output looks.

    The second scenario is knowledge Q&A and retrieval augmentation. The model itself is not responsible for the knowledge base; retrieval quality sets the upper bound. Here, focus on the model’s ability to recall information from the middle of a long context and on citation faithfulness, meaning whether the answer is strictly constrained by the provided material.

    The third scenario is structured extraction and tool calling. The key metrics are schema compliance rate and parameter validity rate, and the output must be reliably parseable by programs. In engineering terms, output formats should be strictly constrained, and failed samples should be retried automatically.

    1. {
    2. "task": "extract",
    3. "schema": {"order_id": "string", "amount": "number", "currency": "string"},
    4. "retry": {"max": 2, "on": ["schema_violation", "timeout"]}
    5. }

    The fourth scenario is multimodal and real-time interaction. Evaluate the latency distribution rather than the average, because the interaction experience is determined by the long tail. It is advisable to set dual thresholds for time to first token and end-to-end latency, and to prepare a fallback path.

    3. Evaluation System: Turning Subjective Impressions into Regression Metrics

    Evaluation should have three layers. The offline layer uses a fixed sample set for regression to prevent capability regressions caused by version updates. The online layer uses canary traffic for A/B testing to observe real conversion and the pass rate of manual spot checks. The fallback layer monitors abnormal output rate, timeout rate, and sensitive content interception rate.

    Building the sample set is the most easily overlooked step. A recommended mix is 70% high-frequency real requests, 20% boundary cases, and 10% adversarial samples, with a single scoring standard annotated for each sample. Scoring can combine rule-based checks with model-based review, but model-based review must use a fixed review prompt and temperature parameter; otherwise the data is not comparable.

    4. Cost and Performance Constraints

    Cost is not a matter of unit price but of token consumption per unit of business output. Costs can be significantly reduced through prompt compression, context trimming, cache reuse, and tiered routing: simple requests go to a lightweight tier, while complex requests are escalated to a higher-capability tier. The routing decision itself can be made by a lightweight classifier to avoid extra call overhead.

    1. Request -> complexity check -> cache hit? -> return directly
    2. -> miss -> lightweight tier
    3. -> low confidence -> escalate to higher-capability tier

    On the performance side, pay attention to concurrency quotas and rate-limiting strategies. Use queue buffering and exponential backoff retries to avoid widespread failures triggered by instantaneous peaks.

    5. Security, Compliance, and Observability

    Bidirectional filtering of inputs and outputs, masking of sensitive information, and prompt injection protection are all essential. Every call should retain a trace identifier to make problem investigation easier. Logs and metrics should be collected centrally into a logging service and a monitoring and alerting system, with alerts configured for abnormal outputs and sudden cost spikes.

    6. Rollout Roadmap and Cloud Support

    A four-step approach is recommended: first validate feasibility with a small sample, then build an evaluation set to lock in standards, then roll out gradually with tiered routing enabled, and finally optimize capacity and cost. The general capabilities offered by Baidu AI Cloud can cover the stages required by this pipeline, for example using a container platform to host inference services, object storage to store samples and artifacts, a message queue for asynchronous peak shaving, and logging and monitoring services for observability. The model service itself is accessed through a unified interface, making it easy to switch smoothly between capability tiers and avoid binding business code tightly to a specific implementation.