TSPR-WEB-LLM-HIC 生产级架构升级方案

TSPR-WEB-LLM-HIC 生产级架构升级方案

技术支持:拓世网络技术开发工作室

  1. 权重动态化(支持按领域配置 + 离线搜索)

  2. 反馈闭环具象化(不直接改概率,而是引入反馈偏置)

  1. 多轮对话状态管理(增加会话一致性控制)

  2. 成本主动控制(预算熔断)

  3. 补齐验收标准与风险表


TSPR-WEB-LLM-HIC 生产级架构升级方案 v2.1

一、总架构定位

项目 说明

名称 TSPR-WEB-LLM-HIC v2.0

定位 可控式 LLM 决策引擎 + 知识增强推荐系统

核心能力 概率链调度 + 人在闭环 + 成本治理 + 可解释推理

适用场景 智能推荐、智能导购、企业问答、垂类助手、ToB SaaS


二、核心数据结构(已扩展)

2.1 Query 增强

```python

class Query:

query_id: str

session_id: str

user_id: str

text: str

history: list[dict] # 对话历史

timestamp: int

source: str # WEB/APP/API

intent: Intent

multi_intent: list[Intent]

semantic_vector: list[float]

prob_chain: ProbabilityChain

context: dict # 上下文槽位

need_llm: bool

need_human: bool

status: str # INIT / PROCESS / DONE / HUMAN

```

2.2 Intent 结构

```python

Intent = {

"intent_id": str,

"role": str,

"scenario": str,

"domain": str, # ecommerce / education / medical

"need": str,

"constraint": dict,

"entities": list[Entity],

"confidence": float,

"is_multi": bool

}

```

2.3 ProbabilityChain(增强版)

```python

ProbabilityChain = {

"S1": 0.82, "S2": 0.75, "S3": 0.68, "S4": 0.72, "S5": 0.66,

"weights": {...}, # 按 domain 动态加载

"final": 0.71,

"calc_method": "weighted_sum_norm",

"version": "v1",

"feedback_bias": 0.0 # 新增:历史反馈偏置

}

```


三、核心算法(已修正)

3.1 概率融合公式

```python

def compute_probability_chain(query: Query) -> ProbabilityChain:

P1 = intent_model(query.text)

P2 = semantic_match(query.intent, content_pool)

P3 = kg_score(query.intent)

P4 = content_score(content_pool)

P5 = ranking_score(query, content_pool)

按领域加载权重(可配置)

w = load_weights_by_domain(query.domain)

final_raw = w["S1"]*P1 + w["S2"]*P2 + w["S3"]*P3 + w["S4"]*P4 + w["S5"]*P5

final_prob = min(max(final_raw, 0.0), 1.0)

return {"S1":P1, "S2":P2, "S3":P3, "S4":P4, "S5":P5,

"weights":w, "final":final_prob,

"calc_method":"weighted_sum_norm", "feedback_bias":0.0}

```

3.2 动态决策阈值

```python

THRESHOLD_CONFIG = {

"default": {"high":0.7, "mid":0.4},

"ecommerce": {"high":0.65, "mid":0.35},

"education": {"high":0.75, "mid":0.5}

}

def llm_decision(prob_chain, domain="default"):

th = THRESHOLD_CONFIG[domain]

final = prob_chain["final"] + prob_chain.get("feedback_bias", 0.0)

if final > th["high"]:

return "NO_LLM"

elif final > th["mid"]:

return "CALL_LLM"

else:

return "HUMAN_REQUIRED"

```

3.3 人工反馈闭环(修正版)

不再直接修改概率链,而是引入 反馈偏置,支持时间衰减:

```python

def apply_human_feedback(query_id, intent, is_correct):

存入反馈存储

feedback_store.record(query_id, intent, is_correct)

def get_feedback_bias(intent, window_days=7):

stats = feedback_store.stats(intent, window_days)

if stats.total == 0:

return 0.0

正确率越高,偏置越大(正向)

bias = (stats.correct - stats.incorrect) / stats.total

return min(max(bias * 0.1, -0.1), 0.1) # 限制范围

```

3.4 多轮对话一致性控制

```python

def apply_conversation_consistency(query, last_intent):

if query.session_id and last_intent:

if query.intent != last_intent:

意图跳变惩罚

return 0.85

return 1.0

```


四、微服务架构(含降级)

4.1 服务拆分

```

intent-service

semantic-service

kg-service

content-engine

ranking-engine

tspr-core # 新增:降级/熔断/缓存

llm-gateway # 增强:路由/限流/成本/预算熔断

hic-console

orchestrator v2 # 并行调度 + 一致性控制

monitor-service

config-service # 动态阈值 + 权重配置

```

4.2 熔断降级规则

条件 动作

kg-service 异常 P3 = 1.0,标记 DEGRADE_KG

vector 异常 P2 = 1.0,标记 DEGRADE_VECTOR

错误率 > 30% 全局降级为规则引擎 + 缓存

月度成本 > 预算 80% 强制 NO_LLM


五、LLM Gateway(生产级)

能力 说明

多模型路由 OpenAI / Claude / Gemini / 本地模型

容错 超时、重试、熔断、限流

成本控制 Token统计、预算熔断、成本告警

安全 敏感词过滤、结果缓存

可观测 全链路日志追踪


六、API 设计

6.1 推理接口

```http

POST /tspr/v2/infer

Headers: Authorization, Domain

Body: {

"query": "...",

"session_id": "xxx",

"user_id": "xxx"

}

```

6.2 配置刷新

```http

POST /admin/config/refresh

```

6.3 状态查询

```http

GET /tspr/v2/status/{query_id}

```


七、Orchestrator 调度核心(最终版)

```python

def orchestrator(query: Query):

1 全局熔断检查

if monitor.get_error_rate() > 0.3:

return degrade_direct_output(query)

if llm_gateway.monthly_cost() > budget * 0.8:

return direct_output(query) # 强制不调LLM

2 并行调用

p1 = intent_service.call_async(query.text)

p2 = semantic_service.call_async(query.text)

p3 = kg_service.call_async(query.intent)

wait_all(p1, p2, p3)

3 后续串行

p4 = content_engine.call(query)

p5 = ranking_engine.call(query)

4 概率计算

prob_chain = compute_probability_chain(query)

5 多轮一致性调整

last_intent = session_store.get_last_intent(query.session_id)

consistency = apply_conversation_consistency(query, last_intent)

prob_chain["final"] *= consistency

6 反馈偏置

bias = get_feedback_bias(query.intent)

prob_chain["feedback_bias"] = bias

7 决策

decision = llm_decision(prob_chain, query.domain)

if decision == "NO_LLM":

return direct_output(query)

elif decision == "CALL_LLM":

return llm_gateway.call(query)

else:

return hic_console.trigger(query)

```


八、监控指标(全维度)

类别 指标

概率层 S1~S5 分布、final_prob 分位线

决策 LLM调用率、人工介入率、降级次数

成本 月度成本、单次成本、预算告警

质量 满意度、转化率、反馈偏置变化

系统 错误率、延迟、熔断次数


九、验收标准(KPI)

指标 目标值

LLM 调用率 ≤ 30%

人工介入率 ≤ 5%

P99 延迟 ≤ 1.5s

系统可用性 ≥ 99.9%

月度 LLM 成本 ≤ 预算 80%(主动熔断)

反馈偏置收敛 7 天内显著区分好坏意图


十、风险与对策表

风险 概率 影响 对策

权重不收敛 中 高 离线贝叶斯搜索 + A/B实验

恶意反馈攻击 低 中 反馈偏置限幅 ±0.1 + 用户信用分

多轮对话状态爆炸 中 中 Session TTL + 槽位过期策略

成本超预算 中 高 预算熔断 + 日/周告警

模型退化 中 高 离线评估 + 自动回滚


十一、MVP 路径(能力升级版)

阶段 内容

阶段1 规则 + 轻向量 + 基础调度

阶段2 KG + 概率链 + 动态阈值 + 反馈存储

阶段3 HIC + 可解释 + A/B测试 + 多轮一致性

阶段4 自学习(离线微调 + 权重搜索)+ 多租户 SaaS


十二、资源预估(2人月)

角色 人力 周期

后端开发 1人 1.5月

算法工程师 0.5人 1月

运维/监控 0.5人 0.5月

相关推荐
毛骗导演几秒前
Claude Code Agent 实现原理深度剖析
前端·架构
不瘦80斤不改名19 分钟前
深入理解 FastAPI 核心架构:依赖注入、分页机制与数据流转的底层逻辑
python·架构·fastapi
Jutick27 分钟前
Spring Boot WebSocket 实时行情推送实战:从断线重连到并发优化
后端·架构
浮芷.32 分钟前
生命科学数据视界防御:基于鸿蒙Flutter陀螺仪云台与三维体积光栅的视轴锁定架构
flutter·华为·架构·开源·harmonyos·鸿蒙
zz07232043 分钟前
Seata ——微服务分布式事务
分布式·微服务·架构·seata
浮芷.44 分钟前
东方修仙模拟器:基于 鸿蒙Flutter 状态机与 CustomPainter 的境界跃升与天劫渲染架构
科技·flutter·华为·架构·开源·harmonyos·鸿蒙
在秃头的路上啊1 小时前
数据库下Lambda 架构(spark+flink)
架构·flink·spark
禅思院1 小时前
从术到道:构建企业级异步组件加载方案的设计哲学与实现精要
前端·vue.js·架构
lwf0061641 小时前
Architecture Diagram Generator + Excalidraw + 飞书绘制架构图操作指南
架构·飞书
tq10861 小时前
配置、CPS、插件与Lisp宏:规则延迟固化的四种能力层次
架构·lisp