您的位置:首页 > 手游攻略 > 用 BM25 和 DeepSeek 构建不幻觉的 AI 客服:跨境电商 82% 答率背后的架构

用 BM25 和 DeepSeek 构建不幻觉的 AI 客服:跨境电商 82% 答率背后的架构

作者:互联网  时间: 2026-07-24 07:13:02  

六周前,我收到 Gorgias 的 $300 账单——他们的 AI 客服自信地告诉我的客户一个根本不存在的退货政策。那一刻我决定自己写一个 AI 客服:不幻觉、可解释、成本可控

用 BM25 + DeepSeek 构建不幻觉的 AI 客服:跨境电商 82% 答率背后的架构

2026 年 AI 客服的三个致命问题

  1. 幻觉:GPT-4 + system prompt = 自信地编造政策。商家最大的痛点。
  2. 成本:按 ticket 收费,viral 产品能把客服成本打爆。
  3. 语言:跨境电商需要 7+ 语言,建 7 个 KB 不现实。

架构

客户提问
  ↓
[BM25 检索] ← 知识库(产品页 chunks)
  ↓
Top-K 相关 chunks + 分数
  ↓
[置信度检查] → 分数太低?→ "我不确定,转人工"
  ↓
[LLM 生成] ← "只根据上下文回答"
  ↓
回答(基于真实产品数据)

关键技术决策

1. BM25 而非 embeddings(针对产品页)

产品页 = 短、结构化、关键词密集。BM25 在这种场景下:

  • 零依赖(不需要 sentence-transformers / 向量数据库)
  • CPU 运行(不需要 GPU)
  • 10x 快(短页面检索)
  • 确定性(同 query 同结果)
  • 成本 $0

Pinecone 起步 $70/月,对早期独立开发者是负担。

2. 置信度评分(反幻觉核心)

def should_answer(retrieved):
    if not retrieved:
        return False  # 无相关上下文
    top1 = retrieved[0][1]
    if top1 < MIN_TOP_SCORE:  # 阈值 1.0
        return False  # 最佳匹配太弱
    if len(retrieved) >= 2:
        gap = retrieved[0][1] - retrieved[1][1]
        if gap < SCORE_GAP_THRESHOLD:  # 阈值 0.5
            return False  # 多个弱匹配 = 歧义
    return True

如果 should_answer 返回 False,AI 说:

"I am not confident I know the answer to that. Let me connect you with a human agent who can help."

这是商家最需要的功能。 他们不要 AI 永远正确——他们要 AI 知道什么时候自己错了。置信度评分比回答质量更重要。

3. Grounded generation(不自由发挥)

只有当置信度高时 LLM 才介入:

system_prompt = (
    "You are a customer support agent. "
    "Answer the customer question using ONLY the information in the "
    "## Product Information section below. "
    "If the answer is not in the product information, say "
    "I am not sure, let me connect you to a human agent. "
    "Do not invent policies, shipping times, or return rules."
)

LLM(DeepSeek,OpenAI 兼容)温度 0.3(低创造性,高忠实度)。每对话 $0.003(DeepSeek)vs $0.50+(GPT-4),是 1/170。

4. 查询时翻译(1 KB → 7 语言)

# 客户用中文问,KB 是英文
translated = await translate_query("你们的退货政策是什么?", target_lang="en")
# → "What is your return policy?"

# 用翻译后的 query 搜英文 KB
results = index.search(translated, top_k=4)

# 用英文生成答案,再翻译回中文
answer_en = await llm_generate(results, translated)
answer_zh = await translate_query(answer_en, target_lang="zh")

支持 7 种语言(en/zh/ja/fr/de/es/ko)。一个 KB,不重复造轮子。

实测数据(8 个 Shopify 商家)

商家类型答率备注
Allbirds鞋类71%跨语言 zh→en
Kith街头100%CNY 变体复杂库存
Cascadia Roasters订阅83%暂停/跳过/烘焙度
Peak Design摄影100%丰富 JSON-LD
Loop Earplugs健康88%选哪款
Beardbrand美妆50%其余正确转人工
平均 82%跨语言

那 18% 没答的?正确转人工,不编造。

我学到的

  1. BM25 > embeddings(产品页场景)。产品页短、结构化、关键词密集,BM25 更快更便宜更确定性。
  2. "I do not know" 是功能不是 bug。商家要 AI 知道什么时候自己错,置信度比答案质量重要。
  3. 查询时翻译 > 7 个 KB。一个 KB + 查询时翻译 = 7x 便宜 + 同等准确。
  4. Flat pricing > per-ticket。按 ticket 收费惩罚成功,flat $49/月让商家敢用。

技术栈

  • Python + FastAPI
  • 自实现 BM25(无依赖)
  • DeepSeek API(OpenAI 兼容)
  • httpx + BeautifulSoup
  • 无向量数据库 / 无 GPU

试用

  • Demo(30 秒,无需注册):https://ling-support.com/try
  • 免费 FAQ 生成器:https://ling-support.com/tools/faq-generator
  • 定价:$49/月 flat,无 per-ticket 费

前 10 个订阅者 50% off forever ($24.5/月),用码 EARLY10。


Building in public. Day 47/90. 8 个商家,0 个付费用户,但架构稳定 funnel 打开. 在评论里问我任何问题。

最新游戏

更多

Copyright©2010-2019. All rights reserved | 波波三国游戏官网|[email protected]

备案编号:湘ICP备2022015115号-4