llm-large-files 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1719 -466
- package/README.md +190 -60
- package/dist/analyze.d.ts +8 -1
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +198 -54
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts +14 -3
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +194 -40
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +63 -7
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +1131 -214
- package/dist/ask.js.map +1 -1
- package/dist/decode.d.ts +19 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +97 -0
- package/dist/decode.js.map +1 -0
- package/dist/encoding.d.ts +17 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +852 -0
- package/dist/encoding.js.map +1 -0
- package/dist/errors.d.ts +59 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +80 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +339 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +163 -0
- package/dist/events.js.map +1 -0
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +9 -2
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +26 -7
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +180 -314
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +17 -8
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +117 -66
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +23 -3
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +6 -2
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/endpoints.d.ts +5 -1
- package/dist/gemini/endpoints.d.ts.map +1 -1
- package/dist/gemini/endpoints.js +11 -2
- package/dist/gemini/endpoints.js.map +1 -1
- package/dist/gemini/errors.d.ts +9 -4
- package/dist/gemini/errors.d.ts.map +1 -1
- package/dist/gemini/errors.js +32 -0
- package/dist/gemini/errors.js.map +1 -1
- package/dist/gemini/generate.d.ts +10 -2
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +33 -10
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -2
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -1
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -1
- package/dist/gemini/sse.js.map +1 -1
- package/dist/groups.d.ts +54 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/groups.js +136 -0
- package/dist/groups.js.map +1 -0
- package/dist/html.d.ts +11 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +1112 -0
- package/dist/html.js.map +1 -0
- package/dist/http.d.ts +116 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +347 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +13 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +67 -5
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +449 -93
- package/dist/library.js.map +1 -1
- package/dist/limiter.d.ts +2 -1
- package/dist/limiter.d.ts.map +1 -1
- package/dist/limiter.js +3 -2
- package/dist/limiter.js.map +1 -1
- package/dist/map-reduce.d.ts +28 -1
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +240 -52
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +84 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +190 -2
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +20 -4
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +184 -28
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/ingest-child.d.ts +38 -0
- package/dist/node/ingest-child.d.ts.map +1 -0
- package/dist/node/ingest-child.js +42 -0
- package/dist/node/ingest-child.js.map +1 -0
- package/dist/node/isolated.d.ts +88 -0
- package/dist/node/isolated.d.ts.map +1 -0
- package/dist/node/isolated.js +381 -0
- package/dist/node/isolated.js.map +1 -0
- package/dist/node/sse.d.ts +59 -0
- package/dist/node/sse.d.ts.map +1 -0
- package/dist/node/sse.js +174 -0
- package/dist/node/sse.js.map +1 -0
- package/dist/office.d.ts +105 -0
- package/dist/office.d.ts.map +1 -0
- package/dist/office.js +1092 -0
- package/dist/office.js.map +1 -0
- package/dist/openai/adapter.d.ts +29 -5
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +325 -37
- package/dist/openai/adapter.js.map +1 -1
- package/dist/output-limit.d.ts +14 -2
- package/dist/output-limit.d.ts.map +1 -1
- package/dist/output-limit.js +39 -10
- package/dist/output-limit.js.map +1 -1
- package/dist/pause.d.ts +24 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +38 -0
- package/dist/pause.js.map +1 -0
- package/dist/pdf-pages.d.ts +32 -2
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +277 -20
- package/dist/pdf-pages.js.map +1 -1
- package/dist/pdf-pictures.d.ts +30 -3
- package/dist/pdf-pictures.d.ts.map +1 -1
- package/dist/pdf-pictures.js +50 -8
- package/dist/pdf-pictures.js.map +1 -1
- package/dist/pdf-work.d.ts +40 -0
- package/dist/pdf-work.d.ts.map +1 -0
- package/dist/pdf-work.js +734 -0
- package/dist/pdf-work.js.map +1 -0
- package/dist/peers.d.ts +8 -0
- package/dist/peers.d.ts.map +1 -0
- package/dist/peers.js +32 -0
- package/dist/peers.js.map +1 -0
- package/dist/plan.d.ts +22 -4
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +61 -12
- package/dist/plan.js.map +1 -1
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +4 -2
- package/dist/ranged.js.map +1 -1
- package/dist/retry.d.ts +23 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +33 -3
- package/dist/retry.js.map +1 -1
- package/dist/search.d.ts +107 -24
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +803 -149
- package/dist/search.js.map +1 -1
- package/dist/sse.d.ts +35 -2
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +145 -31
- package/dist/sse.js.map +1 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +5 -2
- package/dist/stores.js.map +1 -1
- package/dist/text-index.d.ts +9 -1
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +28 -9
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +87 -3
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +526 -24
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +61 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +461 -46
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +103 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/word-styles.d.ts +102 -0
- package/dist/word-styles.d.ts.map +1 -0
- package/dist/word-styles.js +419 -0
- package/dist/word-styles.js.map +1 -0
- package/dist/xlsx.d.ts +23 -0
- package/dist/xlsx.d.ts.map +1 -0
- package/dist/xlsx.js +511 -0
- package/dist/xlsx.js.map +1 -0
- package/dist/xml-stream.d.ts +55 -0
- package/dist/xml-stream.d.ts.map +1 -0
- package/dist/xml-stream.js +235 -0
- package/dist/xml-stream.js.map +1 -0
- package/dist/zip-directory.d.ts +43 -0
- package/dist/zip-directory.d.ts.map +1 -0
- package/dist/zip-directory.js +130 -0
- package/dist/zip-directory.js.map +1 -0
- package/docs/README.md +288 -0
- package/docs/api.md +37 -381
- package/docs/configuration.md +28 -558
- package/docs/getting-started.md +407 -223
- package/docs/guides/anthropic.md +590 -0
- package/docs/guides/conversations.md +629 -0
- package/docs/guides/costs-and-limits.md +728 -0
- package/docs/guides/deployment.md +720 -0
- package/docs/guides/errors-and-reliability.md +748 -0
- package/docs/guides/explorer-model.md +399 -0
- package/docs/guides/openai-compatible.md +602 -0
- package/docs/guides/own-adapter-and-loop.md +1169 -0
- package/docs/guides/pdfs.md +1024 -0
- package/docs/guides/storage.md +731 -0
- package/docs/guides/testing.md +1203 -0
- package/docs/guides/vertex-and-gemini.md +717 -0
- package/docs/guides/web-app.md +1590 -0
- package/docs/how-it-works.md +1035 -164
- package/docs/measurements.md +881 -0
- package/docs/publishing.md +274 -46
- package/docs/reference/anthropic.md +427 -0
- package/docs/reference/ask.md +910 -0
- package/docs/reference/errors-and-retries.md +760 -0
- package/docs/reference/events.md +1001 -0
- package/docs/reference/gemini.md +827 -0
- package/docs/reference/library.md +1598 -0
- package/docs/reference/node.md +706 -0
- package/docs/reference/openai.md +385 -0
- package/docs/reference/tools.md +1031 -0
- package/docs/security.md +940 -101
- package/docs/troubleshooting.md +1410 -0
- package/package.json +7 -3
- package/src/analyze.ts +204 -49
- package/src/anthropic/adapter.ts +200 -40
- package/src/ask.ts +1151 -210
- package/src/decode.ts +89 -0
- package/src/encoding.ts +850 -0
- package/src/errors.ts +125 -0
- package/src/events.ts +451 -0
- package/src/evidence.ts +11 -2
- package/src/extract.ts +191 -308
- package/src/gemini/adapter.ts +127 -70
- package/src/gemini/chat.ts +28 -4
- package/src/gemini/endpoints.ts +12 -2
- package/src/gemini/errors.ts +34 -1
- package/src/gemini/generate.ts +42 -13
- package/src/gemini/index.ts +3 -3
- package/src/gemini/sse.ts +1 -1
- package/src/groups.ts +162 -0
- package/src/html.ts +1071 -0
- package/src/http.ts +376 -1
- package/src/index.ts +29 -6
- package/src/library.ts +498 -93
- package/src/limiter.ts +6 -1
- package/src/map-reduce.ts +252 -51
- package/src/model.ts +244 -4
- package/src/node/handlers.ts +196 -31
- package/src/node/index.ts +4 -0
- package/src/node/ingest-child.ts +61 -0
- package/src/node/isolated.ts +464 -0
- package/src/node/sse.ts +198 -0
- package/src/office.ts +1047 -0
- package/src/openai/adapter.ts +319 -38
- package/src/output-limit.ts +44 -8
- package/src/pause.ts +41 -0
- package/src/pdf-pages.ts +270 -20
- package/src/pdf-pictures.ts +56 -9
- package/src/pdf-work.ts +722 -0
- package/src/peers.ts +29 -0
- package/src/plan.ts +70 -12
- package/src/ranged.ts +4 -2
- package/src/retry.ts +49 -5
- package/src/search.ts +800 -155
- package/src/sse.ts +153 -28
- package/src/stores.ts +5 -2
- package/src/text-index.ts +30 -9
- package/src/text.ts +524 -23
- package/src/tools.ts +445 -46
- package/src/types.ts +108 -5
- package/src/word-styles.ts +420 -0
- package/src/xlsx.ts +478 -0
- package/src/xml-stream.ts +224 -0
- package/src/zip-directory.ts +136 -0
|
@@ -0,0 +1,881 @@
|
|
|
1
|
+
# Measurements
|
|
2
|
+
|
|
3
|
+
This page gathers every live result and measurement that the documentation of this package has
|
|
4
|
+
quoted, each with its date, the version of the library, the models and the setup. Read it when you
|
|
5
|
+
choose a model or a setting, or want to know what has been run against a real provider and what
|
|
6
|
+
has not.
|
|
7
|
+
|
|
8
|
+
Each result is a measurement at one point in time, with the models named. It is not a guarantee.
|
|
9
|
+
Another model, a later version of the same model, another provider or other files can give other
|
|
10
|
+
results. Nothing was run again for this page but one record, which says so: each result is given
|
|
11
|
+
as it was recorded, with the release it was recorded for. Before you rely on a number, check it on your own files
|
|
12
|
+
([Measuring your own setup](#measuring-your-own-setup)).
|
|
13
|
+
|
|
14
|
+
## How to read this page
|
|
15
|
+
|
|
16
|
+
- **Live** means against a real model provider. The other numbers are timings, sizes and counts
|
|
17
|
+
from the library's own runs; the record says when one was taken against a fake model or in a
|
|
18
|
+
probe that reproduced a fault, and so does this page.
|
|
19
|
+
- **Version** is the release a result was recorded for. 0.1.0 is of 2026-11-06, 0.2.0 and 0.3.0 of
|
|
20
|
+
2026-11-10, 0.3.5 and 0.3.6 of 2026-11-11, 0.4.0 of 2026-11-12, and 0.4.1 and 0.5.0 of
|
|
21
|
+
2026-11-13. The checks of 0.6.0 are of November 2026. All live results are of
|
|
22
|
+
November 2026.
|
|
23
|
+
- **Main** is a result recorded on the code on `main` up to commit 5157e7f (2026-11-20), or on its
|
|
24
|
+
branches, before the rest of 0.6.0 was written. "The 0.6 review" is the review of that code, of
|
|
25
|
+
2026-11-20.
|
|
26
|
+
- **5157e7f**, in a table, is that commit: the code before the changes of 0.6.0 that the table
|
|
27
|
+
measures. It reads and stores files as 0.5.0 does: the code that extracts, cleans, indexes and
|
|
28
|
+
stores a file, and reads the pages of a PDF, is that of 0.5.0, but for the cut of a log template
|
|
29
|
+
and of an outline of more than 400 headings. Its `parseSseJson` scans a stream as 0.5.0 does.
|
|
30
|
+
- Where the record names no model, this page says "model not recorded".
|
|
31
|
+
- What a result led to in the library is explained in the guides. This page links to them and does
|
|
32
|
+
not repeat them. The [changelog](../CHANGELOG.md) records 0.6.0, and links to the history of
|
|
33
|
+
0.1.0 to 0.5.0.
|
|
34
|
+
- **Before** in a table of 0.6.0 is the code of 0.6.0 before the change measured, which was never
|
|
35
|
+
released. A column named 5157e7f or 0.5.0 is that code.
|
|
36
|
+
|
|
37
|
+
## What has been run live
|
|
38
|
+
|
|
39
|
+
| Provider | Live runs on record | Not run live |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Gemini API: `askGemini`, `gemini()`, `geminiApi()` | From 0.1.0 to 0.5.0: large files, pages of PDFs, explorer pairs, follow-up questions | Gemini 2.5 with pages (`toolFilePlacement`) and in explorer pairs: it is closed to new users on the Gemini API |
|
|
42
|
+
| Vertex AI: `vertexAi()` | 0.3.0: pages of PDFs, in the locations `global` and `eu`. 0.3.5: explorer pairs. Main (see above): a count, a repeated search, the error of a request too large, and in the 0.6 review a production log of 3 MB | |
|
|
43
|
+
| OpenAI-compatible: `openAiCompatible()` | 0.5.0: Gemini's OpenAI layer only | Every other server: OpenAI, Azure OpenAI, DeepSeek, OpenRouter, vLLM, Ollama, LiteLLM, llama.cpp. The adapter is tested against fake servers. `pdfInput` was never run to an answer: Gemini's OpenAI layer refuses its `file` part (HTTP 400), it was not run against OpenAI itself, and it follows OpenAI's documented shape untested |
|
|
44
|
+
| Claude: `anthropic()` | None | The whole adapter. It is tested against the request and response shapes of the Messages API documentation |
|
|
45
|
+
|
|
46
|
+
Also live on Gemini, with the record not saying whether on the Gemini API or on Vertex AI: Gemini
|
|
47
|
+
ignoring `mode: "NONE"` (0.1.0), counting and listing (0.2.0), PDF tables (0.2.0), the prompt cache
|
|
48
|
+
(0.2.0), the usage of a run of 0.4.0, and models that think (0.4.1).
|
|
49
|
+
|
|
50
|
+
The models that the record names: `gemini-3.8-flash`, `gemini-3.5-flash-lite`,
|
|
51
|
+
`gemini-3.1-flash-lite`, `gemini-2.5-flash-lite`, and, for whole-file reads on a model that thinks,
|
|
52
|
+
Gemini 4 Hydrogen. In 0.5.0, thinking Gemini models that the record does not name also ran, alone
|
|
53
|
+
and with an explorer. The explorer checks of 0.3.5 did not include models larger than Flash-Lite,
|
|
54
|
+
or Gemini 4, and the checks of pages (0.3.0) did not include Gemini 4.
|
|
55
|
+
|
|
56
|
+
The provider guides say what this means for your setup: [Vertex AI and the Gemini
|
|
57
|
+
API](./guides/vertex-and-gemini.md), [OpenAI-compatible endpoints](./guides/openai-compatible.md),
|
|
58
|
+
[Claude](./guides/anthropic.md).
|
|
59
|
+
|
|
60
|
+
## Large files with one model (0.1.0)
|
|
61
|
+
|
|
62
|
+
`gemini-3.8-flash` on the Gemini API, November 2026:
|
|
63
|
+
|
|
64
|
+
| File | Question | Result |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| A log of 5 MB and 60,000 lines, about 1.27M tokens: over the 1M window | "What caused the outage?" | The right root cause, failover time and affected services, citing the right lines (checked with grep). About 60 s, 11 tool calls, about 15K prompt tokens per turn. The model read straight to the FATAL line that the card listed. |
|
|
67
|
+
| A novel of 467 KB, about 117K tokens | "Where was the ledger hidden?" | Sent whole. Right. Estimated at 116,840 tokens; Gemini billed 116,842. |
|
|
68
|
+
| The same novel, read whole in parts of 40K tokens | "Read all of it…" | 4 parts, read in parallel, 1 of them relevant. A right answer that cited line 2036, in 32 s. |
|
|
69
|
+
|
|
70
|
+
The token counts of the two files are the estimate of 0.1.0, four characters a token. That rule
|
|
71
|
+
counted logs low, and the estimate of today counts a log as far more tokens
|
|
72
|
+
([Token estimates](#token-estimates-020)). For prose it was close, as the novel shows.
|
|
73
|
+
|
|
74
|
+
Live testing of 0.1.0 (model not recorded) also showed that Gemini can ignore
|
|
75
|
+
`functionCallingConfig: { mode: "NONE" }`: it kept calling tools on the turn meant to force an
|
|
76
|
+
answer. So the request that must be answered in text declares no tools to Gemini
|
|
77
|
+
([How it works](./how-it-works.md)).
|
|
78
|
+
|
|
79
|
+
## Token estimates (0.2.0)
|
|
80
|
+
|
|
81
|
+
Until 0.2.0, `estimateTokens` counted four characters a token. That holds for prose only: Gemini
|
|
82
|
+
counts about one token per digit. A service log was estimated at 37% of its real count and a CSV of
|
|
83
|
+
numbers at 26%, so such files were sent whole, and split into parts, at about three times the
|
|
84
|
+
configured budget.
|
|
85
|
+
|
|
86
|
+
The estimate of 0.2.0, which is still the one in the code, prices each kind of character. Its
|
|
87
|
+
weights were fitted to Gemini's `countTokens` on 60 texts: prose in eleven languages, source code,
|
|
88
|
+
JSON, CSV and eight log formats. Gemini 2.5, 3.5 and 3.8 count them identically. On those texts
|
|
89
|
+
the estimate is between 0.98 and 1.7 times Gemini's count. The one kind of text it counts low, at
|
|
90
|
+
about 70%, is a long run of random letters in one case with no digits.
|
|
91
|
+
|
|
92
|
+
Characters per token, as Gemini counts them:
|
|
93
|
+
|
|
94
|
+
| Text | Characters per token |
|
|
95
|
+
|---|---|
|
|
96
|
+
| English prose | 4.3 to 5.0 |
|
|
97
|
+
| Source code | 3.5 to 4.1 |
|
|
98
|
+
| Hebrew, Arabic, Russian prose | 2.1 to 3.3 |
|
|
99
|
+
| Chinese, Japanese, Korean prose | 1.4 to 1.7 |
|
|
100
|
+
| Logs (timestamps, IDs, IP addresses) | 1.4 to 2.8 |
|
|
101
|
+
| CSV of numbers, hex dumps, base64 | 1.0 to 1.4 |
|
|
102
|
+
|
|
103
|
+
Other providers' tokenizers were not measured. The `tokenScale` of 1.35 that `anthropic()` assumes
|
|
104
|
+
is a cautious guess, not a measurement: during a question the loop corrects it by the count the API
|
|
105
|
+
reports ([Costs and limits](./guides/costs-and-limits.md)).
|
|
106
|
+
|
|
107
|
+
## Reading a whole file
|
|
108
|
+
|
|
109
|
+
**Counting and listing (0.2.0, live, model not recorded).** A whole-file read was asked to list
|
|
110
|
+
every one of 1,200 matching lines: 492 came back, and the result said that it was incomplete. The
|
|
111
|
+
notes of a part were capped at 4,096 output tokens and the answer at 8,192, as they still are for
|
|
112
|
+
a model that does not think. Even without reaching a cap, the model can skip items: 91 of 120 in
|
|
113
|
+
the same test. Since 0.6.0 the tool guide sends counting and listing to `search_document` in exact
|
|
114
|
+
or regex mode, whose `total_matching_lines` is exact ([Tools](./reference/tools.md)).
|
|
115
|
+
|
|
116
|
+
**A count by exact search (main, live on Vertex AI, 2026-11-16).** `gemini-3.1-flash-lite`,
|
|
117
|
+
asked "how many ERROR lines say the payment gateway timed out" about a generated log of 4,000
|
|
118
|
+
lines, answered with one exact search: 40, the right count, with the first and last lines (100 and
|
|
119
|
+
4,000). After the merge of those changes, the packed package, installed in a clean folder, did
|
|
120
|
+
the same on a log of 2,000 lines: one exact search, 20, lines 100 and 2,000, in two requests and
|
|
121
|
+
5,531 input tokens. In that run a model that does not exist was refused as kind `"invalid"`, and
|
|
122
|
+
the request was sent once.
|
|
123
|
+
|
|
124
|
+
**The last match of a count (the 0.6 review, live on Vertex AI, 2026-11-20).**
|
|
125
|
+
`gemini-3.1-flash-lite` was asked how many PAY-5031 errors payments-api logged in a production log
|
|
126
|
+
of 3 MB, and on which lines the first and the last were. An exact search for "PAY-5031" found 884
|
|
127
|
+
lines, and a regex for the lines that payments-api wrote itself found 442. The count was right, and
|
|
128
|
+
so was the first line (11,355), but the model could not tell the last. That question took 11
|
|
129
|
+
requests, 3 of them repeats answered with pointers. Asked in a follow-up to run the search again
|
|
130
|
+
and confirm the count, it named line 12,088 as the last, in 6 requests. It was line 15,269. The
|
|
131
|
+
searches had shown the model their first matching lines and the total, and nothing of where the
|
|
132
|
+
others were. Since 0.6.0 an exact or regex search also shows the last matching line, with a note
|
|
133
|
+
that says how many of how many are shown ([How it works](./how-it-works.md#tools)). This page
|
|
134
|
+
records no live run of 0.6.0 on that log.
|
|
135
|
+
|
|
136
|
+
**Models that think (0.4.1, live).** Such a model counts its thoughts in `maxOutputTokens`. Asked
|
|
137
|
+
for 4,096 tokens of notes on a part of a log, Gemini 3.8 Flash spent 3,931 of them thinking and
|
|
138
|
+
wrote 317 characters, and Gemini 4 Hydrogen wrote none. With a second request at 32,768 tokens
|
|
139
|
+
(`THINKING_OUTPUT_TOKENS`), both models returned whole notes, and an answer cited all 70 matching
|
|
140
|
+
lines of a log read in three parts.
|
|
141
|
+
|
|
142
|
+
**The overview (0.4.1).** Before 0.4.1, `get_document_overview` read the whole file to count the
|
|
143
|
+
parts of a whole-file read: 60 MB of reads and 0.7 s for a log of 60 MB. It now works them out
|
|
144
|
+
from the metadata. The number is the count, or within a few percent of it.
|
|
145
|
+
|
|
146
|
+
**Reads of one turn run together (0.5.0, against a fake model).** Six whole-file reads, two in each
|
|
147
|
+
of three turns, took 841 ms one after another and about 540 ms run together.
|
|
148
|
+
|
|
149
|
+
**Reads asked for again (0.5.0, a probe).** A model asked for the same file to be read whole six
|
|
150
|
+
times in one question. Since 0.5.0, `limits.wholeDocumentReads` allows one read of each document
|
|
151
|
+
by default ([Costs and limits](./guides/costs-and-limits.md)).
|
|
152
|
+
|
|
153
|
+
## An explorer model (0.3.5)
|
|
154
|
+
|
|
155
|
+
Flash-Lite models, November 2026, through `ingest` and `askGemini`. The log has 6,000 lines, 24
|
|
156
|
+
deadlocks and one fatal error. The PDF is the one with a chart and a photo from
|
|
157
|
+
[Pages of PDFs](#pages-of-pdfs-030).
|
|
158
|
+
|
|
159
|
+
| Explorer → `model` | Question | Result |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| `gemini-3.5-flash-lite` → `gemini-3.1-flash-lite`, Gemini API | How many deadlocks, and the line of the first | Two searches, then `DONE`. Answer right. Four requests, 3 s. |
|
|
162
|
+
| | What shut the gateway down, its error code, the warning before it | One search, then `DONE`. Four of four facts, with the right lines. |
|
|
163
|
+
| | The name of the file and its line count, which the card shows | `DONE` at once. Answered from the card, in two requests. |
|
|
164
|
+
| | Every kind of error, from a whole-file read | The explorer read the four parts and wrote up the notes, then searched three times. Answer right. |
|
|
165
|
+
| | The chart and the photo, with the text sent whole | The explorer looked at two pages. The other model got them and had five of five facts right. |
|
|
166
|
+
| | The same, with the PDF searched | A read and a look in one turn. Five of five. |
|
|
167
|
+
| | The gateway and the chart again, both models thinking (`thinkingLevel: "high"`) | Both right. |
|
|
168
|
+
| `gemini-3.1-flash-lite` → `gemini-3.5-flash-lite`, Gemini API | The deadlocks | Answer right. The explorer repeated one search until its eleven requests were used up, as it does when it works alone. |
|
|
169
|
+
| `gemini-2.5-flash-lite` → `gemini-3.5-flash-lite`, Vertex AI | The deadlocks, the gateway, and the chart with pages `"beside"` | All right. This explorer wrote an answer each time instead of `DONE`. |
|
|
170
|
+
| `gemini-3.5-flash-lite` → `gemini-2.5-flash-lite`, Vertex AI | The deadlocks, the chart with pages `"beside"`, and the card | All right. |
|
|
171
|
+
| `gemini-3.1-flash-lite` → `gemini-3.5-flash-lite`, Vertex AI, both thinking | The gateway | Right. |
|
|
172
|
+
|
|
173
|
+
In the eleven checks with `gemini-3.5-flash-lite` exploring, the answering model was right every
|
|
174
|
+
time, from what the explorer found.
|
|
175
|
+
|
|
176
|
+
- `gemini-3.5-flash-lite` as explorer replied `DONE` each time, at one output token.
|
|
177
|
+
`gemini-2.5-flash-lite` wrote an answer instead, which costs those output tokens and is dropped.
|
|
178
|
+
- Given a `thinkingLevel`, `gemini-2.5-flash-lite` on Vertex AI answers HTTP 400, "thinking_level
|
|
179
|
+
is not supported by this model". That is what `explorerGenerationConfig` is for.
|
|
180
|
+
- A Gemini 3 model refuses a request that ends with the result of a function call it did not sign
|
|
181
|
+
(HTTP 400, "Function call is missing a thought_signature"). When a user message follows the
|
|
182
|
+
results, the same calls are accepted without a signature: by Gemini 3.1 and 3.5 Flash-Lite on
|
|
183
|
+
the Gemini API and on Vertex AI, and by Gemini 2.5 Flash-Lite on Vertex AI. So the answering
|
|
184
|
+
model's request always ends with a user message.
|
|
185
|
+
- Not checked: models larger than Flash-Lite, and Gemini 4. With `askGemini` the explorer is
|
|
186
|
+
called with the endpoint's headers, so no check paired a model on the Gemini API with one on
|
|
187
|
+
Vertex AI.
|
|
188
|
+
|
|
189
|
+
In 0.5.0 an explorer behind Gemini's OpenAI layer, with a thinking Gemini model answering, was
|
|
190
|
+
also run live on the Gemini API ([Checks of 0.5.0](#checks-of-050)).
|
|
191
|
+
|
|
192
|
+
On main, on Vertex AI (2026-11-16), `gemini-3.5-flash-lite` explored and `gemini-3.1-flash-lite`
|
|
193
|
+
answered "What was the FATAL error, and what warning came shortly before it?" about the generated
|
|
194
|
+
log of 4,000 lines: the answer cited the FATAL line (3,210) and the warning 11 lines before it
|
|
195
|
+
(3,199). With the count and the repeated search of the same run, the three questions took 8
|
|
196
|
+
requests, 45,152 input tokens (7,755 cached) and 537 output tokens. The
|
|
197
|
+
[Explorer model guide](./guides/explorer-model.md) explains who does what and what it costs.
|
|
198
|
+
|
|
199
|
+
## Pages of PDFs (0.3.0)
|
|
200
|
+
|
|
201
|
+
### On the Gemini API
|
|
202
|
+
|
|
203
|
+
`gemini-3.5-flash-lite` on the Gemini API, November 2026, through `ingest` and `askGemini`:
|
|
204
|
+
|
|
205
|
+
| Check | Result |
|
|
206
|
+
|---|---|
|
|
207
|
+
| Which bar of a chart is tallest and shortest, and their colours; a number on a sign in a photo. Text sent whole. | Looked at 2 pages unasked. All five facts right, in 3 s. From the text alone, the model said that it could not see the chart. |
|
|
208
|
+
| The same, with the PDF searched instead | One look, all five right. |
|
|
209
|
+
| Ten questions that the text answers, about a PDF with a photo on each of its 60 pages | 0 of 10 looked at a page, with the text sent whole and with the PDF searched. 10 of 10 right both times. |
|
|
210
|
+
| A chart in one colour: a caption, but no mark | The model looked at the page and read the chart correctly. |
|
|
211
|
+
| Five pages in one look (five numbers on five signs) | All five right. 2,660 tokens for the pages. |
|
|
212
|
+
| A slide deck of 41 slides: a number on slide 8, a bar on slide 1 | Two looks, both right. |
|
|
213
|
+
| A PDF encrypted to restrict printing | One look, all right. |
|
|
214
|
+
| A scan of three pages (pictures of text) | One look at the three pages. Four of four facts right. |
|
|
215
|
+
| The request without tools that ends a question, after a look | Accepted, answered correctly, with the pages still in it. |
|
|
216
|
+
|
|
217
|
+
### On Vertex AI
|
|
218
|
+
|
|
219
|
+
The same model on Vertex AI, in the locations `global` and `eu`, November 2026: one look, two looks
|
|
220
|
+
in one model turn, one look that decides the next, the request without tools that ends a question,
|
|
221
|
+
and a PDF that is searched. All were accepted and answered correctly, with `vertexAi()` and through
|
|
222
|
+
an application's own URLs, streaming and not. Real files went through too: a number on a photo in a
|
|
223
|
+
report of 7.5 MB written by Word, and five numbers from one look at five pages of a file of 25 MB
|
|
224
|
+
(a PDF of 2.2 MB in the request).
|
|
225
|
+
|
|
226
|
+
### Where the pages go
|
|
227
|
+
|
|
228
|
+
| `toolFilePlacement` | Gemini 3.5 Flash-Lite, on the Gemini API and on Vertex AI | Gemini 2.5 Flash-Lite, on Vertex AI |
|
|
229
|
+
|---|---|---|
|
|
230
|
+
| `"inside"` (the default) | Works | Accepted and counted, but the model does not see the pages: it answers that it cannot see them |
|
|
231
|
+
| `"beside"` | Works | Works |
|
|
232
|
+
|
|
233
|
+
Vertex AI refuses a turn in which anything follows a function response (HTTP 400, "Requests ending
|
|
234
|
+
with a model turn are not supported", seen with Gemini 3.5), so with `"beside"` the pages have a
|
|
235
|
+
turn of their own. Not checked: Gemini 2.5 on the Gemini API, and Gemini 4.
|
|
236
|
+
|
|
237
|
+
### What a page costs the model
|
|
238
|
+
|
|
239
|
+
A page costs Gemini about 530 tokens, whatever is on it: 532 for each of 1, 2, 3 and 5 A4 pages,
|
|
240
|
+
and 527 for a 16:9 slide (`gemini-3.5-flash-lite`). On Vertex AI it was 532 as well. The default
|
|
241
|
+
`pageTokens` of `gemini()`, `GEMINI_PAGE_TOKENS`, is 530 ([gemini reference](./reference/gemini.md)).
|
|
242
|
+
|
|
243
|
+
### What a cut weighs
|
|
244
|
+
|
|
245
|
+
`view_pages` cuts the pages out of the kept file. Copied the simple way, a contents page took every
|
|
246
|
+
page it links to: the cut was 89% of the file, and the contents page of a report of 7.5 MB came
|
|
247
|
+
out at 6.7 MB. Cut the way the library does it:
|
|
248
|
+
|
|
249
|
+
| File | Pages cut | Size of the cut |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| Chrome, 72 photos, 100 MB | 5 | 7.0 MB (7%) |
|
|
252
|
+
| PowerPoint deck, 40 photos, 9.9 MB | 5 | 1.2 MB (13%) |
|
|
253
|
+
| Word report with a contents page, 7.5 MB | the contents page | 55 KB (0.7%) |
|
|
254
|
+
| All images in one shared list, 12 MB | 2 | 0.6 MB (5%) |
|
|
255
|
+
|
|
256
|
+
### What a cut costs the server
|
|
257
|
+
|
|
258
|
+
The whole file is read into memory on every call:
|
|
259
|
+
|
|
260
|
+
| File | Time | Memory at the peak |
|
|
261
|
+
|---|---|---|
|
|
262
|
+
| 100 MB of photos, 900 objects | 0.06 s | about 300 MB |
|
|
263
|
+
| 100 MB written the way Ghostscript writes | 3 s | about 300 MB |
|
|
264
|
+
| 54 MB, 330,000 objects (a tagged table of 591 pages) | 4 to 5 s | about 700 MB |
|
|
265
|
+
|
|
266
|
+
Memory is about twice the size of the file, plus 1.0 to 1.6 KB for each object in it, measured on
|
|
267
|
+
files of 300,000 objects. Reading cannot be interrupted once it has started: 1 MB of junk
|
|
268
|
+
between two objects took 3.6 seconds to skip. [Security](./security.md) and
|
|
269
|
+
[Deployment](./guides/deployment.md) say what to do about it.
|
|
270
|
+
|
|
271
|
+
### Marking the pages that show a picture
|
|
272
|
+
|
|
273
|
+
The marks are found from the structure of the file, without decoding any image. A PDF of 200
|
|
274
|
+
photos (85 MB) took 0.3 s to ingest without marks and 0.8 s with them. A PDF whose streams do not
|
|
275
|
+
state their length (Ghostscript writes them so) is scanned byte by byte, about 30 ms per MB: a file
|
|
276
|
+
of 100 MB written that way took 3 s to ingest instead of 0.1 s. A file that declares more than
|
|
277
|
+
150,000 objects gets no marks: reading it would take over two seconds.
|
|
278
|
+
|
|
279
|
+
Before 0.3.6, a PDF of 3 KB whose forms each paint the next one 30 times ran the process out of
|
|
280
|
+
memory. Since 0.3.6 such a file is read in 0.6 s.
|
|
281
|
+
|
|
282
|
+
### The PDFs these were tested with
|
|
283
|
+
|
|
284
|
+
The features of 0.3.0 (the marks and `view_pages`) were tested with PDFs made by Chrome, Word and
|
|
285
|
+
PowerPoint. PDFs made by LaTeX and InDesign were not tested. For FPDF, Ghostscript and scanners,
|
|
286
|
+
the structures they are known to write were tested with files made for the purpose, not with files
|
|
287
|
+
from those tools. Encrypted PDFs were tested with files encrypted by the library itself, and
|
|
288
|
+
confirmed as encrypted by pdf.js.
|
|
289
|
+
|
|
290
|
+
The [PDFs guide](./guides/pdfs.md) covers the marks, `view_pages` and its limits.
|
|
291
|
+
|
|
292
|
+
## PDF tables (0.2.0)
|
|
293
|
+
|
|
294
|
+
`gemini-3.5-flash-lite`, live: 110 questions about single cells of seven PDFs made by Word and
|
|
295
|
+
Chrome, half of them about empty cells. 44 answers were right from the text in file order, and 110
|
|
296
|
+
from the rebuilt rows. The rules that find the tables were tuned on PDFs made by Chrome and by
|
|
297
|
+
Word.
|
|
298
|
+
|
|
299
|
+
What the cell marks cost: a bank statement came to 27% more tokens than its text in file order, and
|
|
300
|
+
a report with one table in it to 9% more. Reading 600 pages with 24,600 table rows took 1.6 s
|
|
301
|
+
instead of 1.3 s. See the [PDFs guide](./guides/pdfs.md).
|
|
302
|
+
|
|
303
|
+
## Conversations and the prompt cache
|
|
304
|
+
|
|
305
|
+
**Documents first (0.2.0, live, with `askGemini`, model not recorded).** With the documents at the
|
|
306
|
+
start of the first user turn, a follow-up question about a document of 53,000 tokens had 96% of its
|
|
307
|
+
input served from Gemini's cache, against 0% when the document was appended to the latest turn.
|
|
308
|
+
|
|
309
|
+
**Stored tool rounds (0.5.0, live on the Gemini API, model not recorded).** With
|
|
310
|
+
`result.toolTurns` passed back in the conversation, a follow-up question took one request instead
|
|
311
|
+
of three, and no search.
|
|
312
|
+
|
|
313
|
+
**A repeated search (main, live on Vertex AI, 2026-11-16).** With `gemini-3.1-flash-lite`, a
|
|
314
|
+
follow-up that was sent the stored tool rounds of the first question and repeated its first search
|
|
315
|
+
got a pointer to the earlier result, instead of a second run, and answered from that result.
|
|
316
|
+
|
|
317
|
+
The [Conversations guide](./guides/conversations.md) shows how to keep tool rounds.
|
|
318
|
+
|
|
319
|
+
## Usage and the size of a request
|
|
320
|
+
|
|
321
|
+
**Usage totals (0.4.0, live, model not recorded).** In a live run of 0.4.0, whose `usage` was the
|
|
322
|
+
usage of the last response only, 13,687 prompt tokens were billed and 6,398 reported. For the
|
|
323
|
+
usage of 0.5.0 against the provider's, see [Checks of 0.5.0](#checks-of-050).
|
|
324
|
+
|
|
325
|
+
**Many reads in one turn.** Before 0.4.1, sixty reads in one turn built a request of 339,000 tokens;
|
|
326
|
+
0.4.1 runs at most eight calls of a turn. Before 0.5.0, a turn of sixty reads built a request of
|
|
327
|
+
491,000 tokens against a window of 128,000; with 0.5.0 the same run peaks at about 100,000.
|
|
328
|
+
|
|
329
|
+
**The error of a request too large (main, live on Vertex AI).** Sent a request of 1.78M tokens,
|
|
330
|
+
`gemini-3.1-flash-lite` on Vertex AI answered "The input token count exceeds the maximum number of
|
|
331
|
+
tokens allowed 1048576." The library reads that as the kind `"context_overflow"`, with a
|
|
332
|
+
`limitTokens` of 1,048,576 ([Errors and reliability](./guides/errors-and-reliability.md)).
|
|
333
|
+
|
|
334
|
+
## The server
|
|
335
|
+
|
|
336
|
+
**Regex search (0.4.1).** A pattern that backtracks without end on a line, such as `(a|a)+$`, costs
|
|
337
|
+
about 0.8 s, not the full 3-second limit. Before 0.4.1, five such searches in one turn kept the
|
|
338
|
+
server from answering any other request for 15 seconds. Before 0.2.0, `((a+))+$` and `(a|a)+$` never
|
|
339
|
+
finished on a line of 40 characters.
|
|
340
|
+
|
|
341
|
+
**DOCX and PPTX (0.3.6).** Before 0.3.6, a DOCX of 900 bytes held the server for 8 seconds, and one
|
|
342
|
+
of 10 KB would have held it for an hour. A DOCX of 160 KB that unpacked to 50 MB of XML was stored
|
|
343
|
+
as 29 million characters; since 0.3.6 it is refused at 16 MB, in 0.2 s.
|
|
344
|
+
|
|
345
|
+
**The memory cache (0.4.0).** Before 0.4.0 the cache was bounded in documents: six documents of 50
|
|
346
|
+
MB took over 600 MB. Since 0.4.0 every use of a document kept in memory asks the store first, with
|
|
347
|
+
`getMeta`: about a millisecond.
|
|
348
|
+
|
|
349
|
+
**Sizes counted for JSON (0.4.1).** Before 0.4.1, `jsonBytes` and the planner counted text with
|
|
350
|
+
quotes, backslashes, tabs or many line breaks low: by 23% for a JSON-lines export and 31% for TSV.
|
|
351
|
+
A read of quoted text came out at 42,514 characters against a cap of 24,000.
|
|
352
|
+
|
|
353
|
+
**Memory and stalls of an ingest (main, November 2026, Node 24 on Windows, plain-text logs).**
|
|
354
|
+
Peak memory above the uploaded bytes: about 175 MB for a log of 25 MB, 270 MB for 50 MB, and 470 MB
|
|
355
|
+
for 95 MB. An ingest of the 95 MB log fitted in a worker thread of 256 MB. One exact search of the
|
|
356
|
+
95 MB log, read by range, took about 60 to 80 MB. Eight such searches at once took about 70 to 85
|
|
357
|
+
MB, and about 220 MB with `cacheBytes` at 1 GB, which keeps the decoded pieces. An ingest held the
|
|
358
|
+
event loop for about 0.8 to 1.5 seconds (25 MB) and 3 to 5 seconds (95 MB). Linux was not
|
|
359
|
+
measured. [Deployment](./guides/deployment.md) turns these into sizing advice.
|
|
360
|
+
|
|
361
|
+
**Ingest of large and hostile files (0.6.0, November 2026, Node 24 on Windows).** Each file was
|
|
362
|
+
ingested into a `MemoryDocumentStore` in a fresh process, with the parsers loaded first, 5157e7f
|
|
363
|
+
(which ingests as 0.5.0 does) and 0.6.0 in turn, on a machine that ran other work too. A stall is
|
|
364
|
+
the longest gap between two beats of a 5 ms timer; memory is the resident set at the beats, so for
|
|
365
|
+
5157e7f, whose ingests let no beat in, it is not given.
|
|
366
|
+
|
|
367
|
+
| File | 5157e7f | 0.6.0 |
|
|
368
|
+
|---|---|---|
|
|
369
|
+
| A log of 99 MB, 1,160,000 lines (3 runs each) | 1.9 to 2.0 s, all of it one stall | 1.9 s; longest stall 31 to 34 ms; 415 to 433 MB |
|
|
370
|
+
| A PDF of 2,000 pages, 30 lines each, 3.5 MB (3 runs each) | 4.6 to 4.9 s; longest stall 4.4 to 4.5 s | 4.9 to 5.0 s; longest stall 0.16 s |
|
|
371
|
+
| A DOCX of 1.5 MB holding 120 MB of empty paragraphs, heap of 512 MB (2 runs each) | Out of memory: the process stopped | Refused ("did not contain any text") in 3.0 to 3.2 s, at 115 MB |
|
|
372
|
+
| A DOCX of 3 MB that unpacks to 1,000 MB of XML, heap of 512 MB (2 runs each) | Out of memory: the process stopped | Refused at 1,000,000 paragraphs in 0.85 to 0.91 s, at 165 MB |
|
|
373
|
+
| PDFs of 3 KB and 6 KB whose page tree lists one dense page 150 and 600 times | 107 MB of text stored; 205 s held with a heap of 1.5 GB, and out of memory with 512 MB (the 0.6 review) | Refused in 0.23 s |
|
|
374
|
+
|
|
375
|
+
The 0.6 review, on files of its own, measured stalls of 3.5 s for a 100 MB log and 8.3 s for
|
|
376
|
+
a 2,000-page PDF.
|
|
377
|
+
|
|
378
|
+
Hostile files, each in a fresh process with heaps of 256 and 512 MB, 0.6.0 only (2 runs each, the
|
|
379
|
+
parsers not loaded first):
|
|
380
|
+
|
|
381
|
+
| File | 0.6.0 |
|
|
382
|
+
|---|---|
|
|
383
|
+
| PDFs of 23 KB and 95 KB whose 140 and 600 distinct pages all paint one dense content stream | Refused at 16 MB of text ("draws more than 16 MB of text, over 100 times its size") in 5.5 to 6.0 s, at 210 MB; longest stall 0.34 to 0.59 s. Without that limit, the first was stored with 99.5 MB of text after 35 to 40 s, at 430 MB. |
|
|
384
|
+
| The DOCX of 1.5 MB holding 120 MB of empty paragraphs, with JSZip loaded first | Stalls of 0.2 to 0.25 s, one after the other, for 3 s: JSZip unpacks a piece of the file in one block, and a piece packed this tight is several MB of XML. A DOCX of 4 MB written the usual way, with 32 MB of XML, never held the event loop for 30 ms. |
|
|
385
|
+
| A PDF of 650 KB whose one page runs 160 MB of text operators, packed 250 times | Read: 9 KB of text in 24 to 26 s, nearly all of it one stall of about 25 s, at 510 MB. pdf.js reads a page in one block, and neither `ingestTimeoutMs` nor a signal stops it within the page. |
|
|
386
|
+
| A PDF of 160 KB of three pages that each run 40 MB | Read in 17 s, with one stall of 11 s. |
|
|
387
|
+
|
|
388
|
+
These last two, measured without the page check, are why it was written (below), and why
|
|
389
|
+
[Deployment](./guides/deployment.md#uploads-and-ingest) ingests files you do not trust in a process
|
|
390
|
+
of their own.
|
|
391
|
+
|
|
392
|
+
**The page check (0.6.0, November 2026, Node 24 on Windows).** Each file ingested into a
|
|
393
|
+
`MemoryDocumentStore` in a fresh process with the parsers loaded first, without the check (the
|
|
394
|
+
0.6.0 code before it; one or two runs) and with it (one run). Time is the whole ingest; the stall
|
|
395
|
+
is the longest gap between two beats of a 5 ms timer.
|
|
396
|
+
|
|
397
|
+
| File | Without the check | With the check |
|
|
398
|
+
|---|---|---|
|
|
399
|
+
| 2.8 KB: one page paints a form that paints the next 50 times, 3 deep (125,000 forms with text) | Read in 13 to 14 s, one stall of 13 to 14 s, at 345 to 380 MB | Refused in 15 ms, at 68 MB |
|
|
400
|
+
| 2.2 to 2.3 KB, the same 4, 5 and 6 deep (20, 12 and 8 times) | Read in 17 to 36 s, nearly all of it one stall, at 385 to 470 MB | Refused in 14 to 19 ms |
|
|
401
|
+
| 4.3 KB and 21 KB, the same 3 deep 100 times, and 2 deep 1,000 times (1,000,000 forms) | Refused once read, for 16 MB of text, after 95 to 119 s, all of it one stall | Refused in 19 and 22 ms |
|
|
402
|
+
| 636 KB: one page runs 160 MB of text operators, packed 250 times | Read in 23 to 29 s, one stall of 23 to 29 s, at 420 MB | Refused in 54 ms; longest stall 20 ms |
|
|
403
|
+
| 160 KB: three pages each run 40 MB | Read in 18 to 22 s, longest stall 6 to 14 s | Refused in 32 ms |
|
|
404
|
+
| 2.9 KB: a Type3 glyph paints a form 390,000 times, through forms inside forms | Read in 9.1 s, one stall of 9.0 s, at 730 MB | Refused in 17 ms, at 68 MB |
|
|
405
|
+
| 2.6 KB: eight forms with text that each paint all eight | Read in 5.8 to 6.0 s, one stall | Refused in 42 ms |
|
|
406
|
+
| 2.9 KB: forms inside forms, painted from content stored with a predictor | Read in 9.7 to 10.0 s, one stall | Refused in 20 ms |
|
|
407
|
+
| 23 KB: 140 pages show one dense content stream | Refused at 16 MB of text after 5.8 s; longest stall 0.53 s | Refused in 26 ms |
|
|
408
|
+
| 25 KB: 60 pages show one stream of 4 MB | Read in 38 s; a stall of 1.3 s a page | Refused in 35 ms |
|
|
409
|
+
|
|
410
|
+
The check found the pages of the documents tested at 11% of the limit at most. Under 2%: PDFs
|
|
411
|
+
printed by Chrome, Word and PowerPoint (10,000 to 150,000 units a page), books of 300 to 2,000
|
|
412
|
+
pages (10,000), a 3,000-page file of 60,000 objects (under 5,000), and 300 pages of 1,500 filled
|
|
413
|
+
shapes each (180,000). Under 11%: Edge printing a table of 6,000 rows, an SVG chart of 30,000
|
|
414
|
+
points (16.6 million units in a 4.6 MB file; pdf.js read the page in 0.32 s), 5,000 SVG icons,
|
|
415
|
+
30 fonts, and pages of CSS gradients and shadows; matplotlib saving a scatter plot of 50,000
|
|
416
|
+
points, a 40-page report of 16 charts a page, and 600,000 points of lines.
|
|
417
|
+
|
|
418
|
+
A form painted for its text counts 640 units, about 0.1 ms. pdf.js took 75 to 85 µs a form,
|
|
419
|
+
warm: 0.84 s for a page that paints one small form with text 10,000 times, 0.79 s for forms
|
|
420
|
+
inside forms 100 times 2 deep, 1.26 s for 25 times 3 deep, and 1.70 s for 12 times 4 deep. The
|
|
421
|
+
first two are read, the last two refused. Files built to make the check itself work hard are
|
|
422
|
+
checked fast: 300 pages whose resources all point to one list of 140,000 drawings in 0.16 s, and
|
|
423
|
+
a page that may paint any of 140,000 drawings 100 times in 0.42 s. Their longest stall, 0.1 to
|
|
424
|
+
0.15 s, is reading the list once, about as long as `@cantoo/pdf-lib` takes to parse it.
|
|
425
|
+
|
|
426
|
+
The 14 inputs of the identity check of 0.6.0 (logs of 10 to 100 MB, JSONL, CSV,
|
|
427
|
+
Markdown, and the PDFs below with and without picture marks) store byte for byte the text, index
|
|
428
|
+
and metadata that 5157e7f stores. What the check adds to an ingest:
|
|
429
|
+
|
|
430
|
+
PDFs written with `@cantoo/pdf-lib` (pages of 45 lines of text, or of 1,500 small filled shapes),
|
|
431
|
+
ingested into a `FileDocumentStore` with originals kept, without the check and with it in turn,
|
|
432
|
+
three runs each: the median, and the range. A warm process ingests the file a second time, the
|
|
433
|
+
parsers already loaded; a fresh one loads them during the ingest. Peak memory is that of the
|
|
434
|
+
process.
|
|
435
|
+
|
|
436
|
+
| PDF | Picture marks | Ingest, warm: without / with | Longest stall, warm | Ingest, fresh process | Longest stall, fresh | Peak memory, fresh |
|
|
437
|
+
|---|---|---|---|---|---|---|
|
|
438
|
+
| 300 pages, 1 MB | on | 0.91 / 0.91 s | 50 / 46 ms | 1.48 / 1.56 s | 0.44 / 0.41 s | 169 / 169 MB |
|
|
439
|
+
| 300 pages | off | 0.84 / 0.93 s | 54 / 61 ms | 1.00 / 1.49 s | 0.13 / 0.41 s | 146 / 159 MB |
|
|
440
|
+
| 1,000 pages, 3.2 MB | on | | | 4.03 / 3.91 s | 0.50 / 0.43 s | 323 / 332 MB |
|
|
441
|
+
| 1,000 pages | off | | | 3.25 / 4.16 s | 0.22 / 0.47 s | 258 / 325 MB |
|
|
442
|
+
| 2,000 pages, 6.4 MB | on | 6.27 [5.99 to 8.01] / 7.26 [6.20 to 7.47] s | 0.18 / 0.19 s | 7.93 / 8.19 s | 0.52 / 0.49 s | 418 / 443 MB |
|
|
443
|
+
| 2,000 pages | off | 6.05 / 6.37 s | 0.19 / 0.19 s | 7.02 / 8.29 s | 0.33 / 0.49 s | 345 / 436 MB |
|
|
444
|
+
| 300 pages of drawings, 3 MB | on | 3.86 / 4.07 s | 40 / 33 ms | 5.08 / 4.87 s | 0.51 / 0.47 s | 315 / 323 MB |
|
|
445
|
+
| 300 pages of drawings | off | | | 2.95 / 3.64 s | 0.13 / 0.49 s | 87 / 154 MB |
|
|
446
|
+
|
|
447
|
+
With picture marks on, the file was read with `@cantoo/pdf-lib` before too, after the text: the
|
|
448
|
+
check itself took 31 ms for 300 pages of text, 0.11 s for 300 pages of drawings and 0.25 s for
|
|
449
|
+
2,000 pages, inside the spread of the runs. With them off, that reading is new: in a warm process
|
|
450
|
+
0.08 s for 300 pages and 0.3 s for 2,000. In a fresh process, the first PDF also loads
|
|
451
|
+
`@cantoo/pdf-lib`, one block of about 0.4 s: the longest stall of a fresh process with
|
|
452
|
+
`pictures: false` is that load, which a server that loads the parsers when it starts does not pay
|
|
453
|
+
([Deployment](./guides/deployment.md#uploads-and-ingest)).
|
|
454
|
+
|
|
455
|
+
**Heap limits of workers and child processes (0.6.0, Node 24 on Windows).** The heap limit a
|
|
456
|
+
thread sees (`v8.getHeapStatistics().heap_size_limit`), with `resourceLimits:
|
|
457
|
+
{ maxOldGenerationSizeMb: 512 }` on a worker or `--max-old-space-size=512` on a forked child:
|
|
458
|
+
|
|
459
|
+
| The parent runs with | Worker | Forked child |
|
|
460
|
+
|---|---|---|
|
|
461
|
+
| No heap flag | 704 MB | 704 MB |
|
|
462
|
+
| `--max-old-space-size=1024`, on the command line or in `NODE_OPTIONS` | 1,216 MB, the parent's | 704 MB |
|
|
463
|
+
|
|
464
|
+
`execArgv: []` or a cleared `NODE_OPTIONS` on the worker left it at 1,216 MB. In the 0.6
|
|
465
|
+
review, a worker of 512 MB with no heap flag on the parent ran out of memory on a hostile DOCX and
|
|
466
|
+
stopped the whole process. With the recipe of [Deployment](./guides/deployment.md#uploads-and-ingest),
|
|
467
|
+
a child forked with a heap of 48 MB ran out of memory on the 2,000-page PDF and stopped alone: the
|
|
468
|
+
upload was answered with an error, and the next one was ingested.
|
|
469
|
+
|
|
470
|
+
**Text files that are not UTF-8 (0.6.0, November 2026, Node 24 on Windows).** 0.5.0 read such a
|
|
471
|
+
file as UTF-8, in one go, with every letter of the older encoding stored as U+FFFD. 0.6.0 looks at
|
|
472
|
+
its lines, chooses an encoding, and decodes in steps of about a megabyte, with pauses in between.
|
|
473
|
+
|
|
474
|
+
A log of 77 MB in windows-1255, 1,002,740 lines each with a Hebrew name, and the same lines in
|
|
475
|
+
UTF-8 (84 MB), each ingested into a `MemoryDocumentStore` in a fresh process, in turn, nine runs
|
|
476
|
+
each, in two sessions of 2026-11-21, on a machine that ran other work too. The stall is the longest
|
|
477
|
+
gap between two beats of a 5 ms timer, and memory the peak resident set at the beats:
|
|
478
|
+
|
|
479
|
+
| Log | Ingest | Longest stall | Memory |
|
|
480
|
+
|---|---|---|---|
|
|
481
|
+
| 77 MB in windows-1255 | 2.8 to 4.0 s | 34 to 73 ms | 462 to 485 MB |
|
|
482
|
+
| The same lines in UTF-8, 84 MB | 2.5 to 3.5 s | 63 to 119 ms | 458 to 477 MB |
|
|
483
|
+
|
|
484
|
+
The second session (six runs each) took about a quarter longer than the first, with stalls up to
|
|
485
|
+
twice as long, under other load on the machine. In both, the windows-1255 log took longer on
|
|
486
|
+
average than its UTF-8 copy, and its stalls were shorter.
|
|
487
|
+
|
|
488
|
+
The decoder alone, on files of 30 MB, in a fresh process, three times, two passes each (the first
|
|
489
|
+
pass also builds the tables of the encodings):
|
|
490
|
+
|
|
491
|
+
| File of 30 MB | Before: whole time, longest step | 0.6.0: whole time, longest step |
|
|
492
|
+
|---|---|---|
|
|
493
|
+
| All in windows-1255 | 265 to 293 ms, 27 to 42 ms | 274 to 284 ms, 13 to 14 ms |
|
|
494
|
+
| Rows of ASCII and of windows-1255, and one row of UTF-8 | 215 to 234 ms, 23 to 36 ms, with the UTF-8 row read wrong | 348 to 372 ms, 21 to 22 ms |
|
|
495
|
+
| Lines with accents, of windows-1252 and of UTF-8 in turn, 100 bytes each, with one windows-1252 line more (with as many of each, the file is read as UTF-8) | 203 to 298 ms, 25 to 44 ms, with the UTF-8 lines read wrong | 495 to 532 ms, 9 to 21 ms |
|
|
496
|
+
| One row of UTF-8, then one line of 30 MB in windows-1255 | 247 to 275 ms, 13 to 16 ms | 291 to 320 ms, 17 to 19 ms |
|
|
497
|
+
| Lines of one letter, of windows-1252 and of UTF-8 in turn | 294 to 345 ms, 27 to 45 ms | 2,089 to 2,212 ms, 12 to 21 ms |
|
|
498
|
+
| CESU-8 (emoji as halves of surrogate pairs) | 195 to 266 ms, 16 to 34 ms, read as windows-1252 | 132 to 140 ms, 17 to 22 ms |
|
|
499
|
+
|
|
500
|
+
"Before" read a file with lines in both encodings whole in the older one. Reading each line in its
|
|
501
|
+
own encoding costs 1.6 times the time on a mixed CSV, about twice on lines that all take turns, and
|
|
502
|
+
7 times on lines of one letter, all of it spread over pauses. A whole ingest of the mixed CSV took
|
|
503
|
+
1,064 to 1,072 ms (two runs). The longest stalls of these whole ingests, 63 to 197 ms before and
|
|
504
|
+
after, came from later steps of the ingest, not from the decoder. Before the pauses between the
|
|
505
|
+
encodings it tries, choosing one held the event loop for 45 to 90 ms in one block the first time a
|
|
506
|
+
process met such a file.
|
|
507
|
+
|
|
508
|
+
**Cleaning a long line (0.6.0, November 2026, Node 24 on Windows).** Ingest cleans the text a
|
|
509
|
+
slice at a time, but a slice runs on to the next line break, so a text with no line break was
|
|
510
|
+
cleaned in one go. Each file below is one line of 30 MB, ingested into a `MemoryDocumentStore` in a
|
|
511
|
+
fresh process for each run, on a machine that ran other work too: the longest stall, and the peak
|
|
512
|
+
memory of the process. 5157e7f, which cleans text as 0.5.0 does, is given where it was measured; it
|
|
513
|
+
removed fewer characters, and held the event loop for the whole ingest.
|
|
514
|
+
|
|
515
|
+
| One line of 30 MB | 5157e7f | Before | 0.6.0 |
|
|
516
|
+
|---|---|---|---|
|
|
517
|
+
| A zero-width space between letters | 357 to 370 ms | 931 to 1,061 ms, 721 to 809 MB | 34 to 52 ms, 195 to 196 MB |
|
|
518
|
+
| A control character between letters | 1,856 to 1,887 ms, 761 MB | 2,014 to 3,428 ms, 1,497 to 1,567 MB | 71 to 76 ms, 248 to 250 MB |
|
|
519
|
+
| Soft hyphens alone | | 792 to 891 ms, 496 to 501 MB | 40 ms, 193 MB |
|
|
520
|
+
| Tag characters and variation selectors in turn | | 634 to 705 ms, 464 to 470 MB | 40 to 51 ms, 220 to 269 MB |
|
|
521
|
+
| `a` and `ESC [0m` in turn | 671 to 726 ms | 455 to 488 ms, 413 MB | 31 to 36 ms, 211 to 217 MB |
|
|
522
|
+
| `a` and `U+009B 1m` in turn | 467 ms | 573 to 656 ms, 427 MB | 42 to 55 ms, 245 to 260 MB |
|
|
523
|
+
|
|
524
|
+
With a heap of 1 GB, a line of 99 MB with a zero-width space or a control character between its
|
|
525
|
+
letters ran the process out of memory before; 0.6.0 held the event loop for 97 to 118 ms, at 467
|
|
526
|
+
to 476 MB. With `U+009B 1m` in turn, 2.1 to 2.3 s at 1.1 GB before, and 0.11 to 0.13 s at 542 to
|
|
527
|
+
547 MB. The text stored is the same. The rows of escape sequences were measured with the final
|
|
528
|
+
code; the other rows with a first version of it, which cleans those characters the same way, and
|
|
529
|
+
which the final code matched within the spread.
|
|
530
|
+
|
|
531
|
+
**Hidden text in Word (0.6.0, November 2026, Node 24 on Windows).** A hidden line longer than about
|
|
532
|
+
1,950 characters is cut into marked pieces. Before, the end of the line was looked for again for
|
|
533
|
+
each piece, so the work grew with the square of the line, in one block. Each DOCX ingested into a
|
|
534
|
+
`MemoryDocumentStore` in a fresh process, one run of 0.6.0 each:
|
|
535
|
+
|
|
536
|
+
| DOCX | Before | 0.6.0 |
|
|
537
|
+
|---|---|---|
|
|
538
|
+
| 16.7 KB, one hidden run of 16 million letters | 11.3 to 14.5 s (four runs), nearly all of it one stall | 0.55 s, longest stall 0.18 s |
|
|
539
|
+
| 348 KB, one hidden run of 16 million characters of words | 11.7 s, one stall of 11.3 s | 0.53 s, longest stall 74 ms |
|
|
540
|
+
| 1.48 MB, one hidden run of 134 million characters, refused for its text | 722 s | 0.75 s, longest stall 0.30 s, the same refusal |
|
|
541
|
+
|
|
542
|
+
5157e7f, which reads a DOCX as 0.5.0 does and did not mark hidden text, read the 16.7 KB file in
|
|
543
|
+
0.46 to 0.54 s (three runs).
|
|
544
|
+
Marking the 16 million letters alone took 92 ms (10.1 s before). Reading the XML of 200,000 runs,
|
|
545
|
+
formatted, hidden or neither, took the same time before and after, within the spread (0.6 to 0.8 s,
|
|
546
|
+
five rounds).
|
|
547
|
+
|
|
548
|
+
**Reading a PDF into objects, and looks at pages (0.6.0, November 2026, Node 24 on Windows).**
|
|
549
|
+
`@cantoo/pdf-lib` reads the whole file into objects for the page check and the picture marks at
|
|
550
|
+
ingest, and for each look of `view_pages`. 0.6.0 makes it pause after every 12 ms of work, or up to
|
|
551
|
+
40 ms where a pause itself takes long, as a timer does on Windows. Before, it paused after a count
|
|
552
|
+
of 500 objects (0.5.0 and 5157e7f: 4,000). The stall is the longest the event loop was held:
|
|
553
|
+
|
|
554
|
+
| Read into objects | Before: count of 500 | 0.6.0: by time |
|
|
555
|
+
|---|---|---|
|
|
556
|
+
| A file of 4,000 large arrays: longest stall | 164 to 179 ms | 28 to 32 ms |
|
|
557
|
+
| A PDF of 2,000 pages: longest stall | 32 to 106 ms | 19 to 38 ms |
|
|
558
|
+
| A file of 61,000 small objects: whole read | 1.65 to 1.87 s | 0.91 to 0.96 s |
|
|
559
|
+
| A file of large objects: whole read | 1.13 to 1.22 s | 1.35 to 1.43 s |
|
|
560
|
+
|
|
561
|
+
What `@cantoo/pdf-lib` reads in one step still holds the server. One object takes about 0.1 to
|
|
562
|
+
0.2 s for each MB of an array of numbers, more when the numbers are short: 1.1 to 1.2 s for 8 MB,
|
|
563
|
+
4.1 s for 32 MB, 9 s for 64 MB. A crafted one-page PDF of 16 MB held the server for 2.7 s at
|
|
564
|
+
ingest and 2.5 s on each look. Measured again on a busy machine, one look at 16 MB took 2.1 s with
|
|
565
|
+
numbers such as `1234.5` and 3.5 s with numbers of one digit. These ran on Node's default heap, which
|
|
566
|
+
held them. With a heap flag of 512 (two runs), 16 MB of numbers such as `1234.5` took 359 MB and
|
|
567
|
+
1.7 s at a look, and with 256 it ran out of memory there; at ingest it took 229 MB and 1.6 to
|
|
568
|
+
1.7 s with either flag (one run each). With numbers of one digit, a look took 984 MB and 2.7 to
|
|
569
|
+
2.8 s on a heap flag of 2048 (two runs). A stream whose length the file gives
|
|
570
|
+
by reference takes about 0.03 s for each MB, and a cross-reference table written as text 0.15 s
|
|
571
|
+
for 150,000 objects: the longest stall of a file of 150,000 objects was 168 to 197 ms, 151 ms of
|
|
572
|
+
it that table. Such files also take many times their size in heap, the more the shorter their
|
|
573
|
+
numbers: one array of numbers such as `1234.5` left 173 MB in use at 16 MB and 399 MB at 32 MB,
|
|
574
|
+
and one of one-digit numbers 493 MB and 929 MB. The count of objects that a file declares does not
|
|
575
|
+
show this. What such files do to a server of 256 or 512 MB is in the next paragraph.
|
|
576
|
+
|
|
577
|
+
**One object of a crafted PDF (0.6.0, November 2026, Node 24 on Windows).** pdf.js and
|
|
578
|
+
`@cantoo/pdf-lib` build each object of a PDF in one step, and nothing checks an object before it
|
|
579
|
+
is built. Each run below is a fresh process with `--max-old-space-size=256` (a heap limit of
|
|
580
|
+
448 MB) or `=512` (704 MB), twice each unless the table says otherwise. Each file is one page of
|
|
581
|
+
text and one large object that the page does not use, unless the table says otherwise. "In an
|
|
582
|
+
object stream" means packed with FlateDecode into an object stream; "unpacked twice" means with
|
|
583
|
+
`/Filter [/FlateDecode /FlateDecode]`. Ingest is the default PDF extractor, whose page check and
|
|
584
|
+
picture marks have `@cantoo/pdf-lib` read every object; "pdf.js alone" is
|
|
585
|
+
`createPdfExtractor({ checkPages: false, pictures: false })`. Heap is the most in use at a garbage
|
|
586
|
+
collection, about 20 MB of it from before the file; memory, where given, is the most the process
|
|
587
|
+
held (its peak resident set), which includes what is outside the heap; the stall is the longest the
|
|
588
|
+
event loop was held.
|
|
589
|
+
|
|
590
|
+
| File | Read by | Heap of 256 MB | Heap of 512 MB |
|
|
591
|
+
|---|---|---|---|
|
|
592
|
+
| 4 MB, one array of numbers (`[1 1 1 …]`) | Ingest | 154 MB, stall 0.7 to 0.8 s | 148 to 158 MB, 0.7 s |
|
|
593
|
+
| The same | A look at page 1 | 252 MB, 0.7 s | 268 MB, 0.7 s |
|
|
594
|
+
| 8 MB, the same | Ingest | 232 MB, 1.5 s | 243 to 244 MB, 1.5 s |
|
|
595
|
+
| The same | A look | Out of memory | 422 to 427 MB, 1.5 s |
|
|
596
|
+
| 16 MB, the same | Ingest | Out of memory | 465 MB, 3.2 s |
|
|
597
|
+
| The same | A look | Out of memory | Out of memory |
|
|
598
|
+
| 32 MB, the same | Ingest, a look | Out of memory | Out of memory |
|
|
599
|
+
| 2 MB of empty dictionaries (`[<<>> <<>> …]`) | Ingest | 167 MB, 0.4 s | 166 to 168 MB, 0.4 s |
|
|
600
|
+
| 4 MB, the same | Ingest | 290 MB, 1.0 s | 296 to 298 MB, 0.8 to 1.3 s |
|
|
601
|
+
| 8 MB, the same | Ingest | Out of memory | 532 to 537 MB, 2.2 to 2.4 s |
|
|
602
|
+
| 8 KB: an array of 8 MB in an object stream | Ingest | 234 to 235 MB, 1.5 to 3.0 s | 261 MB, 3.2 to 3.5 s |
|
|
603
|
+
| 8 KB: 8 MB of empty dictionaries in an object stream | Ingest | Out of memory | 538 to 542 MB, 2.4 s |
|
|
604
|
+
| 32 KB: an array of 32 MB in an object stream | Ingest | Out of memory | Out of memory |
|
|
605
|
+
| 32 MB, one array of numbers, in the file or in an object stream | pdf.js alone | Not read: 20 to 22 MB | The same |
|
|
606
|
+
| 8, 16 and 32 MB, one array of numbers that the page names as its MediaBox | pdf.js alone | 135, 212 and 313 MB; 0.2, 0.5 and 1.1 s | 135, 277 and 427 MB; 0.2, 0.5 and 1.2 to 1.3 s |
|
|
607
|
+
| 3 KB: 2 MB of empty dictionaries in the object stream that holds the catalog | pdf.js alone | 146 MB, 0.2 s | 146 MB, 0.2 s |
|
|
608
|
+
| The same | Ingest | 297 to 299 MB, 0.5 s | 293 to 301 MB, 0.4 s |
|
|
609
|
+
| 5 KB: 4 MB of them, the same way | pdf.js alone | Out of memory | 274 to 281 MB, 0.5 to 0.6 s |
|
|
610
|
+
| The same | Ingest | Out of memory | Out of memory |
|
|
611
|
+
| 8 KB: 8 MB of them, the same way | pdf.js alone, ingest | Out of memory | Out of memory |
|
|
612
|
+
| 732 bytes: 4 MB of them, the same way, unpacked twice | pdf.js alone | Out of memory | 281 MB, 0.4 to 0.6 s |
|
|
613
|
+
| The same | Ingest | Out of memory | Out of memory |
|
|
614
|
+
| 759 bytes: 8 MB of them, the same way, unpacked twice | pdf.js alone | Out of memory | Out of memory |
|
|
615
|
+
| 1,633 bytes: the object stream that holds the catalog, unpacked twice, holds 512 MB of spaces before its objects | Ingest | Read. Heap 20 MB, memory 1,643 MB, stall 6.2 to 6.4 s | Read. Heap 20 MB, memory 1,643 to 1,644 MB, 6.1 to 6.2 s |
|
|
616
|
+
| The same | pdf.js alone | Read. Heap 20 MB, memory 1,594 MB, 6.3 s (one run) | Read. Heap 20 MB, memory 1,594 MB, 6.2 to 6.3 s |
|
|
617
|
+
| The same | A look | Not measured | Heap 20 MB, memory 1,083 MB, 1.0 s (one run) |
|
|
618
|
+
| 1,660 bytes: the same spaces in the content stream of the page, unpacked twice | Ingest | Refused by the page check in 0.06 to 0.07 s | Not measured |
|
|
619
|
+
| 8.7 KB: a cross-reference stream inside the file that declares 1,048,576 entries and holds none | Ingest | 0.6 to 0.8 s; 152 MB still in use after the ingest and a full collection, about 140 MB more than before | The same; 2,097,152 entries: 1.3 to 1.5 s, 267 to 287 MB still in use; 4,194,304: out of memory |
|
|
620
|
+
|
|
621
|
+
pdf.js reads only the objects a page needs, but every object of an object stream once it needs one
|
|
622
|
+
of them: the catalog of a PDF is often in one. At ingest pdf.js opens the file first, and the
|
|
623
|
+
objects it built are still in memory while `@cantoo/pdf-lib` builds them again, so the file of 5 KB
|
|
624
|
+
ran out at 512 MB with the default extractor. `@cantoo/pdf-lib` reads every object, and for each
|
|
625
|
+
cross-reference stream it meets makes one entry for each object number its dictionary declares,
|
|
626
|
+
whatever the stream holds. The checks on the number of objects a file declares read that number
|
|
627
|
+
at the end of the file and where `startxref` points: they found 7 to 9 objects in each of these
|
|
628
|
+
files.
|
|
629
|
+
|
|
630
|
+
A stream unpacked twice packs far tighter than one unpacked once: 8 MB of empty dictionaries took
|
|
631
|
+
759 bytes that way, and 8 KB with one filter. What a stream unpacks to is held in memory outside
|
|
632
|
+
the heap, where `--max-old-space-size` does not limit it: the file of 1,633 bytes was read with no
|
|
633
|
+
more heap than before it, while the process took 1.6 GB of memory for the 512 MB that pdf.js
|
|
634
|
+
unpacked, in one block of 6 s. The same spaces in the content stream of the page are refused by
|
|
635
|
+
the page check before pdf.js reads them.
|
|
636
|
+
|
|
637
|
+
What one MB of a file takes when `@cantoo/pdf-lib` reads it, by what the MB holds (heap of 2 GB, one
|
|
638
|
+
run each; the time is one block):
|
|
639
|
+
|
|
640
|
+
| One MB of | Heap | Time |
|
|
641
|
+
|---|---|---|
|
|
642
|
+
| Empty dictionaries, `<<>>` | 91 MB | 0.29 s |
|
|
643
|
+
| Arrays of two numbers, `[1 2]` | 52 MB | 0.21 s |
|
|
644
|
+
| Names, each one different | 49 MB | 0.35 s |
|
|
645
|
+
| Empty arrays, `[]` | 41 MB | 0.11 s |
|
|
646
|
+
| A dictionary of different keys | 38 MB | 0.28 s |
|
|
647
|
+
| Numbers of one digit | 32 MB | 0.34 s |
|
|
648
|
+
| One string | 30 MB | 0.09 s |
|
|
649
|
+
| One name, again and again | 20 MB | 0.24 s |
|
|
650
|
+
| Short strings, `(a)` | 19 MB | 0.09 s |
|
|
651
|
+
| Numbers such as `1234.5` | 18 MB | 0.2 s |
|
|
652
|
+
| Short hex strings, `<00>` | 12 MB | 0.07 s |
|
|
653
|
+
| One reference, again and again | 6 MB | 0.1 s |
|
|
654
|
+
|
|
655
|
+
pdf.js took as much or less for each of these, read from an object stream that holds the catalog
|
|
656
|
+
(2 MB of each): 127 MB against 146 MB for empty dictionaries, 20 MB against 66 MB for numbers, and
|
|
657
|
+
25 MB against 26 MB for short strings.
|
|
658
|
+
|
|
659
|
+
`@cantoo/pdf-lib` also keeps every name and every reference it reads, for the life of the process.
|
|
660
|
+
After a document was dropped and the heap collected, 2 MB of different names (about 300,000) still
|
|
661
|
+
took 37 MB, and 2 MB of references to different objects (about 190,000) 28 MB. Reading the same
|
|
662
|
+
file again added nothing; numbers, and a name repeated, left nothing. Each file with other names or
|
|
663
|
+
object numbers adds its own. Files of 8.8 KB, each with a cross-reference stream inside it that
|
|
664
|
+
declared 1,048,576 new object numbers, were read one after another in one process, with a full
|
|
665
|
+
collection after each. At ingest with a heap flag of 512, 152, 288 and 368 MB stayed in use, and
|
|
666
|
+
the fourth file ran out of memory (two runs); with 256, the second did (one run). A look at each,
|
|
667
|
+
with a flag of 832 (a heap limit of 1 GB), left 148, 285, 366, 559, 639 and 720 MB, and the
|
|
668
|
+
seventh ran out of memory (two runs). The same file read three times left 151 to 152 MB (one run).
|
|
669
|
+
|
|
670
|
+
A look at pages now also pauses while it copies the pages and writes the cut. Compared with
|
|
671
|
+
5157e7f, whose looks are those of 0.5.0:
|
|
672
|
+
|
|
673
|
+
| Look at pages | 5157e7f: longest stall, of the whole look | 0.6.0 |
|
|
674
|
+
|---|---|---|
|
|
675
|
+
| Pages 1,800 to 1,802 of a PDF of 2,000 pages, 6.2 MB | 159 to 177 ms, of 163 to 185 ms | 19 to 20 ms, of 0.2 s (19 to 48 ms on a busy machine) |
|
|
676
|
+
| One page that refers to 4,000 large arrays | 0.73 to 0.75 s, of 1.27 to 1.30 s | 39 to 50 ms, of 1.5 to 1.6 s |
|
|
677
|
+
| One page that refers to 20,000 large arrays | 1.87 to 2.02 s, of 3.8 to 3.9 s | 43 to 47 ms, of 4.0 s |
|
|
678
|
+
|
|
679
|
+
The writer of `@cantoo/pdf-lib` searched its list of objects for each new one, a block that grew
|
|
680
|
+
with the square of their count (0.5 s for 20,000 objects); the cut's own list is now added to at its
|
|
681
|
+
end. 65 cuts of 50 PDFs are the same to the byte as before. Still in one block: the first look of a
|
|
682
|
+
process loads `@cantoo/pdf-lib`, in about 0.4 s (0.37 to 0.39 s for the ES build that `import()`
|
|
683
|
+
loads); a page whose resources list 140,000 pictures
|
|
684
|
+
takes about 0.15 s to drop the ones it does not paint; and a content stream of 7 to 8 MB takes 74
|
|
685
|
+
to 84 ms to read for the pictures it paints.
|
|
686
|
+
|
|
687
|
+
**The ZIP directory of a DOCX or PPTX (0.6.0, November 2026, Node 24 on Windows).** JSZip reads
|
|
688
|
+
the whole directory of a ZIP into memory before it unpacks any part. The limit of 20,000 parts took
|
|
689
|
+
the count from the end of the file; the directory is now read as JSZip will read it, before
|
|
690
|
+
JSZip does, and what JSZip would keep from it is added up: the parts, the extra fields, and the
|
|
691
|
+
bytes it turns into text or goes through byte by byte (names, comments, and the data of the ZIP64,
|
|
692
|
+
Unicode Path and Unicode Comment fields). Each file ingested into a `MemoryDocumentStore` in a
|
|
693
|
+
fresh process, with heaps of 256 and 512 MB, 2 runs each, with the 0.6.0 code before this reading
|
|
694
|
+
and with it, on a machine that ran other work too. Heap is the most used, sampled at each beat of a
|
|
695
|
+
1 ms timer and at the end, so it misses the peak of one long block; the gap is the longest time
|
|
696
|
+
between two beats. A refusal's time is nearly all the loading of JSZip: the reading itself takes a
|
|
697
|
+
few ms.
|
|
698
|
+
|
|
699
|
+
| File | Before | With the reading |
|
|
700
|
+
|---|---|---|
|
|
701
|
+
| 35 MB: 300,002 empty parts, the end record says 2 | Out of memory at 256 MB. Read at 512 MB in 2.2 to 2.4 s, all of it one gap | Refused in 53 to 56 ms, heap 8 MB |
|
|
702
|
+
| 32 MB: 270,002 parts, the count kept to its low 16 bits (7,858) | Out of memory at 256 MB. Read at 512 MB in 1.8 to 2.0 s, heap 483 to 484 MB | Refused in 54 to 57 ms, heap 7 to 9 MB |
|
|
703
|
+
| 35 MB: 300,002 parts, the true count, and 70 KB after the end record that is not its comment | Out of memory at 256 MB. Read at 512 MB in 2.4 to 2.5 s | Refused in 53 to 58 ms, heap 8 MB |
|
|
704
|
+
| 19 MB: 300 parts of 16,383 extra fields each | Out of memory at 256 and 512 MB | Refused in 44 to 49 ms, heap 7 to 8 MB |
|
|
705
|
+
| 0.28 MB: 5,000 parts that point to one local header, whose name is 65,535 bytes | Out of memory at 256 MB. Read at 512 MB in 0.42 s, heap 335 to 336 MB | Refused in 36 to 58 ms, heap 9 MB |
|
|
706
|
+
| 0.17 MB: 2,000 parts, each with a Unicode Path field that says it is 65,535 bytes long and runs over the records after it | Out of memory at 256 MB. Read at 512 MB in 8.5 to 8.6 s, all of it one gap | Refused in 37 to 38 ms, heap 9 MB |
|
|
707
|
+
| 1.1 MB: the same with 19,999 parts | Out of memory at 256 and 512 MB | Refused in 36 to 39 ms, heap 9 MB |
|
|
708
|
+
| 1.1 MB: the same with 19,999 Unicode Comment fields | Out of memory at 256 and 512 MB | Refused in 35 to 36 ms, heap 9 MB |
|
|
709
|
+
| 1.0 MB: the same with 19,999 ZIP64 fields, whose data JSZip goes through byte by byte | Read in 4.44 to 4.46 s, all of it one gap, heap 37 MB | Refused in 36 to 54 ms, heap 9 MB |
|
|
710
|
+
| 94 MB: 1,500 parts, each with a name of 65,535 bytes of 0xFF and "/" | Out of memory at 256 MB. Read at 512 MB in 3.2 s, all of it one gap, heap 453 to 457 MB | Refused in 36 to 38 ms, heap 8 MB |
|
|
711
|
+
| 63 MB: 1,000 parts whose local header sits in their own comment, its name of 65,535 bytes over the rest | Out of memory at 256 MB. Read at 512 MB in 2.3 s, all of it one gap, heap 426 to 430 MB | Refused in 35 to 43 ms, heap 8 MB |
|
|
712
|
+
| 94 MB: 1,500 parts, each with a comment of 65,535 bytes | Read in 0.59 to 0.61 s, all of it one gap, heap 199 to 200 MB | Refused in 36 to 39 ms, heap 8 MB |
|
|
713
|
+
| 636 bytes: a ZIP64 end record that says it is 6 bytes longer than its fields, then a field of length -6 | Held the process until it was killed, at 60 s | Refused in 36 to 40 ms, heap 9 MB |
|
|
714
|
+
| 100 MB of the bytes 06 07, a ZIP64 locator at the start, and an end record that asks for ZIP64 | Refused for "over 65,000" parts in 36 to 52 ms | Refused by JSZip, which finds no ZIP64 end record, in 0.51 to 0.53 s, all of it one gap |
|
|
715
|
+
| A DOCX of 4 MB, 120,000 paragraphs | 0.74 s, heap 91 to 94 MB, gap 43 to 48 ms | 0.74 to 0.76 s, heap 84 to 119 MB, gap 44 to 45 ms |
|
|
716
|
+
| A PowerPoint deck of 500 slides with notes and pictures, 1.3 MB, 2,041 parts | 145 to 151 ms, heap 16 to 17 MB, gap 57 to 60 ms | 146 to 162 ms, heap 16 MB, gap 60 to 75 ms |
|
|
717
|
+
| A DOCX of 0.25 MB written again by Info-ZIP, with a Unicode Path field and a comment on each part | 65 to 70 ms, heap 11 MB | 66 to 78 ms, heap 11 MB |
|
|
718
|
+
| 20,000 empty parts, 2.4 MB, end record says 2 | 164 to 192 ms, heap 47 MB, all of it one gap | 161 to 209 ms, heap 47 MB, all of it one gap |
|
|
719
|
+
| 95 MB: one picture of 95 MB, stored | 144 to 150 ms, heap 8 MB, all of it one gap | 144 to 159 ms, heap 8 MB |
|
|
720
|
+
| 95 MB: the end record, then 95 MB that is not its comment | 322 to 328 ms, all of it one gap | 357 to 366 ms |
|
|
721
|
+
| 100 MB that starts as a ZIP and has no end record | Refused by JSZip in 334 to 337 ms, all of it one gap | 365 to 374 ms |
|
|
722
|
+
|
|
723
|
+
What the limits still let through, with the reading: a DOCX of 9 to 9.4 MB just under them, with
|
|
724
|
+
20,000 parts and 7.6 to 7.9 MB of one kind of text, in 115 to 120 pieces of 65,000 bytes of 0xFF
|
|
725
|
+
and "/".
|
|
726
|
+
|
|
727
|
+
| Just under the limits | Read in, all of it one gap | Heap |
|
|
728
|
+
|---|---|---|
|
|
729
|
+
| Names | 405 to 409 ms | 84 to 104 MB |
|
|
730
|
+
| Unicode Path fields, decoded as names | 413 to 482 ms | 81 to 141 MB |
|
|
731
|
+
| Comments | 198 to 210 ms | 62 to 69 MB |
|
|
732
|
+
| Unicode Comment fields | 224 to 245 ms | 68 to 70 MB |
|
|
733
|
+
| ZIP64 fields | 195 to 207 ms | 44 to 47 MB |
|
|
734
|
+
| Unicode Path fields, and 79,996 extra fields in all | 460 to 482 ms | 126 to 140 MB |
|
|
735
|
+
|
|
736
|
+
The reading alone, in a warm process: 1 to 3 ms for a directory of 20,000 parts, under 4 ms for
|
|
737
|
+
any of the real files below (a Java archive of 163 MB and 46,559 parts included), 1 to 7 ms for the
|
|
738
|
+
file just under every limit, and 32 to 45 ms to search 95 to 100 MB for an end record that is not
|
|
739
|
+
at its end. The 100 MB of near signatures above takes 0.22 to 0.23 s of searches; the reading finds
|
|
740
|
+
no directory that JSZip could read, and JSZip then searches the file again with its own loop, for
|
|
741
|
+
0.3 s, and fails. The code before refused that file at once, only because its end record said
|
|
742
|
+
65,535 parts. JSZip goes through the whole file once as it starts to read, the gap of 0.15 s at
|
|
743
|
+
95 MB.
|
|
744
|
+
|
|
745
|
+
245 ZIP files gave the parts, and the bytes of text, that JSZip reads: 223 of Word, PowerPoint,
|
|
746
|
+
Excel, Java and other programs; 17 copies of the deck and of a Word template written again by
|
|
747
|
+
Python's `zipfile` (stored, packed, ZIP64), .NET, `System.IO.Packaging`, bsdtar and jar; and 5 Word
|
|
748
|
+
files written again by Info-ZIP (with Unicode Path fields and comments), Python with comments and
|
|
749
|
+
`git archive`. The most text in an Office file was 68 KB, and in any file 3.5 MB (a Java archive
|
|
750
|
+
of 46,559 parts, past the limit of parts anyway); at most 282 bytes a part, and 2 extra fields a
|
|
751
|
+
part. Their 101 Office files were read, or refused for their content, as by the code before: none
|
|
752
|
+
was refused by the reading. 36,000 copies of 11 small ZIPs (a Word template, JSZip's with and
|
|
753
|
+
without data descriptors, ZIP64, a comment, a program before the archive, parts that share a
|
|
754
|
+
header, and the Info-ZIP and Python files) changed at their records and their extra fields gave the
|
|
755
|
+
parts that JSZip reads, and never fewer bytes of text; JSZip read no part of the 185 refused for
|
|
756
|
+
their ZIP64 end record, nor of the 6,273 where the reading found no directory.
|
|
757
|
+
|
|
758
|
+
**Streams of a reply (0.6.0, November 2026, Node 24 on Windows).** `parseSseJson`, which the
|
|
759
|
+
adapters read streamed replies with, scanned an event again with each piece that came. One event of
|
|
760
|
+
1, 4 and 8 MB, in pieces of 16 KB, in memory, took 11 to 15 ms, 201 to 220 ms and 794 to 954 ms
|
|
761
|
+
before, and takes 1 to 2 ms, 5 to 9 ms and 10 to 18 ms with 0.6.0. 0.5.0 scans as the code
|
|
762
|
+
before did.
|
|
763
|
+
|
|
764
|
+
Now that it is fast, an endpoint that never ends an event could fill memory fast: one event holds
|
|
765
|
+
at most 64,000,000 characters. A hostile endpoint on the same machine, read through the adapters'
|
|
766
|
+
own `fetch`:
|
|
767
|
+
|
|
768
|
+
| The endpoint sends | Before | 0.6.0 |
|
|
769
|
+
|---|---|---|
|
|
770
|
+
| One event without an end | 513 MB read, failed as `"unreachable"` and sent again: 4 requests, 7.7 s, the process up 894 MB | Failed as `"invalid"` after 62 MB, not sent again: 1 request, 0.36 s, up 165 MB |
|
|
771
|
+
| Data lines without the blank line that ends an event, heap of 1 GB | Out of memory: the process stopped | Failed as `"invalid"` after 62 MB, 0.39 s, up 166 MB |
|
|
772
|
+
|
|
773
|
+
A reply made of many events has no cap yet.
|
|
774
|
+
|
|
775
|
+
**Streams of a reply, measured again for 0.5.0 (2026-11-21, Node 24.19 on Windows).** One event
|
|
776
|
+
of 1, 4 and 8 MB in pieces of 16 KB, in memory, five runs of each build in each of two sessions:
|
|
777
|
+
0.5.0 took 14 to 18 ms, 212 to 294 ms and 965 to 1,193 ms; 5157e7f 14 to 19 ms, 227 to 299 ms and
|
|
778
|
+
957 to 1,190 ms; 0.6.0 1 to 4 ms, 7 to 10 ms and 10 to 20 ms. An event that never ended, sent to
|
|
779
|
+
0.5.0 in pieces of 16 KB, slowed with the square of its size: 16 MB took 3.1 to 3.9 s, and 32 MB
|
|
780
|
+
12.5 to 13.5 s. 32 MB of data lines without the blank line that ends an event took 12.4 to 13.1 s,
|
|
781
|
+
as one string. Two runs each.
|
|
782
|
+
|
|
783
|
+
[Security](./security.md) explains the limits that came of these measurements.
|
|
784
|
+
|
|
785
|
+
## Faults reproduced before a fix
|
|
786
|
+
|
|
787
|
+
Numbers from probes and tests that showed a fault, not from live runs. Each is fixed in the version
|
|
788
|
+
named. A fault marked main was found and fixed on the code on main before 0.6.0 was released, and
|
|
789
|
+
the fix ships in 0.6.0.
|
|
790
|
+
|
|
791
|
+
- **0.3.6.** A log of 10,000 lines whose third line held a logged user agent `ua="evil␛]"` was
|
|
792
|
+
stored as 3 lines, with no error.
|
|
793
|
+
- **Main.** Two whole-file reads of one turn, each checked alone against what was left, ran
|
|
794
|
+
together and passed the ceiling: 16 requests against a `limits.requests` of 11, in a probe.
|
|
795
|
+
- **Main.** With a Gemini explorer and Claude answering, on text that cost 30% more than
|
|
796
|
+
estimated, the request for the answer came to 66,000 tokens of Claude's window of 60,000.
|
|
797
|
+
- **Main.** On a model whose conversation may only grow (Claude), four searches of about 300
|
|
798
|
+
characters each, after four rounds of reads on a window of 64,000, ran three and forced the
|
|
799
|
+
answer.
|
|
800
|
+
- **0.6.0.** A DOCX of 1.5 MB holding 120 MB of empty paragraphs ran a server with a heap of 512
|
|
801
|
+
MB out of memory, and stopped it.
|
|
802
|
+
- **0.6.0.** A PDF of 3 KB whose page tree listed one dense page 150 times was stored with 107 MB
|
|
803
|
+
of text. One of 6 KB with 600 listings held the event loop for 205 s.
|
|
804
|
+
- **0.6.0.** `files.tools()`, handed a `DocumentMeta` built from an ID with no owner or another
|
|
805
|
+
one, read the text of a document that had an owner, and showed the pages of its PDF.
|
|
806
|
+
- **0.6.0.** A Hebrew CSV that Excel saved in windows-1255 was stored as U+FFFD: "ירושלים" was
|
|
807
|
+
found in none of its 30 rows.
|
|
808
|
+
- **0.6.0.** A line with 44 Unicode tag characters, which spell out an instruction that a person
|
|
809
|
+
does not see, sent all 44 to the model, in the prompt and in tool results.
|
|
810
|
+
- **0.6.0.** With unpdf 1.5.0 to 1.6.0 on Node 20.19 and 22.12, the first PDF stopped the whole
|
|
811
|
+
process (`TypeError: Promise.try is not a function`, where nothing could catch it).
|
|
812
|
+
- **0.6.0.** A call to a tool named with 200,000 characters made a step of 400,025 characters, and
|
|
813
|
+
an error result of 200,047 that went back to the model.
|
|
814
|
+
- **0.6.0.** A question whose adapter never ended its request, and ignored the signal, hung for
|
|
815
|
+
good after an abort at 300 ms. It now throws the signal's reason at 310 ms.
|
|
816
|
+
|
|
817
|
+
## Checks of 0.5.0
|
|
818
|
+
|
|
819
|
+
Live on the Gemini API, models not recorded: `askWithFiles` with `gemini()`, and with
|
|
820
|
+
`openAiCompatible()` on Gemini's OpenAI layer (streamed, a log of 5.2 MB); an explorer behind the
|
|
821
|
+
OpenAI layer, with a thinking Gemini model answering; `askGemini` on a thinking model, alone and
|
|
822
|
+
with an explorer; a follow-up question from stored tool rounds; and a part read through the OpenAI
|
|
823
|
+
adapter. In each, the usage the library returned was what the provider reported, request by
|
|
824
|
+
request.
|
|
825
|
+
|
|
826
|
+
## Checks against earlier releases
|
|
827
|
+
|
|
828
|
+
These compare the requests or the tool results of a release with those of an earlier one.
|
|
829
|
+
|
|
830
|
+
| Release | Checked against | How |
|
|
831
|
+
|---|---|---|
|
|
832
|
+
| 0.3.0 | 0.2.0, as published | An application that changes nothing, and does not install `@cantoo/pdf-lib`, sends the same requests: byte for byte, over eight scenarios. |
|
|
833
|
+
| 0.3.5 | 0.3.0 | Without an explorer, the same requests: byte for byte, over seven scenarios. |
|
|
834
|
+
| 0.4.0 | 0.3.6 | The API, the tools and their results: call by call. |
|
|
835
|
+
| 0.4.1 | 0.3.6 | Tool results, call by call, over 40 documents: the same but for three changes that the 0.4.1 changelog lists. |
|
|
836
|
+
| 0.5.0 | 0.3.6 and 0.4.1 | Tool results, call by call with 0.3.6 over 40 documents: the same, except that a repeated whole-file read is refused. The requests of `askGemini` are those of 0.4.1: its 44 tests pass unchanged, but for one that now turns the retry off. |
|
|
837
|
+
|
|
838
|
+
## Measuring your own setup
|
|
839
|
+
|
|
840
|
+
The live answers above were judged against what is known to be in the file. To measure a model on
|
|
841
|
+
your own files, ask a question, log the fields of the result, and judge the answer the same way.
|
|
842
|
+
This sample uses Gemini on Vertex AI; `askWithFiles` returns the same fields for any adapter
|
|
843
|
+
([ask reference](./reference/ask.md)).
|
|
844
|
+
|
|
845
|
+
```ts
|
|
846
|
+
import { readFile } from "node:fs/promises";
|
|
847
|
+
import { createLargeFiles, MemoryDocumentStore } from "llm-large-files";
|
|
848
|
+
import { askGemini, vertexAi } from "llm-large-files/gemini";
|
|
849
|
+
|
|
850
|
+
const files = createLargeFiles({ store: new MemoryDocumentStore() });
|
|
851
|
+
const meta = await files.ingest({ name: "app.log", bytes: await readFile("./app.log") });
|
|
852
|
+
|
|
853
|
+
const started = Date.now();
|
|
854
|
+
const result = await askGemini({
|
|
855
|
+
files,
|
|
856
|
+
endpoint: vertexAi({
|
|
857
|
+
project: process.env.GOOGLE_CLOUD_PROJECT!,
|
|
858
|
+
location: "global",
|
|
859
|
+
model: process.env.GEMINI_MODEL!, // the model you want to measure
|
|
860
|
+
explorerModel: process.env.GEMINI_EXPLORER_MODEL, // optional: leave it unset for one model
|
|
861
|
+
accessToken: process.env.VERTEX_ACCESS_TOKEN!, // the Vertex AI guide shows tokens that renew
|
|
862
|
+
}),
|
|
863
|
+
documentIds: [meta.id],
|
|
864
|
+
messages: [{ role: "user", text: "How many ERROR lines say the payment gateway timed out?" }],
|
|
865
|
+
limits: { inputTokens: 250_000 }, // past it, no more tools: the next request is the answer
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
console.log({
|
|
869
|
+
answered: result.answered,
|
|
870
|
+
seconds: (Date.now() - started) / 1000,
|
|
871
|
+
searched: result.plan.searchable.map((document) => document.name), // the others were sent whole
|
|
872
|
+
chatRequests: result.turns, // part reads of a whole-file read not included
|
|
873
|
+
usage: result.usage, // the whole question: requests and tokens, and per model in byModel
|
|
874
|
+
steps: result.steps, // each tool call, as a user would see it
|
|
875
|
+
});
|
|
876
|
+
console.log(result.text);
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
Compare the answer with what you know is in the file: a count you made with grep, a line you know.
|
|
880
|
+
To test the integration without a real model, see [Testing](./guides/testing.md); to keep a
|
|
881
|
+
question's cost in bounds, [Costs and limits](./guides/costs-and-limits.md).
|