Diagnose issues stage-by-stage across the RAG pipeline and apply targeted improvements to systematically enhance retrieval and response quality
- Indexing: Document parsing, chunking, and vectorization
- Retrieval: Matching and retrieving relevant chunks from the index based on a query
- Generation: The LLM generating the final answer using both the retrieved content and the query
Step 1: Establish an Evaluation Baseline
Before optimizing, define a quantifiable evaluation framework—otherwise, you cannot objectively assess whether improvements are effective.
Build an Evaluation Dataset
Prepare at least 100 test cases, each containing a question and its expected answer. Ensure coverage across the following types:
| Type | Example |
|---|---|
| Factual | "What is the warranty period for Product X?" |
| Comparative | "Compare the key differences between Product X and Product Y." |
| Tutorial | "How do I install Product X?" |
| Analytical | "Why has Product X’s sales increased over the past three months?" |
Run the Baseline Test
Execute the full evaluation set once using either the Q&A service’s debugging console or the chat API. Record both the retrieved chunks and the generated responses for every test case. This report serves as your reference baseline for all subsequent optimizations.
Step 2: Diagnosis and Remediation
Analyze underperforming test cases in the baseline report one by one, categorize the issue, and apply the appropriate solution below.
2.1 Failed Retrieval: Relevant Knowledge Exists but Is Not Retrieved
The knowledge exists in the knowledge base, yet the retrieval system fails to match it.
Augment Knowledge Base Content
Augment Knowledge Base Content
Optimize Source Document Content and Formatting
Optimize Source Document Content and Formatting
- Using clear, hierarchical headings and well-structured content
- Removing watermarks
- Avoiding complex tables with merged or cross-page cells
- Preferring Markdown format; for PDF/DOCX files, convert them to Markdown before ingestion
Align Query Language with Source Language
Align Query Language with Source Language
Resolve Entity Ambiguity
Resolve Entity Ambiguity
You can feed documents to an LLM to assist with terminology standardization. For long documents, split them into smaller segments first and process each segment individually.
Enable Query Rewriting
Enable Query Rewriting
phone X1 → rewritten as Please provide all currently available versions of phone X1 and their specifications from the product catalog.Enable the Query Rewriting toggle in the knowledge base-specific configuration section of either Knowledge Retrieval or Knowledge Q&A.2.2 Failed Retrieval: Irrelevant Chunks Are Retrieved
Relevant knowledge exists in the knowledge base, but irrelevant chunks are retrieved instead.
Apply Tag-Based Filtering
Apply Tag-Based Filtering
- During Import: Add tags in Step 3 of Data Upload
- After Import: Click “More” → “Tags” in the document list
- Configure Tag Filtering in the knowledge base-specific settings of Knowledge Retrieval or Knowledge Q&A
- Specify
tagsin the request payload when calling via API
Enable Metadata Extraction
Enable Metadata Extraction
- Extract metadata from the query (e.g.,
{"key": "name", "value": "phone X1"}) - Filter chunks that contain matching metadata values
- Perform vector search only on the filtered subset
2.3 Suboptimal Chunking
Inappropriate chunking leads to the following issues:
| Issue | Manifestation | Impact |
|---|---|---|
| Chunks too short | Each chunk contains only one sentence, lacking context | Retrieval fails to match semantically relevant content |
| Chunks too long | A single chunk mixes multiple topics | Retrieval returns excessive irrelevant content |
| Semantic truncation | Chunks are forcibly cut mid-sentence | Retrieved content is incomplete or malformed |
Adopt Smart Chunking Strategy
Adopt Smart Chunking Strategy
- First, the system splits documents into paragraphs using built-in sentence delimiters
- Then, it determines optimal chunk boundaries based on inter-paragraph semantic similarity
Manually Review and Correct Chunks
Manually Review and Correct Chunks
%20). After import, manually spot-check chunk quality.Navigate to the Chunk Details tab in the knowledge base detail page to view all chunks. Edit and correct problematic ones directly—the updated chunks take effect immediately for retrieval.Corrections affect only indexed chunks—not original source documents. Re-imported documents require re-inspection.
Manually Add or Remove Chunks
Manually Add or Remove Chunks
- Add Chunk: Insert missing critical information or additional context. Must be associated with an existing document; max length: 6000 characters
- Delete Chunk: Remove erroneous or duplicate chunks—other chunks in the same document remain unaffected
2.4 Poor Re-Ranking
Relevant chunks are retrieved—but poorly ranked, resulting in suboptimal final output.
Adjust Similarity Threshold
Adjust Similarity Threshold
- Too high: May discard all relevant chunks, leaving the LLM under-informed
- Too low: May retrieve many low-relevance chunks, introducing noise
Increase Maximum Retrieval Count
Increase Maximum Retrieval Count
Select Ranking Model and Mode
Select Ranking Model and Mode
| Mode | Use Case |
|---|---|
| Q&A Mode (default) | User asks a complete question expecting direct answers from chunks |
| Similarity Mode | Query and chunk phrasing styles align closely (e.g., searching historical records or policy clauses) |
| Custom Advanced Mode | Specialized ranking logic required (e.g., “prioritize content from the last 12 months”) |
- Per-Knowledge-Base Configuration: Expand the knowledge base panel in retrieval or Q&A services to select model and mode
- Global Reranking Model: Configure once in Knowledge Retrieval to apply uniformly across all bound knowledge bases
2.5 LLM Misunderstanding
Correct chunks are retrieved—but the LLM generates inaccurate or incomplete answers.
Switch Generation Models
Switch Generation Models
| Scenario | Recommended Model |
|---|---|
| Simple fact lookup & summarization | Smaller-parameter models (e.g., qwen3-flash) |
| Complex logical reasoning | Larger-parameter models (e.g., qwen3-max) |
| Heavy reliance on many retrieved chunks | Models with longer context windows |
Optimize Prompt Engineering
Optimize Prompt Engineering
---, <|context|>) to improve LLM structural understanding.Enable Refusal Policy
Enable Refusal Policy
Tune Model Parameters
Tune Model Parameters
- Higher values: Increase output diversity—ideal for creative writing or brainstorming
- Lower values: Increase output determinism—ideal for factual queries or technical documentation
2.6 Multi-Knowledge-Base Optimization
When binding multiple knowledge bases, apply these strategies to improve joint retrieval effectiveness:
| Strategy | Description |
|---|---|
| Set Knowledge Base Weight/Priority | Assign higher weights or priority to core knowledge bases so their results dominate final ranking |
| Enable Knowledge Base Routing | System automatically routes queries to relevant knowledge bases based on intent—reducing noise from irrelevant sources. Configure in Knowledge Retrieval |
| Choose Reranking Mode | Q&A mode suits QA scenarios; Similarity mode fits semantic paragraph search; Custom Advanced mode supports specialized sorting logic |
Step 3: Continuous Iteration
After each configuration change:
- Re-run Evaluation: Execute the same evaluation set to quantify improvement
- Compare & Analyze: Contrast results against the baseline—confirm which issues were resolved and whether new regressions emerged
- Expand Test Coverage: Add newly discovered production failures (“bad cases”) to your evaluation set to broaden coverage