Skip to content

An AI-powered search engine with a generative UI

fix(chat): recalibrate PDF and image attachment token estimates (#1025)

Yoshiki Miurae893d554d77a
diff --git a/lib/streaming/__tests__/create-chat-stream-response.test.ts b/lib/streaming/__tests__/create-chat-stream-response.test.ts
index bf0885ac..2bb2dfb5 100644
--- a/lib/streaming/__tests__/create-chat-stream-response.test.ts
+++ b/lib/streaming/__tests__/create-chat-stream-response.test.ts
@@ -556,7 +556,7 @@ describe('createChatStreamResponse', () => {
input: '"earlier.png" (image/png)',
output: 'Answer',
metadata: {
- carriedContext: { attachments: 1, attachmentTokens: 10_000 }
+ carriedContext: { attachments: 1, attachmentTokens: 4_000 }
}
})
})
diff --git a/lib/utils/attachment-tokens.ts b/lib/utils/attachment-tokens.ts
index 5387b771..2fb831bc 100644
--- a/lib/utils/attachment-tokens.ts
+++ b/lib/utils/attachment-tokens.ts
@@ -1,8 +1,8 @@
-export const IMAGE_ATTACHMENT_TOKENS = 10_000
+export const IMAGE_ATTACHMENT_TOKENS = 4_000
export const MIN_PDF_ATTACHMENT_TOKENS = 10_000
-// A 500 KB PDF reaches the small-document floor; larger containers scale so
+// A 300 KB PDF reaches the small-document floor; larger containers scale so
// multi-page files cannot all hide behind a flat estimate.
-export const PDF_BYTES_PER_TOKEN = 50
+export const PDF_BYTES_PER_TOKEN = 30
export const BYTES_PER_TOKEN = 3.9
export const UNKNOWN_ATTACHMENT_TOKENS = 50_000