|
| 1 | +<!-- |
| 2 | + * @Author: haoxingjun |
| 3 | + * @Date: 2026-01-27 13:10:41 |
| 4 | + * @Email: haoxingjun@bytedance.com |
| 5 | + * @LastEditors: haoxingjun |
| 6 | + * @LastEditTime: 2026-01-27 13:11:01 |
| 7 | + * @Description: file information |
| 8 | + * @Company: ByteDance |
| 9 | +--> |
| 10 | +# Intent Tool |
| 11 | + |
| 12 | +本模块提供基于意图识别的股票因子检索能力。 |
| 13 | + |
| 14 | +## 快速开始 |
| 15 | + |
| 16 | +```python |
| 17 | +from veadk.tools.builtin_tools.intent_tool.governance import IntentGovernor |
| 18 | +from veadk.tools.builtin_tools.intent_tool.retriever import StockRetriever |
| 19 | + |
| 20 | +# 1. 初始化 |
| 21 | +governor = IntentGovernor() |
| 22 | +# 指定 VikingDB 中的 Collection 名称 |
| 23 | +retriever = StockRetriever(collection_name="stock_factors_kb") |
| 24 | + |
| 25 | +# 2. 用户提问 |
| 26 | +query = "前2月销额累计值同比稳增的半导体股" |
| 27 | + |
| 28 | +# 3. 意图识别 |
| 29 | +intent_result = governor.process(query) |
| 30 | + |
| 31 | +if intent_result["status"] == "PROCEED": |
| 32 | + # 4. 执行检索 |
| 33 | + context_data = retriever.retrieve(intent_result["payload"]) |
| 34 | + |
| 35 | + print("检索到的上下文:") |
| 36 | + print(context_data["context_str"]) |
| 37 | + |
| 38 | + # 5. (可选) 发送给 LLM 生成最终回答 |
| 39 | + # llm.chat(query, context=context_data["context_str"]) |
| 40 | +else: |
| 41 | + print("需澄清:", intent_result["message"]) |
| 42 | +``` |
| 43 | + |
| 44 | +## ⚙️ 关键配置说明 |
| 45 | + |
| 46 | +### IntentGovernor |
| 47 | +* **默认值注入**: 在 `process` 方法中,针对 `industry` 和 `time_window` 为空的情况做了默认值处理(全市场/最新)。 |
| 48 | +* **指标清洗**: 内置 `_clean_indicator` (内部逻辑) 函数,防止“半导体”同时出现在行业和指标列表中。 |
| 49 | + |
| 50 | +### StockRetriever |
| 51 | +* **search_knowledge**: 调用 VikingDB 的标准接口。 |
| 52 | +* **Limit**: 默认每个指标检索 `TOP_K=1` 条最相关定义(因为使用了强时间约束,召回精度较高)。 |
| 53 | + |
| 54 | +## ❓ 常见问题 |
| 55 | + |
| 56 | +**Q: 为什么检索结果里还是有“前3月”的数据?** |
| 57 | +A: 请检查 `GoalFrame` 中的 `time_window` 是否被正确提取。如果提取正确,可能需要调整 VikingDB 的 Embedding 模型或增加 Rerank 步骤。 |
| 58 | + |
| 59 | +**Q: 离线编译报错 "Reasoning mismatch"?** |
| 60 | +A: 这是因为 LLM 的思维链与生成的 JSON 不一致。请检查 `builder.py` 中的 Labeler Prompt,确保约束条件明确。我们已在最新版中放宽了校验逻辑。 |
| 61 | + |
| 62 | +**Q: 如何更新意图识别能力?** |
| 63 | +A: 只需在 CSV 中添加新的典型 Case,重新运行 `builder.py`,然后重启在线服务即可。无需修改 Python 代码。 |
0 commit comments