- gateway/proxy/ 十文件:config(ProxyConfig:元->毫元加载期换算 D-P1、差异化售价、 桶/峰谷/限流/semcache 配置)/ errors(8 类 HTTP 语义异常)/ ledger(四表两索引 DDL, WAL,ReviewQueue 连接纪律)/ auth·pricing·normalizer·semcache·upstream(§6 签名占位) / routes(/proxy/v1/models OpenAI 形状)/ __init__(build_proxy_router 组装点) - settings DEFAULTS 增 proxy 段(enabled 默认 False,D-P7) - api.py 首次 include_router(enabled 门控 + 装配失败不拖垮主应用) - serve.py workers>1 拒绝启动(D-P9:WEB_CONCURRENCY/UVICORN_WORKERS 校验) - 测试 +4(门控 404/DDL 幂等/毫元换算/池模型列表),全量 322 passed
25 lines
889 B
Python
25 lines
889 B
Python
"""语义缓存(T-P6 落地;本文件先立签名)。
|
||
|
||
规格(§6):L1 精确 + L2 字符 2/3-gram 倒排(启动自 sqlite 重建),
|
||
加权 Jaccard(3-gram 权 2)+ 共享 gram>=3 门限 + 阈值 0.92,
|
||
TTL + LRU(max_entries),L2 命中 promote_frequency 次晋升 L1。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, Dict, Optional
|
||
|
||
|
||
class SemanticCache:
|
||
"""两级语义缓存(T-P6 实现)。"""
|
||
|
||
def lookup(self, bucket: str, doc_version: int, norm_hash: str,
|
||
norm_text: str, now: float) -> Optional[Dict[str, Any]]:
|
||
raise NotImplementedError("T-P6")
|
||
|
||
def put(self, bucket: str, doc_version: int, norm_hash: str,
|
||
norm_text: str, answer: str, model: str, now: float) -> None:
|
||
raise NotImplementedError("T-P6")
|
||
|
||
def stats(self) -> Dict[str, Any]:
|
||
raise NotImplementedError("T-P6")
|