Evaluating and Optimizing LLM Accuracy for Knowledge Q&A
This article presents a practical framework for evaluating and improving the accuracy of large language models (LLMs) on knowledge-based question answering. It explains why identical questions can produce widely different answers, introduces a five-dimension scoring rubric covering knowledge coverage, concept disambiguation, traceability, structure, and user-facing tone, and outlines four common failure modes. It then details three optimization paths: an observable RAG pipeline, explicit prompt and output contracts, and automated regression testing, showing how teams can turn subjective experience gaps into measurable, improvable metrics.
1. Background: Why the Same Question Gets Very Different Answers
In model selection and quality evaluation, a common pattern appears: when the same knowledge question is given to several LLMs, the results differ noticeably in completeness, structure, and naturalness of expression. The original case used the question “Which emperors had ‘Wu’ as their core posthumous name?” This type of question is characterized by a fuzzy boundary around the answer set, the presence of posthumous honors that were granted or revised later, easy confusion with temple names, and heavy dependence on the context of Chinese historical sources.
Such questions make good evaluation samples because they test four capabilities at once: knowledge coverage, concept disambiguation, retrieval and traceability, and the ability to organize content for the user. The four types of differences below are abstracted into quantifiable evaluation dimensions.
2. Designing Evaluation Dimensions: Turning Subjective Experience into Scores
A five-dimension scoring table is recommended, with each dimension scored from 0 to 5 and combined as a weighted sum:
| Dimension | Focus | Typical Deductions |
|---|---|---|
| Knowledge coverage | Whether the answer set is complete | Missing key entries |
| Concept disambiguation | Whether similar concepts are distinguished | Treating a temple name as a posthumous name |
| Retrieval and traceability | Whether sources are provided | No citations, cannot be verified |
| Structure | Whether there is a definition, list, and summary | Only a single flat block of text |
| User-facing tone | Whether it addresses the user rather than internal monologue | Exposing internal reasoning |
Sample scoring code:
WEIGHTS = {"coverage": 0.3, "concept": 0.25,"trace": 0.2, "structure": 0.15, "persona": 0.1}def score(resp: dict) -> float:return round(sum(resp[k] * w for k, w in WEIGHTS.items()), 2)sample = {"coverage": 4, "concept": 5, "trace": 4,"structure": 4, "persona": 5}print(score(sample)) # 4.35
3. Four Typical Failure Modes
The first is incomplete coverage. Most models produce the main entries but miss items from periods of frequent regime change, because these entries appear infrequently in training data and retrieval recall is insufficient.
The second is concept confusion. Posthumous names, temple names, and era names are three distinct systems. Without constraints, some models fold temple names such as “X-zong” or “X-zu” into the posthumous name list, creating factual errors.
The third is imbalanced retrieval style. Some answers resemble an “enhanced search engine,” listing information completely but lacking a defining preamble and a closing summary; others are the opposite, with polished structure but hollow content.
The fourth is leaked internal monologue. The model outputs its self-correction and self-justification directly to the user, and content the user already stated is explained again, degrading the reading experience. This is essentially a lack of dialogue state management rather than a lack of knowledge.
4. Optimization Path 1: An Engineering Pipeline for RAG
To reliably improve coverage and verifiability, retrieval-augmented generation should be broken into an observable pipeline:
Query rewriting → Multi-route recall → Reranking → Evidence trimming → Generation → Validation → Archiving
Key engineering points include: query rewriting should fill in implicit qualifiers; the recall stage should use a multi-route strategy to reduce single-source bias; the reranking stage should prioritize authoritative historical texts; evidence trimming should control context length to control cost; and the validation stage should check entity and concept consistency. In Baidu AI Cloud’s general technology stack, this pipeline typically uses object storage to hold the corpus, a message queue to decouple recall tasks, a container platform to host inference services, and logging plus monitoring and alerting for quality tracking.
5. Optimization Path 2: Prompt and Output Contract Constraints
Writing the output format as an explicit contract can significantly improve structure and user-facing tone:
Role: A rigorous historical knowledge assistantSteps: 1) Define core concepts first; 2) then give a list; 3) finally explain differencesConstraints: Do not output internal reasoning; do not count temple names as posthumous names; give a source for each entryFormat: Definition paragraph + table + summary paragraph
A refusal and clarification strategy should also be set: when the question itself mixes concepts, ask a clarifying question first instead of answering along with the false premise.
6. Optimization Path 3: Automated Validation and Regression Evaluation
Manual spot checks cannot cover the long tail, so a regression set is needed. The approach is to fix historical Q&A into a case set, automatically re-score after every model or prompt change, and track factual errors separately. Example:
CASES = [{"q": "Which emperors had 'Wu' as their core posthumous name", "must": ["definition", "table"],"forbid": ["temple names mixed in"]}]def regression(model, cases):bad = []for c in cases:out = model(c["q"])if any(f in out for f in c["forbid"]):bad.append(c["q"])return {"total": len(cases), "failed": len(bad)}
7. Conclusion
The gap between models on knowledge Q&A comes mainly not from parameter scale but from the engineering coordination of three things: retrieval quality, concept constraints, and output contracts. Teams are advised to use the five-dimension scoring table as a baseline, first completing the retrieval and validation stages, then optimizing the expression layer. For enterprise-level deployment, an observable and regression-testable Q&A pipeline can be built on Baidu AI Cloud’s general model services and knowledge base retrieval solutions, turning “experience differences” into quantifiable metrics that can be improved continuously.
