|
243 | 243 | for (const paperId of papers) { |
244 | 244 | const f = figureIndex.find((g) => g.paper_id === paperId && re.test(String(g.caption || "").trim())); |
245 | 245 | if (f && typeof f.page_number === "number") { |
246 | | - out.push({ paperId, page: f.page_number }); |
| 246 | + out.push({ paperId, page: f.page_number, chunkId: f.chunk_id, caption: String(f.caption || "") }); |
247 | 247 | // One page per reference — matching the same "Figure 2" in a second |
248 | 248 | // paper would crowd out the question's other references. |
249 | 249 | break; |
|
266 | 266 | "- Cite specific chunk IDs when making factual claims by wrapping the literal id in square brackets. Example: if a chunk header is [2604.22753v1::p5::c24], cite it as [2604.22753v1::p5::c24] — NOT [chunk_id 2604.22753v1::p5::c24] and NOT [chunk 24]. Use only ids that appear in the provided context.", |
267 | 267 | "- Attached page images are labeled with their own id, e.g. [page image 2604.22753v1::p5::page]. When you describe what a figure, plot, table, or diagram shows based on looking at a page image, cite that page id (e.g. [2604.22753v1::p5::page]) — not a text chunk. Cite text chunk ids only for claims supported by the chunk text itself.", |
268 | 268 | "- Several pages may be attached. Cite the id of the page that actually contains the figure you are describing — check the label immediately before the image you read; a page that merely mentions the figure in its text is the wrong citation.", |
| 269 | + "- Watch figure numbers. If a retrieved chunk discusses a different figure than the one the user asked about (it says \"Fig. 2\" but the question asks about Figure 1), do not transfer its claims to the asked figure. Describe the asked figure only from its own caption chunk or its page image.", |
269 | 270 | "- Prior turns are included for reference. If the user follows up about something from your own previous answer (a term you used, a claim you made) and the current chunks don't cover it, explain it from the previous turn's evidence — without bracket citations — instead of refusing.", |
270 | 271 | "- Keep answers concise (3-6 sentences unless the question demands more).", |
271 | 272 | ].join("\n"); |
|
304 | 305 | } |
305 | 306 | } |
306 | 307 | } |
307 | | - // Attach the page that actually shows a figure/table the question names, |
308 | | - // when retrieval didn't already bring it in. |
309 | | - if (useImages) { |
310 | | - for (const ref of referencedFigurePages(latestUserText, chunks, figureIndex)) { |
311 | | - const key = `${ref.paperId}:${ref.page}`; |
312 | | - if (seenPages.has(key)) continue; |
313 | | - seenPages.add(key); |
314 | | - const dataUrl = await imageToDataUrl(pageImageUrl(ref.paperId, ref.page)); |
315 | | - if (dataUrl) { |
316 | | - content.push({ type: "text", text: `[page image ${ref.paperId}::p${ref.page}::page]` }); |
317 | | - content.push({ type: "image_url", image_url: { url: dataUrl } }); |
318 | | - } |
| 308 | + // When the question names a figure/table, inject its caption as a citable |
| 309 | + // chunk and attach its page. Retrieval often misses the caption chunk — |
| 310 | + // captions rarely share words with the question ("Fig. 1: (a) Previous |
| 311 | + // driving world models…" vs "What does Figure 1 illustrate?") — and the |
| 312 | + // model then transplants text about a DIFFERENT figure onto the asked one. |
| 313 | + for (const ref of referencedFigurePages(latestUserText, chunks, figureIndex)) { |
| 314 | + if (ref.chunkId && ref.caption) { |
| 315 | + content.push({ |
| 316 | + type: "text", |
| 317 | + text: `[chunk ${ref.chunkId}] paper=${ref.paperId} pages=${ref.page} — caption of the figure/table named in the question\n${ref.caption.slice(0, 700)}`, |
| 318 | + }); |
| 319 | + } |
| 320 | + if (!useImages) continue; |
| 321 | + const key = `${ref.paperId}:${ref.page}`; |
| 322 | + if (seenPages.has(key)) continue; |
| 323 | + seenPages.add(key); |
| 324 | + const dataUrl = await imageToDataUrl(pageImageUrl(ref.paperId, ref.page)); |
| 325 | + if (dataUrl) { |
| 326 | + content.push({ type: "text", text: `[page image ${ref.paperId}::p${ref.page}::page]` }); |
| 327 | + content.push({ type: "image_url", image_url: { url: dataUrl } }); |
319 | 328 | } |
320 | 329 | } |
321 | 330 | content.push({ type: "text", text: `\nQuestion: ${latestUserText}` }); |
|
0 commit comments