/ Clairic(字段卡片)。设计制作。)
OCR 输出什么
OCR 输出的是它在图片里认出的字符和行。它不判断一串字是什么意思,也不会把"12.50"转成数字、把"10月3日"转成日期。
所以跑完 OCR,哪一行是订单号、哪个数是税额,还得你自己去找。
Clairic 输出什么
Clairic 按你定义的字段,每个返回一个类型化的值。标量字段可以带 confidence 和 pNull,输入确定不了的值返回 null。用文本作为 state 传入时,text 字段还能带 span,指回原文位置。Clairic 不生成文本。
同一张小票,两种输出(示意):
| OCR | Clairic | |
|---|---|---|
| 输出 | 多行原文文本 | { order_number, purchase_time, subtotal, tax, tip, discount: null } |

流水线对比
典型的 OCR 流水线是:图片 → OCR → 正则/规则/模板 → 字段。这些规则和版式绑在一起,版式一变就得跟着改。
换成 Clairic,规则这一步就变成一次 extract() 调用:写好字段定义和 instructions 即可。
→字段。设计制作。)
| OCR + 规则 | Clairic extract() | |
|---|---|---|
| 输出 | 文本 | 类型化字段 |
| 找字段 | 自己写规则/模板 | 字段定义 + instructions |
| 缺失值 | 规则匹配不到时自行处理 | pNull 超过阈值返回 null |
| 置信信号 | 视引擎而定 | 字段级 confidence、pNull(标量) |
| 计算值(如到期日) | 自己写 | 可通过 instructions 让 Clairic 推出 |
| 计费 | 视方案而定 | 每次请求一次,按输入大小 |
组合使用
已经在用 OCR 的话,直接把它的文字作为 state 传给 Clairic。保留原文的好处是,text 字段的结果能带 span,方便高亮。也可以文本和图片一起传:state 非空,再加最多 4 张图片。
tsimport {
createSystemOne, defineFields, textField, numberField, dateTimeField,
} from '@system-one-ai/core';
import { systemOneAdapter } from '@system-one-ai/adapter-system-one';
import { createFetchTransport } from '@system-one-ai/transport-fetch';
const apiKey = process.env.SYSTEM_ONE_API_KEY;
if (!apiKey) throw new Error('Set SYSTEM_ONE_API_KEY.');
const client = createSystemOne({
adapter: systemOneAdapter,
transport: createFetchTransport(),
apiKey,
timeoutMs: 30_000,
maxRetries: 0,
});
const ocrText = `<text returned by your OCR step>`;
const result = await client.extract({
model: 'clairic',
state: ocrText,
fields: defineFields({
order_number: textField(),
purchase_time: dateTimeField(),
subtotal: numberField({ decimals: 2 }),
tax: numberField({ decimals: 2 }),
discount: numberField({ decimals: 2, instructions: 'Only if the receipt shows a discount.' }),
}),
options: { returnStateText: true },
});
const order = result.answers.order_number;
console.log(order.value, order.span); // span = ocrText 中的 [起, 止] 字符位置
安装:npm install @system-one-ai/core@0.8.0 @system-one-ai/adapter-system-one@0.7.0 @system-one-ai/transport-fetch@0.8.0,在 .env 里设置 SYSTEM_ONE_API_KEY,用 node --env-file=.env 运行。每运行一次就是一次计费请求。options.returnStateText 会返回 span 所索引的那段文本,高亮起来很方便。
不想写代码,也可以先在发票信息提取 demo 里看看 Clairic 处理发票文本的效果(需登录)。
只用 OCR 就够的时候
如果你要的是全文检索、全文存档,并不需要具体字段,单用 OCR 就够了。
需要字段的话,可以看看《LLM 抽取 vs Clairic》和截图转 JSON,费率见 Clairic 模型页。
相关阅读
核验日期:2026-10-22