使用任意 LLM 的 Anthropic 风格引用

Image Sourced from https://www.anthropic.com/news/introducing-citations-api and edited by author

图片来源自 https://www.anthropic.com/news/introducing-citations-api 并由作者编辑

Anthropic’s new Citations feature for Claude recently went viral because it lets you attach references to your AI’s answers automatically — yet it’s only available for Claude. If your pipeline runs on ChatGPT, a local open-source model, or something else, you’re out of luck with the official approach.

Anthropic 为 Claude 的新 Citations 功能最近走红,因为它让你可以 自动 将引用附加到 AI 的答案上 — 却仅适用于 Claude。如果你的管道运行在 ChatGPT、本地开源模型或其他东西上,你就无法使用官方方法了。

That’s why I put together this article: to show how you can roll your own Anthropic-style citation system, step by step, for any LLM you want. We’ll store chunks in a vector DB, retrieve them, pass them to the LLM with instructions on how to produce <CIT> tags referencing specific sentences, and then parse the final answer to display a neat, interactive UI for each citation. Yes, it’s a bit messy—and, if I had my choice, I’d use Anthropic’s built-in feature. But if you can’t, here’s your alternative.

这就是我撰写本文的原因:展示如何为任何您想要的 LLM 自制 Anthropic 风格的引用系统,逐步进行。我们将 chunks 存储在 vector DB 中,检索它们,将它们传递给 LLM 并附带指示如何生成引用特定句子的 <CIT> 标签,然后解析最终答案以为每个引用显示整洁的交互式 UI。是的,有点乱——如果我有选择,我会使用 Anthropic 的内置功能。但如果不能,这里是您的替代方案。

Note*: Anthropic likely uses a single-pass approach (like we do) to generate both the final answer and the citations inline. Another approach is two-pass: first the model writes an answer, then we ask it to label each snippet with references. That can be more accurate, but it’s also more complex and slower. For many use cases, inline citations are enough.*

注意*:Anthropic 很可能使用单次通过方法(像我们一样)来生成最终答案和内联引用。另一种方法是两阶段:首先模型撰写答案,然后我们要求它为每个片段添加引用标签。这可能更准确,但也更复杂且更慢。对于许多用例,内联引用就足够了。*

1. The Architecture at a Glance

1. 架构一览

Below is a quick look at how our do-it-yourself citation system works:

以下是我们自制引用系统的工作原理快速概览:

  1. User Query: We ask, say, “How does Paul Graham decide what to work on?”
  2. 用户查询:我们询问,比如,“Paul Graham 如何决定从事什么工作?”
  3. Vector DB Search: We embe...
开通本站会员,查看完整译文。

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.1. UTC+08:00, 2026-04-18 12:30
浙ICP备14020137号-1 $방문자$