一、Query Analysis 是什么
👉 Query Analysis(输入分析层)
= AI对“用户一句话”的拆解 + 理解 + 结构化
一句话总结:
把自然语言 → 转成机器可用的数据结构
⚙️ 二、核心处理流程(5步)
↓
文本预处理
↓
关键词/实体提取
↓
语义理解(意图识别)
↓
结构化输出(供后续模块使用)
🔍 三、模块拆解(工程级)
1️⃣ 文本预处理(Preprocessing)
目标:清洗输入,让AI更容易理解
处理内容:
- 小写化(Lowercase)
- 去标点
- 拼写纠正
- 同义词归一
示例:
→ “buy pens wholesale”
2️⃣ 分词(Tokenization)
把句子拆成最小单位:
→ [“buy”, “pens”, “wholesale”, “USA”]
3️⃣ 关键词提取(Keyword Extraction)
提取“有价值的词”:
pens → 产品
wholesale → 批发
USA → 地区
👉 常见方法:
- TF-IDF
- TextRank
- embedding语义提取
4️⃣ 实体识别(NER)
识别结构化对象:
| 类型 | 示例 |
|---|---|
| 产品 | pens |
| 地点 | USA / Ohio |
| 数量 | bulk / 1000 pcs |
| 人群 | shop / students |
输出:
“product”: “pens”,
“location”: “USA”,
“quantity”: “bulk”
}
5️⃣ 意图识别(Intent Detection)
👉 这是最核心模块
识别用户“想干什么”:
| 关键词 | 意图 |
|---|---|
| buy / supplier | 采购 |
| best / top | 推荐 |
| cheap / discount | 价格敏感 |
| compare / vs | 对比 |
输出:
“intent”: “B2B_purchase”
}
6️⃣ 修饰词识别(Modifier Detection)
识别影响决策的词:
| 类型 | 示例 | 含义 |
|---|---|---|
| 价格 | cheap | 价格敏感 |
| 质量 | best quality | 高端 |
| 功能 | waterproof | 产品需求 |
| 时间 | fast shipping | 紧急需求 |
7️⃣ 语境补全(Context Enrichment)
当信息不完整时,AI推断:
- “supplier” → 默认B2B
- “bulk” → 批量采购
- “for my shop” → 零售商
🧩 四、最终结构化输出(核心)
👉 Query Analysis的最终目标:
“product”: “pens”,
“intent”: “B2B_purchase”,
“persona_hint”: “bulk_buyer”,
“location”: “USA”,
“price_sensitivity”: true,
“modifiers”: [“wholesale”, “cheap”],
“confidence”: 0.87
}
🚀 五、TSPR-AI工程实现(PHP示例)
核心入口
function query_analysis($query){
$clean = preprocess($query);
$tokens = tokenize($clean);
$keywords = extract_keywords($tokens);
$entities = extract_entities($tokens);
$intent = detect_intent($keywords);
$modifiers = detect_modifiers($keywords);
return [
‘product’ => $entities[‘product’] ?? null,
‘intent’ => $intent,
‘location’ => $entities[‘location’] ?? null,
‘modifiers’ => $modifiers,
‘persona_hint’ => infer_persona($intent, $modifiers),
‘confidence’ => score_confidence($query)
];
}
意图识别函数
function detect_intent($keywords){
if (in_array(“wholesale”, $keywords) || in_array(“supplier”, $keywords)){
return “B2B_purchase”;
}
if (in_array(“best”, $keywords)){
return “comparison”;
}
if (in_array(“cheap”, $keywords)){
return “price_sensitive”;
}
return “general”;
}
Persona推断
function infer_persona($intent, $modifiers){
if ($intent == “B2B_purchase”){
return “Bulk Buyer”;
}
if (in_array(“cheap”, $modifiers)){
return “Price Sensitive Buyer”;
}
return “General User”;
}
🧠 六、典型案例(你的业务场景)
输入:
Query Analysis输出:
“product”: “pens”,
“intent”: “B2B_purchase”,
“persona_hint”: “Bulk Buyer”,
“location”: “Ohio”,
“price_sensitivity”: true,
“modifiers”: [“cheap”, “bulk”],
“confidence”: 0.92
}
🔥 七、核心价值(重点)
Query Analysis决定了:
✔ 用户是谁(角色识别入口)
✔ 用户要什么(意图识别)
✔ 推荐什么内容(TSPR触发)
👉 如果这一层错了,后面全错
✅ 一句话总结
👉 Query Analysis = 把一句人话,拆成“机器可理解的用户画像数据”