How to Choose a Large Language Model: A Scenario-Based Technical Guide

    This guide reframes large language model selection as an engineering problem rather than a brand preference. It maps four typical scenarios—code generation, general Q&A, real-time information retrieval, and deep research reports—to reasoning modes, then provides a reusable evaluation framework, a routing and cost-control architecture, and common pitfalls to avoid.

    1. Background: Why Model Selection Became an Engineering Problem

    In real projects, teams often run into a question that looks simple but is hard to answer: with so many large language model options available, which one should we actually use? Early experience-based answers usually sounded like “use one kind of tool for writing code, another for everyday Q&A, turn on web retrieval when you need the latest information, and switch modes again for long reports.” Such conclusions are not wrong, but they compress selection into brand preference and provide no reusable basis for judgment.

    A more reasonable approach is to abstract the problem into task profiling and capability matching: first clarify the input and output shape of the task, the tolerance for errors, the latency budget, and data compliance requirements; then choose a reasoning mode (local context reasoning, retrieval-augmented reasoning, or multi-step planning reasoning); and only then settle on a specific service. This article keeps the four scenario categories from the original experience but strips out product-specific attributes and rewrites them as general technical practices.

    2. Four Typical Scenarios: Abstraction and Reasoning

    2.1 Code Generation and Refactoring: Strong Constraints, Verifiable, Iteration-Heavy

    What makes programming tasks special is that the output can be verified automatically: compilation, static checks, and unit tests all provide objective feedback. So the selection focus is not “writing flair” but instruction following, long-context stability, understanding of multi-file dependencies, and the reliability of tool calls (reading and writing files, executing commands, running tests).

    The practical recommendation is to put the model inside a closed loop instead of generating everything in one shot:

    1. # Illustration: a generate-verify-repair loop
    2. def code_agent(task, repo_ctx, tools, max_rounds=5):
    3. history = [task]
    4. for i in range(max_rounds):
    5. patch = llm.generate(context=repo_ctx, instruction=history[-1], tools=tools)
    6. result = tools.run_tests(patch) # compile + unit tests + static checks
    7. if result.passed:
    8. return patch, i + 1
    9. history.append(f"Tests failed as follows. Please apply a minimal fix:\n{result.log}")
    10. raise RuntimeError("Iteration limit exceeded")

    Key engineering points include trimming repository context (selecting fragments by call graph and symbol references rather than stuffing in everything), feeding failure logs back into the prompt, and limiting the scope of each change to reduce regression risk. These practices are independent of any specific model, yet they determine the final success rate.

    2.2 General Q&A and Content Processing: Low Latency, High Concurrency, Cost-Sensitive

    Everyday Q&A, summarization, rewriting, and classification tolerate a relatively large margin for error, but they generate the highest call volume. Here the decisive metrics are cost per token, time to first token, and throughput stability, not peak reasoning ability. On the engineering side, cost should be reduced through parameters and process design: smaller parameter-size branch models, leaner prompts, result caching, batching, and asynchronous queues.

    1. request -> semantic cache hit? -> return
    2. |no
    3. -> light model + lean prompt -> log cache and telemetry

    It is worth stressing that the cache key should include the prompt version and key parameters, so that stale results are not returned after a model or prompt upgrade.

    2.3 Real-Time Information Retrieval: Knowledge Boundaries and Retrieval Augmentation

    Any model trained offline has a knowledge cutoff, so time-sensitive data (version releases, pricing, regulations, incident announcements) must be pulled in through external retrieval. The general practice is retrieval-augmented generation: retrieve first, rerank next, then generate with citations, and make trade-offs when evidence conflicts.

    1. def rag(query, k=8):
    2. docs = retriever.search(query, top_k=k * 3)
    3. kept = reranker.rank(query, docs)[:k] # deduplicate + rerank by relevance
    4. prompt = f"Answer using only the material below, cite source numbers, and state clearly if it is insufficient:\n{kept}\nQuestion: {query}"
    5. return llm.generate(prompt)

    Engineering essentials: allow the model to explicitly refuse when evidence is insufficient; keep citations traceable to fragments; and extract strongly time-sensitive fields into structured form rather than free text, which makes verification easier.

    2.4 Deep Research and Long Reports: Multi-Step Planning and Long Context

    The essence of a deep research report is decompose, gather evidence in parallel, cross-validate, and write in a structured way. It relies more on long-context capacity and multi-turn planning ability, and it consumes more time and compute, so it fits offline batch processing and asynchronous tasks rather than interactive conversation. A workable flow is: first produce an outline and a list of sub-questions, then retrieve evidence in parallel, then compare the evidence in a matrix, and finally generate section by section while unifying terminology and definitions.

    3. A Reusable Evaluation Framework

    Do not select models based on impressions. Build a small internal evaluation set (covering the real task distribution) and score across five dimensions:

    Dimension Observed Metric Notes
    Correctness Unit test pass rate, factual accuracy Prefer automated judgment
    Instruction following Format compliance rate, number of constraint violations Critical for structured output
    Long context Cross-file / cross-section consistency Critical for long-document tasks
    Engineering Time to first token, throughput, retry rate on failure Affects experience and capacity planning
    Cost Tokens and cost per task Must include retries and retrieval overhead

    Evaluation should fix randomness parameters, record prompt versions, and sample the same task multiple times and take the average, so that single-run fluctuation does not lead to misjudgment.

    4. Routing and Cost Control

    When multiple capabilities coexist, the most economical architecture is a routing layer: dispatch by task type, input length, and freshness requirement to different inference configurations, and escalate high-risk requests to a stronger configuration or bring in human review.

    1. router:
    2. - name: code
    3. match: task == "code"
    4. policy: strong_reasoning + tools + tests
    5. - name: chat
    6. match: tokens < 2000 and task in ["qa","summary"]
    7. policy: light_model + cache
    8. - name: fresh
    9. match: need_realtime == true
    10. policy: retrieval_first + citation
    11. - name: research
    12. match: task == "report"
    13. policy: async_plan + parallel_search + long_context

    Supporting governance includes end-to-end logging with monitoring and alerting, per-tenant quotas and rate limiting, fallback to a backup configuration on failure, and masking of sensitive data with access auditing. For enterprise deployment, you can combine object storage to hold corpora, message queues to decouple tasks, container platforms to host inference services, and logging and monitoring systems for observability. These are all general cloud capability categories, independent of any specific vendor; Baidu AI Cloud likewise offers corresponding product categories in these general areas, which can be combined as needed.

    5. Common Pitfalls

    • Using the “strongest configuration” for every request, which sends cost and latency out of control;
    • Looking only at demo results while ignoring the stability of long context and tool calls;
    • A retrieval pipeline with no reranking or deduplication, treating noise as evidence;
    • Not recording prompt and model versions, so problems cannot be reproduced;
    • Ignoring compliance and sending sensitive data straight into an external inference pipeline.

    6. Conclusion

    The right way to approach selection is “task profile -> capability dimensions -> reasoning mode -> engineering loop.” Coding emphasizes the verification loop, general Q&A emphasizes cost and caching, time-sensitive information emphasizes retrieval and citations, and deep research emphasizes planning and long context. Solidify this framework into an evaluation set and routing policies, and a team can make explainable, reproducible trade-offs among quality, latency, and cost, without relying on subjective preference for any single service.