Designing a RAG Retrieval Pipeline for Cross-Border E-Commerce AI Customer Service: From Chunking to Reranking
A buyer asks "why can't this order be returned?" The AI agent either digs through the knowledge base and finds nothing, or answers with the return policy of site A to a buyer on site B — these are the two most common failure modes teams hit after launching an AI customer service bot for cross-border e-commerce. Many teams assume RAG just means "plug in a vector database," then watch accuracy stall with no idea which link in the chain is broken.
This post is the first in an experience-sharing series for AI customer service product managers and developers, drawn from hands-on practice as an AI product manager (customer service platform track) at a Southeast Asian cross-border e-commerce platform. In this post I want to share a complete RAG pipeline design — chunking, vector retrieval, keyword retrieval, hybrid recall, and reranking — for an AI agent that must answer platform policy questions, look up orders, and handle after-sales, together with how to prioritize optimization across these stages. This is essentially the first engineering problem every team building knowledge-driven AI customer service runs into.

Five Key Points in RAG Pipeline Design
- End-to-end RAG understanding: seeing document processing, embedding, recall, reranking, and answer generation as one pipeline, instead of just calling a vector search API once.
- Knowledge base design: sensible chunking, metadata, and update mechanisms for different knowledge types such as platform rules and after-sales policies.
- Retrieval optimization: where vector search, keyword search, hybrid recall, and reranking each shine — and where each falls short.
- Data-driven evaluation: a two-layer evaluation system (retrieval and generation) that localizes problems with data instead of tuning parameters by gut feeling.
- Business pragmatism: balancing answer accuracy, multilingual support, response latency, and service cost against the realities of multi-country marketplaces.
The Overall Design
In designing this pipeline, I would start from three concerns: whether the system can find the right knowledge; whether what it finds can support a correct answer; and whether the whole chain can serve real traffic stably. Here is the six-step breakdown.
Step 1: Split business scenarios first — do not throw everything at RAG
Customer service questions all look like "Q&A," but their data sources differ completely. I would split them into three categories:
- Platform policy questions: return policies, shipping rules. These go through RAG against the knowledge base.
- Real-time lookups: order and logistics status. These call order or logistics APIs directly — never let the model answer with stale knowledge-base data.
- Composite questions: "does my order qualify for a refund?" These combine knowledge retrieval with business APIs: fetch the order facts first, then reason with policy knowledge.
Skip this split and every later optimization becomes undifferentiated noise.
Step 2: Knowledge base construction and chunking
Start by running platform rules, FAQs, and after-sales manuals through unified format parsing, deduplication, cleaning, and version management. Chunking strategy must not use one-size-fits-all fixed lengths — it should follow document structure:
- FAQs are chunked as complete question-answer pairs;
- Policy documents are chunked by section, rule clause, and applicability conditions, and the rule body and its exceptions must stay in the same chunk — otherwise the model sees the rule without the exception and the answer will be wrong.
Attach metadata to every chunk: country site, language, business type, effective date, version, source. In cross-border e-commerce the same question may map to different policies per site; weak metadata filtering is exactly how "wrong country's policy" incidents happen.
Step 3: Hybrid recall — keyword plus vector
Each retrieval mode has its strength. Keyword search excels at exact matches: rule IDs, order status names, policy terminology. Vector search handles colloquial, semantically similar phrasing. When a buyer asks "why can't this order be returned," the knowledge base may literally say "refund eligibility restrictions" — pure keyword matching fails here.
So run both retrievals in parallel and merge the two candidate lists with an algorithm such as RRF (Reciprocal Rank Fusion), covering both precision and semantics.
Step 4: Rerank the candidates
Hybrid recall results are not all highly relevant to the current question. Add a reranker for second-stage scoring: recall 20–50 candidate chunks first, then after reranking pass only the top 5–10 highly relevant chunks to the LLM. How many to keep is tuned by evaluating accuracy, response latency, and call cost together — too many wastes tokens and introduces noise; too few starves the model of evidence.
Step 5: Constrain generation
Good retrieved evidence can still be ruined at the generation step:
- Require the model to answer primarily from the retrieved valid knowledge, preserving policy sources and applicability conditions where possible;
- When evidence is insufficient, never fabricate — ask a clarifying question, state plainly that the answer cannot be confirmed, or hand off to a human agent;
- For real business operations such as refunds, the system must call business systems to verify order status and permissions instead of concluding directly from knowledge.
Step 6: Build the evaluation system and set optimization priority
Evaluation runs in three layers: retrieval layer metrics like Recall@K, Precision@K, MRR; generation layer metrics like answer correctness, factual grounding, and completeness; business layer metrics like resolution rate, repeat-contact rate, human handoff rate, response time, and cost per resolution.
With layered metrics, debugging has a path: the correct knowledge never entered the candidate set — check the knowledge base, chunking, or recall; it was recalled but ranked low — optimize reranking; the evidence was provided but the answer is still wrong — inspect context organization and generation strategy.
My optimization priority: first ensure knowledge is complete, accurate, and timely → then optimize chunking and recall → then reranking → finally tune answer generation, model selection, and prompts. No algorithm can rescue bad knowledge.
How This Maps to Weiyu
The Weiyu open-source customer service system (GitHub: https://github.com/bytedesk/bytedesk , website: https://www.weiyuai.cn ) ships knowledge base and RAG capabilities that map directly onto this pipeline: it supports importing knowledge documents in multiple formats, chunking and vectorizing them into a searchable knowledge base; with omnichannel message intake, the AI agent answers from knowledge-base retrieval first; when retrieval confidence is low or the user explicitly asks, it hands off seamlessly to human agents routed by skill group, and agents can see what the AI already retrieved so users need not repeat themselves; conversation statistics and QA reports continuously expose business-layer metrics like resolution rate and handoff rate, providing the data basis for deciding which link to optimize next.
Key Takeaways
- Split scenarios before applying RAG: real-time data goes to APIs, policy knowledge to retrieval, composite questions combine both.
- Chunking respects document structure: Q&A pairs, clauses, and exception notes must not be mechanically truncated; metadata is the precondition for avoiding cross-site contamination.
- Hybrid recall + reranking is the highest-leverage retrieval combination: one path for precision, one for semantics, then a fine filter into context.
- Evaluate in three layers: retrieval, generation, and business each own their metrics — that is what makes root-cause analysis possible.
- Optimization has an order: knowledge quality always preceds algorithm tuning.
