# 1. 混合检索
·ThisToken.AI·
Use Cases场景案例ThisToken.AI
hits = hybrid_search(question, top_k=8) # 向量 + BM25
reranked = rerank(question, hits, top_k=4) # 重排序
if reranked[0].score < 0.35: # 检索质量太差
return {"answer": None,
"msg": "未检索到足够依据,建议转人工"}
2. 带引用生成
context = "\n\n".join(
f"[{i+1}] {h.source}(相关度{h.score:.2f})\n{h.text}"
for i, h in enumerate(reranked)
)
prompt = f"""你是法律咨询助手。仅依据以下资料回答,资料中没有的不要编造。
输出格式:结论 / 依据(标注[编号])/ 风险提示。
资料:
{context}
问题:{question}"""
resp = gateway.chat(prompt, model="deepseek-v3") # 统一网关调用
return {"answer": resp.text, "citations": reranked}
Post-launch real-world results: a single consultation went from 40 minutes of manual work to a machine-generated draft within 90 seconds, plus 3–5 minutes of human review. The team's daily throughput rose from 8 to 100+ consultations. The marginal cost is mainly token fees — the full pipeline (retrieval + generation) costs about 0.05–0.15 RMB per consultation, two orders of magnitude cheaper than hourly human labor.
## Why a Unified AI API Gateway Saves Maintenance Costs
This architecture requires calling three types of models: Embedding, reranking, and generation. Legal Q&A is also very sensitive to model capabilities — different question types suit different models (long-context models for analyzing long contracts, cheap models for simple Q&A). If you register separate accounts for each model type, write separate SDK adapters, and manage separate keys, a small team simply can't handle it:
1. **One SDK to call all models**: Switching models only requires changing one model parameter, no rewriting of integration code. During the evaluation phase, we compared 4 generation models, changing only one line of configuration each time, compressing the entire evaluation cycle from an estimated week down to two days.
2. **Unified billing and monitoring**: Call logs, token consumption, and error rates for all three pipelines are visible in one dashboard. Troubleshooting "why is this reply so slow/expensive" doesn't require logging into three platforms.
3. **Centralized key management**: One master key replaces seven or eight scattered keys, dramatically reducing both leakage risk and rotation costs.
4. **Instant model failover**: If a model provider times out or rate-limits, the gateway layer switches to a backup model without interrupting the live service — especially critical for small teams without 24/7 on-call staffing.
A rough calculation: without a gateway, maintenance work like "multi-platform registration, integration, reconciliation, and failover scripts" would eat up 15–20 hours per month; with a unified gateway, it's compressed to under 2 hours — effectively gaining two free workdays every month.
## Summary
The key to deploying legal consulting RAG isn't sophisticated algorithms, but rather: **chunk well, do hybrid retrieval, strongly constrain generation, and keep models swappable**. For independent developers and small teams, the last point matters most — consolidating model calls through a unified gateway lets you spend your energy polishing the business, not maintaining pipelines.
If you also want to quickly get your first pipeline running, you can start by registering a unified AI API gateway account at [https://api.thistoken.ai/register](https://api.thistoken.ai/register) — in ten minutes you can use the code above to get your first legal Q&A prototype working.
---
Ready to try it yourself? Sign up at https://api.thistoken.ai/register to get your API key and start building.Vous voulez essayer Token.AI ?
Créez une API Key au niveau du projet, activez les canaux dans la console et configurez le routage, les budgets et les journaux d'audit.
注册 ThisToken.AI 并获取 API Key