文件放不进 context window:
怎么找到一段具体内容,怎么总结整本书?

英文问法The file exceeds the context window of your agent. How would you find the croissant recipe in a recipe book and summarize it? · Summarize me this book. How would you implement such a pipeline? · How do you navigate the tree, where do you stop, and what do you show the LLM?

考过★ 作者本人 Apple ISE Proactive 实习一面(2026-11-09),这个组唯一的一手真题 · 你答了 graph 之后,面试官追问 "What's the flow? How do you navigate this? Where do you stop? What do you take? And what do you show the LLM?" 和 "What is the embedding for chapter 3 itself compared to embedding for chapter 3.b?" · 完整记录在 ml-八股 09 第 40 题

先弄清楚:每个概念是什么

Token budget
context window 里能留给 evidence 的额度。面试官给的数字是 32K。扣掉 instruction、问题和回答,剩下的才能放 chunk。
按结构切 chunk
沿标题和章节切,不是每隔固定长度切一刀,一个 recipe 是一个 chunk。基础见 RAG。
Tree index
leaf 是原文 chunk,parent 是 children 的 LLM summary,一层层往上直到 root。书有目录时,标题层级就是现成的 tree。

看图:tree 上怎么找,整本书怎么总结

query:croissant recipe book 0.30 ch 1 0.21 ch 2 0.18 ch 3 0.55 … … 3.a 0.40 3.b croissant 0.83 3.c 0.35 ch 3:summary 的 embedding 3.b:原文的 embedding
图 1:数字是 query 和节点的 similarity,只作示意。Tree traversal 沿粗线一层层往下,collapsed tree 把 7 个节点一起排序,3.b 排第一。
map reduce ch 1 ch 2 ch 3 … ch N summary 1 summary 2 summary 3 … summary N book summary
图 2:没有 query 时用 map-reduce。每章各自 summarize(map),再把这些 summary 合起来 summarize 一次(reduce)。

30 秒回答

I'd start with the simplest thing that works. Split the file along its structure, embed each chunk, score every chunk against the query, sort, and fill the token budget with the best ones; the model answers only from those. If recall is poor, I add BM25 for exact names and pull in the whole section around a hit. A summary tree helps broad questions: each parent is an LLM summary of its children, and I rank nodes from all levels together. For a whole-book summary there is no query to rank by, so I summarize each chapter in parallel, then summarize the summaries, adding a level if they still don't fit.

Case 1:找 croissant recipe

版本做法还剩的问题
v1 Rank + budget按标题切 chunk,每块和 query 算 similarity,排序后从高到低装满 token budget。面试官说这是 easiest approach一个 recipe 被切成几块;专名靠 embedding 不稳
v2 Hybrid + 取整节加 BM25 匹配专名,命中后取所在的整节问得宽时,没有哪个 leaf 足够像
v3 Tree建 tree index,各层节点都能被检索到建 index 要多次调用 LLM;summary 会丢细节

面试官的追问:tree 上怎么走

追问回答
Chapter 3 和 3.b
的 embedding
Chapter 3 的来自它的 summary,概括 3.a–3.c。3.b 的来自自己的原文。所以具体问题和 3.b 更像,宽问题和 chapter 3 更像
Flow在 root 层取 similarity 最高的 k 个,只在它们的 children 里再取 top-k,一层层往下
Where to stop到 leaf 停,或者 token budget 装满
What to takeTree traversal 把每层选中的节点都留下。Collapsed tree 不分层,所有节点一起按 similarity 排序,按 token budget 截断
What to show选中节点的文本带上标题路径,按原文顺序排。parent 和它的 child 都选中时只留 child,这一条是设计取舍,RAPTOR 没有这一步

RAPTOR 的实验里 collapsed tree 比 tree traversal 好。它是在 QASPER 的 20 篇上比的,主实验把上限定在 2000 token,大约是 top-20 个节点。Collapsed tree 就是 v1 的做法用在 tree 的节点上。

Case 2:总结整本书

  1. 切:按章切,一章还放不下就再按节切
  2. Map:每块各自 summarize,可以并行
  3. Reduce:把这些 summary 合起来再 summarize 一次,还超 token budget 就分组多做一层

有 tree 时,root 层的 summary 就是答案,建 index 时算好并缓存。另一种做法是 refine,带着当前的 summary 顺序读下一块。它不能并行,结果还受顺序影响。

手算一遍。书有 200K token,token budget 是 32K。按 8K 一块切成 25 块,每块压成 500 token,合起来 12.5K,一次 reduce 就放得下,一共调用 LLM 26 次。

必答点

追问

这两种情况怎么 eval?

Case 1 先看答案所在的 chunk 有没有进 context,再看回答的 groundedness(见 grounded 回答)。Case 2 看 summary 覆盖了多少 key point,以及每一句在原文里有没有依据。

排在最前面的 chunk 也不相关,怎么办?

给 similarity 设一个阈值,都低于它就说书里没找到,不硬答(见 abstention)。

文件没有目录和标题,怎么建 tree?

先按固定长度切 leaf,再按 embedding 做 clustering,每个 cluster 生成一个 summary 当 parent,重复到聚不动为止。RAPTOR 的 leaf 是 100 token,clustering 用 GMM,一个节点可以属于多个 cluster。

换一个 context 更长的模型,把整本书放进去不行吗?

题目的前提是放不下。就算放得下,context 越长成本越高,中间的内容也更容易被忽略(见 RAG 的 Lost in the Middle)。

来源作者本人 2026-11-09 一面的记录(ml-八股 09 第 40 题)· RAPTOR(tree 的构建、tree traversal 和 collapsed tree、QASPER 上的比较)