多语言客服机器人:东南亚市场实战
基于 RAG 架构 + Qwen2.5-72B 构建东南亚三语(英/泰/越)客服机器人,支持 Shopify 订单查询、退货政策解答、尺码推荐,日均处理 2000+ 对话。
项目背景
东南亚电商市场有三个显著特点:多语言(英语 + 泰语 + 越南语)、客服人力成本低但流动性高、消费者习惯用 Facebook Messenger 而非邮件。这带来一个机会——用 LLM 做一线客服,把复杂问题留给人工。
本项目为一家主攻泰国、越南市场的独立站卖家构建了三语客服机器人,接入 Shopify 店铺,绑定订单查询、退货政策、尺码推荐三个高频场景。机器人日均处理 2000+ 对话,人工客服工作量下降 60%。
技术架构
整体采用 RAG(Retrieval-Augmented Generation)架构:用户问题进来后,先用 Embedding 模型匹配知识库中最相关的文档片段,再将片段注入 LLM 的上下文进行生成。Shopify API 提供实时订单数据,LLM 只负责自然语言理解和生成。
from supabase import create_client
from sentence_transformers import SentenceTransformer
import openai
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12')
openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
SYSTEM_PROMPT = """You are a helpful customer service agent for a cross-border fashion store.
Answer in the same language as the user query.
Only answer based on the provided context. If you don't know, say "I don't know".
"""
def retrieve_context(question: str, top_k: int = 3):
q_vec = model.encode(question).tolist()
result = supabase.rpc(
'match_docs', {'query_embedding': q_vec, 'match_count': top_k}
).execute()
return '\n'.join([r['content'] for r in result.data])
def chat(question: str, order_info: dict = None):
context = retrieve_context(question)
user_msg = f"Order info: {order_info}\n\nQuestion: {question}" if order_info else question
response = openai_client.chat.completions.create(
model='qwen2.5-72b',
messages=[
{'role': 'system', 'content': SYSTEM_PROMPT + '\nContext:\n' + context},
{'role': 'user', 'content': user_msg},
],
temperature=0.3,
)
return response.choices[0].message.content
print(chat('How do I return items ordered on May 20th?'))核心代码
RAG 的核心是知识库构建与检索质量。本系统把 FAQ、退货政策、尺码表、产品描述全部切成 300-500字的 chunks,用多语言模型 Embedding 后存入向量库。检索时控制 `match_threshold=0.7` 过滤噪音。
from supabase import create_client
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
def add_doc(collection: str, title: str, content: str, metadata: dict):
return supabase.table(collection).insert({
'title': title,
'content': content,
'metadata': metadata,
}).execute()
def query_with_filter(question: str, lang: str, top_k: int = 3):
q_vec = model.encode(question).tolist()
result = supabase.rpc(
'match_docs_filtered',
{
'query_embedding': q_vec,
'lang': lang,
'match_count': top_k,
'match_threshold': 0.7,
}
).execute()
return result.data
# 泰语用户查询退货政策
results = query_with_filter('นโยบายการคืนสินค้า', lang='th', top_k=3)
print(f"Retrieved {len(results)} docs for Thai return policy query")关键指标
· 首次响应时间:P50 < 1.2s(含向量检索 + LLM 推理)
· 答案准确率:人工抽检 500 条对话,准确率 91.3%
· 多语言切换:英/泰/越三语混合对话支持率 100%
· 人工介入率:需要人工处理的对话占比 18%,主要在退货纠纷和投诉场景
越南语特殊处理:越南语分词器质量参差不齐,遇到长句时检索召回率明显低于泰语。建议对越南语知识库额外做同义词扩展,Embed 前先用 VNI 字符标准化处理。