检索管线

使用 Laya 进行 RAG Passage Filtering

在送入生成模型前,对检索片段做相关性评分与过滤。

使用场景

把 Laya 放在 retrieval 后、generation 前,过滤明显无关的上下文。

State

Question: What is the refund period? Passage: Annual subscriptions can be refunded within 30 days of the initial purchase.

Typed questions

scorerelevance

How relevant is this passage to the question?

irrelevantweakusefuldirect answer
noulkeep

Should this passage be kept for the downstream answer?

预期方向

  • 查看主要结构化结果是否符合预期
  • 检查概率 / score 是否支持你的业务阈值
上线前用自己的 query / passage 分布验证。

直接复制代码

Python
from laya import Router
router = Router(preload=True)
state = {"question": "What is the refund period?", "passage": "Annual subscriptions can be refunded within 30 days."}
questions = {
    "relevance": {"type": "score", "instructions": "How relevant is this passage?", "criteria": ["irrelevant", "weak", "useful", "direct answer"]},
    "keep": {"type": "noul", "instructions": "Should this passage be kept?"}
}
print(router.predict(state, questions))
TypeScript / Node.js
import { Laya } from "@receptron/laya";
const laya = await Laya.load();
const result = await laya.systemOne(
  { question: "What is the refund period?", passage: "Annual subscriptions can be refunded within 30 days." },
  {
    relevance: { type: "score", instructions: "How relevant is this passage?", criteria: ["irrelevant", "weak", "useful", "direct answer"] },
    keep: { type: "noul", instructions: "Should this passage be kept?" },
  },
);
console.log(result.answers);
await laya.close();