Evaluating and Selecting Large Language Models: A Practical Engineering Guide
This article breaks down large language model selection as an engineering problem rather than a ranking exercise. It defines measurable evaluation dimensions across code generation, mathematical and logical reasoning, multimodal generation, retrieval-augmented generation, and Chinese processing, then outlines a scenario-based selection strategy, cost control through routing and caching, and stability practices such as multi-provider abstraction, canary releases, observability, and data governance. It also lists common pitfalls and shows how to build a repeatable evaluation and rollout workflow.
1. Background: Why Model Selection Became an Engineering Problem
Over the past two years, the capability boundaries of large language models have advanced rapidly. The market now offers general-purpose chat models, programming-focused models, and model families with multimodal generation capabilities. For developers, the real challenge is no longer whether a model can be called, but how to balance capability, cost, stability, and compliance.
From an engineering perspective, model selection must answer four questions at the same time:
- Task fit: whether the model reliably meets the bar in your core scenarios, such as code completion, long-form writing, mathematical derivation, and image or text generation;
- Unit cost: subscription or usage-based pricing, plus rework cost, since a low first-pass success rate significantly increases total spend;
- Engineering controllability: whether programmable interfaces, structured output, canary releases, and rollbacks are supported;
- Risk and compliance: whether content safety policies, data retention policies, service availability, and account risk-control policies are acceptable.
Any “overall ranking” should be treated only as a reference. Reliable conclusions come from your own evaluation set and production canary data.
2. Breaking Down Capability Dimensions: Turning Impressions into Measurable Metrics
2.1 Code Generation and Engineering Usability
Evaluating code capability requires more than checking whether a model can produce an example. Look at:
- First-pass rate: the proportion of generated code that passes tests without manual modification, given the requirement and context;
- Context utilization: whether cross-file dependencies, interfaces, and type definitions are referenced correctly;
- Constraint adherence: whether naming conventions, exception handling policies, and dependency version limits are strictly followed.
In practice, build an internal case set of 30 to 100 items covering CRUD, concurrency control, cache consistency, unit test generation, and refactoring. A sample evaluation skeleton:
cases = [{"prompt": "Implement an HTTP client with retry and backoff", "tests": ["test_retry", "test_timeout"]},{"prompt": "Rewrite callback-style code as async", "tests": ["test_order_preserved"]},]def evaluate(model_client, cases):report = []for c in cases:code = model_client.generate(c["prompt"])passed = run_tests(code, c["tests"])report.append({"case": c["prompt"], "pass": passed})return report
The practical pattern is that stronger models tend to perform better on detail-level rigor, while mid-tier models often require repeated rework on moderately complex tasks, making total cost higher.
2.2 Mathematical and Logical Reasoning
Math and logic tasks demand high reasoning stability. Evaluation should separate:
- Accuracy of arithmetic and algebraic derivation;
- Chain completeness in multi-step reasoning;
- Response latency for the same question.
The engineering recommendation is to hand critical computation to deterministic tools such as symbolic math libraries or rule engines, leaving the model responsible for problem modeling and result explanation. This “model plus tool” hybrid architecture avoids placing numerical precision entirely on a generative model.
2.3 Multimodal Generation
Image and video generation have reached practical use, but engineering adoption depends on:
- Controllability of output, including composition, style, duration, and resolution constraints;
- Integration with business systems through asynchronous tasks, callback notifications, and object storage for artifacts;
- Content safety and copyright risk management.
The recommended architecture submits generation tasks from the business service to a message queue, has an asynchronous consumer invoke the generation capability, writes artifacts to object storage, and tracks success rate and latency through logging and monitoring alerts.
2.4 Retrieval-Augmented Generation and Knowledge Base Q&A
Retrieval-augmented generation (RAG) is almost the standard approach for answering from private knowledge. Core stages include document parsing, chunking strategy, vectorization, retrieval and reranking, and answer constraints. Evaluation focuses on:
- Retrieval hit rate and context relevance;
- Citation traceability;
- Refusal rate when no answer exists.
A minimal retrieval example:
def answer(query, retriever, llm):docs = retriever.search(query, top_k=5)if not docs:return "No supporting evidence found in the knowledge base."context = "\n".join(d.text for d in docs)prompt = f"Answer only based on the following material and cite sources:\n{context}\n\nQuestion: {query}"return llm.generate(prompt)
2.5 Chinese Processing and Translation Quality
Chinese scenarios require extra attention to terminology consistency, concision, and English correctness. Common problems include Chinglish in translated drafts, inconsistent terminology, and punctuation misuse. A two-stage pipeline works well: a rigor-oriented model produces the first draft, a model with stronger creative and language feel polishes it, and the prompt states explicit prohibitions:
Requirements:1. Terminology must be strictly consistent with the glossary;2. Do not use em dashes or exclamation marks;3. Keep output concise and remove redundant modifiers.
3. Layered Selection Strategy: By Scenario, Not by Ranking
- High-rigor batch processing (contract review, report explanation, code review): prefer models that rarely make detail errors, combined with rule-based validation;
- Creative work and code refactoring (copywriting, concept design, complex refactoring): choose a tier with stronger expression and reasoning, accepting higher cost;
- Mathematical and structured derivation: the model handles modeling, tools handle computation;
- Real-time trending and public opinion verification: connect a solution with real-time retrieval and keep human review;
- High-frequency lightweight daily tasks: a low-cost or even free general-purpose option is enough, with effort focused on prompt templates and caching.
For cost control, introduce semantic caching, result reuse, and tiered routing: simple requests go to small models, complex requests escalate to large models.
4. Stability and Engineering Governance
Enterprise adoption must account for service volatility. Recommended practices:
- Multi-provider abstraction layer: a unified interface that hides differences and supports one-click switching;
- Canary and shadow traffic: validate new models with a small traffic share first;
- Full-chain observability: record prompt version, model version, latency, and success rate;
- Data governance: define which data may leave the boundary, and route sensitive scenarios to private deployment or masking.
Request -> Routing layer -> [Primary model | Fallback model]|-> Semantic cache|-> Audit and masking|-> Metrics reporting
5. Common Pitfalls
- Reading leaderboards instead of your own evaluation set;
- Ignoring rework cost, which raises total cost;
- Handing numerical computation entirely to a generative model;
- Adding no constraints in prompts, causing format and terminology drift;
- Depending on a single service with no fallback plan.
6. Conclusion
General and specialized models each have strengths across code, math, multimodal, retrieval, and Chinese processing, and no single option is best for every scenario. Developers should combine scenario layering, metric-based evaluation, a switchable architecture, and cost governance. To get started quickly, you can build an evaluation and canary system on general capabilities such as the container platform, object storage, message queue, logging, and monitoring alerts offered by Baidu AI Cloud, turning model selection from subjective judgment into a continuously optimizable engineering process.
