llm-large-files 0.8.1 → 0.9.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.
Files changed (204) hide show
  1. package/CHANGELOG.md +631 -0
  2. package/README.md +9 -10
  3. package/dist/access.d.ts +86 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +131 -0
  6. package/dist/access.js.map +1 -0
  7. package/dist/ask.d.ts +45 -1
  8. package/dist/ask.d.ts.map +1 -1
  9. package/dist/ask.js +181 -20
  10. package/dist/ask.js.map +1 -1
  11. package/dist/cache.d.ts +12 -3
  12. package/dist/cache.d.ts.map +1 -1
  13. package/dist/cache.js +18 -5
  14. package/dist/cache.js.map +1 -1
  15. package/dist/encoding.js +5 -3
  16. package/dist/encoding.js.map +1 -1
  17. package/dist/error-info.d.ts +57 -0
  18. package/dist/error-info.d.ts.map +1 -0
  19. package/dist/error-info.js +217 -0
  20. package/dist/error-info.js.map +1 -0
  21. package/dist/errors.d.ts +72 -8
  22. package/dist/errors.d.ts.map +1 -1
  23. package/dist/errors.js +102 -15
  24. package/dist/errors.js.map +1 -1
  25. package/dist/events.d.ts +35 -9
  26. package/dist/events.d.ts.map +1 -1
  27. package/dist/events.js +42 -11
  28. package/dist/events.js.map +1 -1
  29. package/dist/evidence.d.ts +4 -2
  30. package/dist/evidence.d.ts.map +1 -1
  31. package/dist/evidence.js +14 -3
  32. package/dist/evidence.js.map +1 -1
  33. package/dist/extract.d.ts +32 -8
  34. package/dist/extract.d.ts.map +1 -1
  35. package/dist/extract.js +46 -35
  36. package/dist/extract.js.map +1 -1
  37. package/dist/gemini/adapter.d.ts +19 -3
  38. package/dist/gemini/adapter.d.ts.map +1 -1
  39. package/dist/gemini/adapter.js +84 -12
  40. package/dist/gemini/adapter.js.map +1 -1
  41. package/dist/gemini/chat.d.ts +18 -6
  42. package/dist/gemini/chat.d.ts.map +1 -1
  43. package/dist/gemini/chat.js +2 -0
  44. package/dist/gemini/chat.js.map +1 -1
  45. package/dist/gemini/index.d.ts +1 -1
  46. package/dist/gemini/index.d.ts.map +1 -1
  47. package/dist/index.d.ts +9 -6
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +4 -3
  50. package/dist/index.js.map +1 -1
  51. package/dist/ingest.d.ts +70 -0
  52. package/dist/ingest.d.ts.map +1 -0
  53. package/dist/ingest.js +868 -0
  54. package/dist/ingest.js.map +1 -0
  55. package/dist/library.d.ts +176 -34
  56. package/dist/library.d.ts.map +1 -1
  57. package/dist/library.js +332 -512
  58. package/dist/library.js.map +1 -1
  59. package/dist/limiter.d.ts +2 -2
  60. package/dist/limiter.js +2 -2
  61. package/dist/map-reduce.js +3 -3
  62. package/dist/map-reduce.js.map +1 -1
  63. package/dist/model.d.ts +43 -2
  64. package/dist/model.d.ts.map +1 -1
  65. package/dist/model.js +63 -3
  66. package/dist/model.js.map +1 -1
  67. package/dist/node/handlers.d.ts +234 -7
  68. package/dist/node/handlers.d.ts.map +1 -1
  69. package/dist/node/handlers.js +482 -121
  70. package/dist/node/handlers.js.map +1 -1
  71. package/dist/node/index.d.ts +3 -2
  72. package/dist/node/index.d.ts.map +1 -1
  73. package/dist/node/index.js +2 -1
  74. package/dist/node/index.js.map +1 -1
  75. package/dist/node/ingest-child.d.ts +7 -1
  76. package/dist/node/ingest-child.d.ts.map +1 -1
  77. package/dist/node/ingest-child.js +18 -3
  78. package/dist/node/ingest-child.js.map +1 -1
  79. package/dist/node/isolated.d.ts +3 -1
  80. package/dist/node/isolated.d.ts.map +1 -1
  81. package/dist/node/isolated.js +11 -4
  82. package/dist/node/isolated.js.map +1 -1
  83. package/dist/node/originals.d.ts +19 -0
  84. package/dist/node/originals.d.ts.map +1 -0
  85. package/dist/node/originals.js +82 -0
  86. package/dist/node/originals.js.map +1 -0
  87. package/dist/node/spool.d.ts +102 -0
  88. package/dist/node/spool.d.ts.map +1 -0
  89. package/dist/node/spool.js +365 -0
  90. package/dist/node/spool.js.map +1 -0
  91. package/dist/node/sse.d.ts +4 -3
  92. package/dist/node/sse.d.ts.map +1 -1
  93. package/dist/node/sse.js +7 -6
  94. package/dist/node/sse.js.map +1 -1
  95. package/dist/pdf-layout.d.ts.map +1 -1
  96. package/dist/pdf-layout.js +71 -12
  97. package/dist/pdf-layout.js.map +1 -1
  98. package/dist/ranged.d.ts +22 -11
  99. package/dist/ranged.d.ts.map +1 -1
  100. package/dist/ranged.js +50 -12
  101. package/dist/ranged.js.map +1 -1
  102. package/dist/retry.d.ts +3 -1
  103. package/dist/retry.d.ts.map +1 -1
  104. package/dist/retry.js +6 -2
  105. package/dist/retry.js.map +1 -1
  106. package/dist/scope.d.ts +25 -0
  107. package/dist/scope.d.ts.map +1 -0
  108. package/dist/scope.js +60 -0
  109. package/dist/scope.js.map +1 -0
  110. package/dist/source.d.ts +60 -0
  111. package/dist/source.d.ts.map +1 -0
  112. package/dist/source.js +170 -0
  113. package/dist/source.js.map +1 -0
  114. package/dist/stores.d.ts +120 -31
  115. package/dist/stores.d.ts.map +1 -1
  116. package/dist/stores.js +582 -139
  117. package/dist/stores.js.map +1 -1
  118. package/dist/testing/fake-fetch.d.ts +31 -0
  119. package/dist/testing/fake-fetch.d.ts.map +1 -0
  120. package/dist/testing/fake-fetch.js +66 -0
  121. package/dist/testing/fake-fetch.js.map +1 -0
  122. package/dist/testing/fake-model.d.ts +38 -0
  123. package/dist/testing/fake-model.d.ts.map +1 -0
  124. package/dist/testing/fake-model.js +62 -0
  125. package/dist/testing/fake-model.js.map +1 -0
  126. package/dist/testing/index.d.ts +7 -0
  127. package/dist/testing/index.d.ts.map +1 -0
  128. package/dist/testing/index.js +9 -0
  129. package/dist/testing/index.js.map +1 -0
  130. package/dist/testing/store-checks.d.ts +72 -0
  131. package/dist/testing/store-checks.d.ts.map +1 -0
  132. package/dist/testing/store-checks.js +619 -0
  133. package/dist/testing/store-checks.js.map +1 -0
  134. package/dist/tools.d.ts +25 -0
  135. package/dist/tools.d.ts.map +1 -1
  136. package/dist/tools.js +135 -13
  137. package/dist/tools.js.map +1 -1
  138. package/dist/types.d.ts +116 -13
  139. package/dist/types.d.ts.map +1 -1
  140. package/docs/README.md +17 -8
  141. package/docs/getting-started.md +18 -13
  142. package/docs/guides/anthropic.md +12 -8
  143. package/docs/guides/conversations.md +112 -47
  144. package/docs/guides/costs-and-limits.md +16 -7
  145. package/docs/guides/deployment.md +309 -87
  146. package/docs/guides/errors-and-reliability.md +161 -23
  147. package/docs/guides/own-adapter-and-loop.md +27 -10
  148. package/docs/guides/pdfs.md +123 -29
  149. package/docs/guides/storage.md +634 -143
  150. package/docs/guides/testing.md +78 -129
  151. package/docs/guides/vertex-and-gemini.md +10 -7
  152. package/docs/guides/web-app.md +322 -77
  153. package/docs/how-it-works.md +35 -8
  154. package/docs/measurements.md +63 -8
  155. package/docs/publishing.md +112 -36
  156. package/docs/reference/ask.md +154 -13
  157. package/docs/reference/errors-and-retries.md +166 -14
  158. package/docs/reference/events.md +53 -20
  159. package/docs/reference/gemini.md +70 -21
  160. package/docs/reference/library.md +709 -165
  161. package/docs/reference/node.md +633 -104
  162. package/docs/reference/testing.md +311 -0
  163. package/docs/reference/tools.md +15 -5
  164. package/docs/security.md +316 -70
  165. package/docs/troubleshooting.md +165 -58
  166. package/docs/upgrading-0.9.md +890 -0
  167. package/package.json +12 -3
  168. package/src/access.ts +144 -0
  169. package/src/ask.ts +230 -19
  170. package/src/cache.ts +20 -5
  171. package/src/encoding.ts +6 -4
  172. package/src/error-info.ts +255 -0
  173. package/src/errors.ts +129 -15
  174. package/src/events.ts +86 -21
  175. package/src/evidence.ts +14 -3
  176. package/src/extract.ts +50 -33
  177. package/src/gemini/adapter.ts +97 -11
  178. package/src/gemini/chat.ts +20 -6
  179. package/src/gemini/index.ts +1 -1
  180. package/src/index.ts +9 -6
  181. package/src/ingest.ts +927 -0
  182. package/src/library.ts +482 -523
  183. package/src/limiter.ts +2 -2
  184. package/src/map-reduce.ts +3 -3
  185. package/src/model.ts +69 -5
  186. package/src/node/handlers.ts +691 -117
  187. package/src/node/index.ts +13 -2
  188. package/src/node/ingest-child.ts +23 -5
  189. package/src/node/isolated.ts +11 -4
  190. package/src/node/originals.ts +78 -0
  191. package/src/node/spool.ts +365 -0
  192. package/src/node/sse.ts +7 -6
  193. package/src/pdf-layout.ts +69 -11
  194. package/src/ranged.ts +42 -14
  195. package/src/retry.ts +6 -2
  196. package/src/scope.ts +63 -0
  197. package/src/source.ts +178 -0
  198. package/src/stores.ts +635 -140
  199. package/src/testing/fake-fetch.ts +80 -0
  200. package/src/testing/fake-model.ts +78 -0
  201. package/src/testing/index.ts +11 -0
  202. package/src/testing/store-checks.ts +660 -0
  203. package/src/tools.ts +150 -14
  204. package/src/types.ts +106 -13
@@ -91,9 +91,9 @@ What each error and `kind` means, and what to tell your user, is in
91
91
  ### `require("llm-large-files")` throws `ERR_REQUIRE_ESM`
92
92
 
93
93
  **Cause.** The package is an ES module only. CommonJS code can load it with `require()` only on the
94
- Node versions that load ES modules that way by default: 20.19 and later in Node 20, 22.12 and later
95
- in Node 22, and 23 and later. Node 21 and Node 22.0 to 22.11 refuse. The library needs Node 20.19
96
- or later in any case.
94
+ Node versions that load ES modules that way by default: 22.12 and later in Node 22, and 23 and
95
+ later. Node 22.0 to 22.11 refuse. The library needs Node 22.12 or later in any case (20.19 until
96
+ 0.9.0).
97
97
 
98
98
  **Fix.** Upgrade Node, or load the package from CommonJS with `await import("llm-large-files")`
99
99
  (and `import("llm-large-files/gemini")` and so on for the other entry points). In TypeScript this
@@ -123,10 +123,9 @@ as `devDependencies` and left out of the production install, or missing from the
123
123
  bundle you deploy.
124
124
 
125
125
  **Fix.** Install them as dependencies of the application that runs the upload route and the
126
- questions: `npm install jszip unpdf @cantoo/pdf-lib` on Node 24 and later. On Node 20 and 22, name
127
- a version of `unpdf` that runs there: `npm install jszip unpdf@1 @cantoo/pdf-lib` on Node 22, and
128
- `npm install jszip unpdf@1.7.0 @cantoo/pdf-lib` on Node 20 (see
129
- [below](#a-pdf-upload-fails-the-unpdf-installed-cannot-read-pdf-files-or-would-stop-the-whole-server)).
126
+ questions: `npm install jszip unpdf @cantoo/pdf-lib` on Node 24 and later. On Node 22, name a
127
+ version of `unpdf` that runs there: `npm install jszip unpdf@1 @cantoo/pdf-lib` (see
128
+ [below](#a-pdf-upload-fails-the-unpdf-installed-would-stop-the-whole-server)).
130
129
  Install `@cantoo/pdf-lib` before PDFs are uploaded: without it nothing fails at upload, but the
131
130
  text of a PDF is written without the line that marks a page with a picture
132
131
  (`[Picture on this page. This text cannot show it.]`), and a document keeps the text it was
@@ -134,41 +133,35 @@ ingested with.
134
133
 
135
134
  See [PDFs and other formats](./guides/pdfs.md).
136
135
 
137
- ### A PDF upload fails: "The unpdf installed cannot read PDF files" or "would stop the whole server"
136
+ ### A PDF upload fails: "The unpdf installed would stop the whole server"
138
137
 
139
- `files.ingest` throws one of these, and the upload handler answers `422` with it:
138
+ `files.ingest` throws this, and the upload handler answers `422` with it:
140
139
 
141
- - `The unpdf installed would stop the whole server at the first PDF file on Node 22, so PDF files are not read. Install unpdf 1.6.1 or later, or run Node 24 or later.`
142
- - `The unpdf installed would stop the whole server at the first PDF file on Node 20, so PDF files are not read. Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 24 or later.`
143
- - `The unpdf installed cannot read PDF files on Node 20 (Serverless PDF.js bundle could not be resolved: ReferenceError: Iterator is not defined). Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 22 or later.`
144
- The text in brackets is unpdf's own message, and differs between its versions.
140
+ `The unpdf installed would stop the whole server at the first PDF file on Node 22, so PDF files are not read. Install unpdf 1.6.1 or later, or run Node 24 or later.`
145
141
 
146
142
  The number is the major version of the Node that runs the server. DOCX, PPTX and text files are
147
143
  read as before.
148
144
 
149
- **Cause.** The version of `unpdf` that is installed cannot read PDFs on this version of Node, and
150
- 0.6.0 checks it before it reads a PDF:
151
-
152
- - unpdf 1.5.0 to 1.6.0 load a pdf.js that calls `Promise.try`, which Node 20 and 22 do not have. In
153
- 0.5.0 the first PDF stopped the whole process, with a `TypeError` that nothing could catch.
154
- - unpdf 1.9 and later, 2.x included, load a pdf.js that needs Node 22. On Node 20, every PDF failed
155
- with unpdf's message alone.
145
+ **Cause.** unpdf 1.5.0 to 1.6.0 load a pdf.js that calls `Promise.try`, which Node 22 does not
146
+ have. In 0.5.0 the first PDF stopped the whole process, with a `TypeError` that nothing could
147
+ catch. Since 0.6.0 the library checks it before it reads a PDF.
156
148
 
157
- unpdf 2 asks for Node 24, and on Node 24 a plain `npm install unpdf` installs it. On Node 22 and
158
- later, a pdf.js that cannot be loaded for another reason fails with unpdf's message, as before.
149
+ unpdf 2 asks for Node 24, and on Node 24 a plain `npm install unpdf` installs it. A pdf.js that
150
+ cannot be loaded for another reason fails with unpdf's own message. (Until 0.9.0, on Node 20, that
151
+ failure came as `The unpdf installed cannot read PDF files on Node 20 (…)`. Node 20 is no longer
152
+ supported.)
159
153
 
160
- **Fix.** Install the `unpdf` that runs on your Node, or move to the Node the message names:
154
+ **Fix.** Install the `unpdf` that runs on your Node, or move to Node 24:
161
155
 
162
156
  | Node | `unpdf` to install |
163
157
  |---|---|
164
- | 20 | 1.4.0, or 1.6.1 to 1.8.1: `npm install unpdf@1.7.0`. 1.7.0 is the last that does not ask for Node 22. |
165
158
  | 22 | 1.4.0, or 1.6.1 or a later 1.x: `npm install unpdf@1`. |
166
159
  | 24 and later | Any version from 1.4.0, 2.x included: `npm install unpdf`. |
167
160
 
168
161
  If the server loads pdf.js when it starts, as [Deployment](./guides/deployment.md#uploads-and-ingest)
169
- shows, an `unpdf` that cannot load pdf.js on that Node (1.9 and later on Node 20) makes the start
170
- fail instead. With unpdf 1.5.0 to 1.6.0 on Node 20 or 22, pdf.js loads and the server starts: PDFs
171
- are then refused at upload, with one of the `would stop the whole server` messages above.
162
+ shows, an `unpdf` that cannot load pdf.js on that Node makes the start fail instead. With unpdf
163
+ 1.5.0 to 1.6.0 on Node 22, pdf.js loads and the server starts: PDFs are then refused at upload,
164
+ with the message above.
172
165
 
173
166
  See [PDFs and other formats](./guides/pdfs.md#formats).
174
167
 
@@ -258,6 +251,56 @@ is read and its text extracted, so a higher limit is more memory for each upload
258
251
 
259
252
  See [Web app](./guides/web-app.md) and [Deployment](./guides/deployment.md).
260
253
 
254
+ ### `503`: "The server is receiving other files right now. Try again in a moment."
255
+
256
+ New in 0.8.2. `createDocumentHandlers` answers `503` with `Retry-After: 5`, before reading the body.
257
+
258
+ **Cause.** The handlers already hold uploads, and this one would bring them past
259
+ `maxPendingUploadBytes` (twice `maxUploadBytes`, 200 MB by default). An upload is held from the
260
+ reading of its body to the end of its ingest, and its room is taken from its `Content-Length`
261
+ before its body arrives (`maxUploadBytes` for a body sent without a `Content-Length`, until it is
262
+ read: two such uploads fill the default room). Many users sending files at once, or a few clients
263
+ that send their headers and then their bodies slowly, fill it. With `uploadSpool` (new in 0.9.0),
264
+ the same answer comes when the spool's files reach `maxSpooledUploadBytes`.
265
+
266
+ **Fix.** Send the file again after `Retry-After` seconds, as the browser code in
267
+ [Web app](./guides/web-app.md#upload-from-the-browser) does. To take more at once, raise
268
+ `maxPendingUploadBytes` and size the server for it (each upload under way takes about three and a
269
+ half to five and a half times its size while it is ingested over a `FileDocumentStore`,
270
+ [measurements](./measurements.md#the-server); ingests take turns, `maxConcurrentIngests`). Put a
271
+ proxy that reads whole bodies before passing them on in front, so that slow clients hold no room.
272
+ Or take the bodies off the heap: `uploadSpool` writes the larger ones, and those without a
273
+ `Content-Length`, to temporary files, and `maxPendingUploadBytes` then counts only the bodies kept
274
+ in memory ([Deployment](./guides/deployment.md#uploads-and-ingest)).
275
+ "The server is reading other files right now." is another `503`: the readers of
276
+ `createIsolatedExtractors` are busy ([Node reference](./reference/node.md#uploadrequest-response)).
277
+ So is "The server has no room for this file right now. Try again later." (new in 0.9.0, with
278
+ `Retry-After: 30`): the disk the body was written to, the spool's or the folder of
279
+ `prepareUpload`, is full.
280
+
281
+ ### `408`: "The upload stopped arriving: nothing came for 30 s. Send it again."
282
+
283
+ New in 0.8.2. **Cause.** The body of an upload stopped arriving for `uploadIdleTimeoutMs` (30 s):
284
+ the client's connection stalled, or a proxy held the body. The connection is closed. **Fix.** Send
285
+ the file again. For users on slow or unsteady links, raise `uploadIdleTimeoutMs` of
286
+ `createDocumentHandlers`.
287
+
288
+ ### `500`: "Upload failed (ETIMEDOUT)." or "Upload failed (ELOOP)."
289
+
290
+ New in 0.9.0, for a body written to a file (the `path` of `prepareUpload`, or `uploadSpool`).
291
+
292
+ - **"ETIMEDOUT".** A call to the disk (checking the folders of a path with a ref, opening the file,
293
+ a write, closing it) did not end within `uploadIdleTimeoutMs` (30 s): the volume stopped
294
+ answering, such as a network volume whose server is gone. The upload's room is given back, and
295
+ the file is removed once the volume answers. **Fix.** Check the volume. A slow network volume can
296
+ take long to close a file it held writes for: raise `uploadIdleTimeoutMs`.
297
+ - **"ELOOP".** `prepareUpload` gave a path that ends with the ref of its `original`, and a folder
298
+ between that root and the file is a link. `fileOriginals` would never read the file back through
299
+ it, so nothing is written. **Fix.** Replace the link with the folder itself, or mount the other
300
+ disk there. The root itself may be a link.
301
+
302
+ See [saving the body](./reference/node.md#saving-the-body-prepareupload).
303
+
261
304
  ### `400`: "Name the file with an X-File-Name header or a ?name= query parameter."
262
305
 
263
306
  **Cause.** The upload request names no file. The name decides the format, and is shown to the
@@ -299,7 +342,10 @@ others. 0.5.0 accepted it.
299
342
  an array.
300
343
 
301
344
  A numeric owner is accepted, as before. `get`, `remove` and questions that pass the owner `""` work
302
- as before, so documents that 0.5.0 stored with that owner stay readable until they expire.
345
+ as before, so documents that 0.5.0 stored with that owner stay readable until they expire. Under
346
+ `requireOwner` the library refuses that owner on every call: `get` and `remove` then answer
347
+ "The file could not be looked up (empty owner)." and "The file could not be deleted (empty owner).",
348
+ also `500` (new in 0.9.0).
303
349
 
304
350
  **Fix.** Return the user's ID, not the user object. Where every upload needs a signed-in user,
305
351
  throw an error with `status: 401` for a request without one. Only where anonymous uploads are
@@ -325,7 +371,7 @@ handler answers `422` with its message. The common ones:
325
371
  | `report.txt is empty.` | A file of 0 bytes. |
326
372
  | `report.docx did not contain any text.` | Nothing left once read: a DOCX of pictures, a file of blank lines. |
327
373
  | `This PDF has no text layer (it may be scanned). It needs OCR before it can be searched.` | A scan, while PDFs are not kept. |
328
- | `The unpdf installed would stop the whole server at the first PDF file on Node 22, …` or `The unpdf installed cannot read PDF files on Node 20 (…). …` | Any PDF, while the `unpdf` installed cannot run on this Node. See [above](#a-pdf-upload-fails-the-unpdf-installed-cannot-read-pdf-files-or-would-stop-the-whole-server). |
374
+ | `The unpdf installed would stop the whole server at the first PDF file on Node 22, …` | Any PDF, while the `unpdf` installed cannot run on this Node. See [above](#a-pdf-upload-fails-the-unpdf-installed-would-stop-the-whole-server). |
329
375
  | `This PDF has 6,200 pages, more than the 5,000 read from one file. Split it, and attach the part you need.` | A PDF of more than `maxPdfPages` pages (5,000 by default). Refused before any page is read. |
330
376
  | `This PDF holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` | A PDF whose text passes `maxTextBytes` (100 MB by default, or `maxUploadBytes` when that is larger). |
331
377
  | `notes.txt holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` | The same, from the text extractor or one of your own: a UTF-16 file can grow by half in UTF-8. |
@@ -365,9 +411,12 @@ below 2 minutes ("45 s"), in minutes from there ("2 min").
365
411
  **Cause.** One `ingest` (extracting the text, its line index and its profile) took longer than
366
412
  `ingestTimeoutMs`, 120,000 ms by default. Most often: a PDF with many pages that are slow to read;
367
413
  an extractor of your own that waits on a slow service, such as OCR of a long scan; or a server
368
- busy with other ingests, which each take their share of the same process. Nothing is stored.
414
+ busy with other ingests, which each take their share of the same process. A file read from a path
415
+ (`source: { path }`, an upload of `prepareUpload` or of the spool) gets the same message when its
416
+ volume stops answering while the file is read. Nothing is stored.
369
417
 
370
- **Fix.** For a file that is slow to read, the user splits it, or saves it as plain text. For OCR or
418
+ **Fix.** For a file read from a path, check its volume first: the file may be fine. For a file
419
+ that is slow to read, the user splits it, or saves it as plain text. For OCR or
371
420
  another slow extractor of your own, raise `ingestTimeoutMs` (0 sets no limit), run the ingest in a
372
421
  background job ([Web app](./guides/web-app.md#long-ingests-in-the-background)), and pass
373
422
  `input.signal` on to the service it calls, so that the request stops at the limit too. Bound the
@@ -490,12 +539,18 @@ handler's `get` answers `404` with `This file is no longer available.` for the s
490
539
  - belongs to another `owner`, or has an owner while the question passes none. A document with an
491
540
  owner is reported as missing, never as forbidden;
492
541
  - was stored in a `MemoryDocumentStore` of another process, or of this one before it restarted;
542
+ - has lost its text in the store while its metadata stayed (removed outside the library). Since
543
+ 0.8.2 such a document is missing here too; before, a question about one read by range failed
544
+ with a plain `Error`;
493
545
  - is not a document ID at all (`isDocumentId` is false for it).
494
546
 
495
547
  **Fix.** Pass the same `owner` to the question as to the upload: the value `getOwner` returned for
496
548
  the same user. Use a store that every server shares and that outlives a restart. Show the user which
497
549
  files to attach again: `error.ids` names the IDs, and your chat knows their file names. A
498
- document's `expiresAt` says when it goes.
550
+ document's `expiresAt` says when it goes. Since 0.9.0 a question can go on without them:
551
+ `onMissingDocuments: "drop"` answers from the other files and lists the missing ones in
552
+ `result.missing`, and a function can ingest them again from uploads you kept
553
+ ([missing documents](./reference/ask.md#missing-documents)).
499
554
 
500
555
  See [Storage](./guides/storage.md) and
501
556
  [`DocumentsNotFoundError`](./reference/ask.md#documentsnotfounderror).
@@ -630,7 +685,8 @@ only what the answering model wrote.
630
685
  **Cause.** The model gets `view_pages` for a PDF only when all of these hold:
631
686
 
632
687
  - `keepOriginals` lists `"pdf"`, and the store has `putOriginal` and `getOriginal`
633
- (`FileDocumentStore` and `MemoryDocumentStore` have both);
688
+ (`FileDocumentStore` and `MemoryDocumentStore` have both), or (0.9.0) the document was ingested
689
+ with `original: { ref }` and the library has `originals`;
634
690
  - the document was ingested after that: one ingested before has no file kept
635
691
  (`meta.originalKept` is not `true`);
636
692
  - every model of the question can be sent a file: not `openAiCompatible()` without `pdfInput`, not
@@ -649,6 +705,19 @@ look fails: install it ([above](#a-pdf-docx-or-pptx-upload-fails-needs-the-optio
649
705
 
650
706
  See [PDFs and other formats](./guides/pdfs.md).
651
707
 
708
+ ### `view_pages` says a file "changed on the server since it was read"
709
+
710
+ The model reads `report.pdf changed on the server since it was read. Attach it again to look at its
711
+ pages.`, and `files.getOriginal` gives `undefined`.
712
+
713
+ **Cause.** The document was ingested with `original: { ref }` (0.9.0), and the file at that ref is
714
+ no longer the one that was ingested: its size or SHA-256 differs from `meta.original`. It was saved
715
+ again under the same name, cut short by a copy that failed, or edited. Its pages would not match the
716
+ text the model has, so none are shown.
717
+
718
+ **Fix.** Keep each upload under a name of its own, and never write over a file a document names.
719
+ To use the new file, ingest it again (`ifExists: "replace"` under the same `id`).
720
+
652
721
  ### Whole-file reads never happen, or are refused
653
722
 
654
723
  `steps` holds no `Read all of …` line, or holds one that failed:
@@ -1024,9 +1093,11 @@ Look at `result.usage`: `inputTokens`, `cachedInputTokens` (read from the provid
1024
1093
  - **`documentPlacement: "last"`.** The documents then move to the latest turn, and a prompt cache
1025
1094
  cannot reuse them: keep the default, `"first"`.
1026
1095
  - **The first request of a follow-up question.** The tool rounds of an earlier question are sent
1027
- again without their `tool_turns_left` (since 0.6.0), so that request reads the cache only up to
1028
- the tool rounds of the question before it: the documents, the cards and the turns before those
1029
- rounds still hit. The later requests of the question hit as before.
1096
+ again without their `tool_turns_left` (since 0.6.0), and as their calls alone: a stored round
1097
+ keeps no thought signatures or thinking blocks, which the requests of its own question sent
1098
+ back. Either one makes that request read the cache only up to the tool rounds of the question
1099
+ before it: the documents, the cards and the turns before those rounds still hit. The later
1100
+ requests of the question hit as before.
1030
1101
  - **The first request after the upgrade to 0.6.0.** The tool guide, the descriptions of
1031
1102
  `search_document` and `analyze_whole_document`, and the frame of every file sent whole changed,
1032
1103
  so the first request of each conversation reads from the cache at most what comes before the
@@ -1143,12 +1214,14 @@ See [Security](./security.md) and [Tools](./reference/tools.md).
1143
1214
  ### `DocumentStoreError`: "The document store could not be read (EIO). Try again."
1144
1215
 
1145
1216
  Thrown by a question, `files.getMeta`, `files.getOriginal`, and by `files.delete` when the look-up
1146
- fails (a failure of the store's own `delete` comes as the store's error). When the error behind it
1147
- has no `code`, the message has none. Inside a question's tool call, the model gets it as the
1148
- call's error, and `steps` shows
1149
- `… — failed: The document store could not be read (EIO). Try again.`. The upload
1150
- handler's `get` and `remove` answer `500` with `The file could not be looked up (EIO).` or
1151
- `The file could not be deleted (EIO).`.
1217
+ fails. When the error behind it has no `code`, the message has none. Inside a question's tool call,
1218
+ the model gets it as the call's error, and `steps` shows
1219
+ `… — failed: The document store could not be read (EIO). Try again.`. The upload handler's `get`
1220
+ and `remove` answer `503` with that message (since 0.9.0; they answered `500`). Since 0.9.0 the
1221
+ errors of writes are `DocumentStoreError`s too, with their own messages: "The document could not be
1222
+ stored (EIO). Try again." from `files.ingest`, "The document could not be deleted (EIO). Try
1223
+ again." from the store's own `delete`, "The document store could not be cleaned up (EIO). Try
1224
+ again." from `files.sweep`.
1152
1225
 
1153
1226
  **Cause.** The store failed while it was read: a network volume that did not answer, too many open
1154
1227
  files, a database that is down. The documents are not gone.
@@ -1159,6 +1232,31 @@ them to upload again. Log `error.cause`, the store's own error, and `error.code`
1159
1232
  See [`DocumentStoreError`](./reference/library.md#documentstoreerror) and
1160
1233
  [Storage](./guides/storage.md).
1161
1234
 
1235
+ ### "The document store could not be read (EACCES)" after an upgrade to 0.9.0
1236
+
1237
+ Uploads work on the server that took them, and every other server, or a backup or sweep job,
1238
+ answers `EACCES` for the new documents.
1239
+
1240
+ **Cause.** Since 0.9.0, `FileDocumentStore` writes files `0600` and folders `0700`: only the user
1241
+ that wrote them can read them. The servers or the job run as different users.
1242
+
1243
+ **Fix.** Run them all as one user. Or, for users of one group (a Kubernetes `fsGroup`), give every
1244
+ store `fileMode: 0o640` and `directoryMode: 0o750`, and change the files written since the upgrade
1245
+ once with `chmod`. See [Deployment](./guides/deployment.md#a-shared-store).
1246
+
1247
+ ### `DocumentScopeError`: "The scope no longer exists."
1248
+
1249
+ An upload into a chat fails with a `DocumentScopeError` of code `"scope_missing"`. The upload
1250
+ handler answers it `404` `{ "error": "This chat no longer exists." }`.
1251
+
1252
+ **Cause.** The store is a `FileDocumentStore` with `scopes`, and the folder of the chat is gone:
1253
+ your application removed it when the chat was deleted, or never made it. The store makes its own
1254
+ folder in a chat's folder, never the chat's folder itself, unless `createScopeFolders` is on.
1255
+
1256
+ **Fix.** For a deleted chat, nothing: tell the user the chat no longer exists. For a new chat, make
1257
+ its folder (`mkdir` with `recursive: true`) when the chat starts, or set `createScopeFolders: true`.
1258
+ See [Storage](./guides/storage.md#files-in-a-folder-per-user-or-per-chat).
1259
+
1162
1260
  ### Documents are found on one server and missing on another
1163
1261
 
1164
1262
  `DocumentsNotFoundError` for documents that were just uploaded, on some requests and not others, or
@@ -1186,29 +1284,38 @@ try again.
1186
1284
 
1187
1285
  See [Storage](./guides/storage.md) and [`DocumentStore`](./reference/library.md#documentstore).
1188
1286
 
1189
- ### `500`: "Upload failed.", or `422` with your database's message
1287
+ ### `503`: "The document could not be stored. Try again.", or `500` "Upload failed."
1288
+
1289
+ **Cause.** A store write that fails is a `DocumentStoreError` since 0.9.0 (it was thrown as it
1290
+ came, and answered `500` "Upload failed."). The upload handler answers it `503` with its message,
1291
+ "The document could not be stored (ENOSPC). Try again." when the store's error has a code, and
1292
+ `Retry-After: 5`. Your database's own message is its `cause`, and may name its host, so it is not
1293
+ sent, and the handlers log nothing.
1294
+
1295
+ An `ingest` of your own that throws a new error in its place, without a status, gets `500`
1296
+ "Upload failed." since 0.9.0. Before, it got `422` with that error's message, which could name your
1297
+ database's host (S12). Every case is in the [node reference](./reference/node.md#how-errors-are-answered).
1298
+
1299
+ **Fix.** Log `error.cause` where you catch it, and fix the storage. An `ingest` of your own must
1300
+ pass the `DocumentStoreError` on as it is, or rebuild it, as `ingestInProcess` in
1301
+ [Deployment](./guides/deployment.md#uploads-and-ingest) does. A route of your own answers it with
1302
+ `uploadAnswerOf` ([Web app](./guides/web-app.md#filesingest-and-its-errors)).
1190
1303
 
1191
- **Cause.** A store write that fails is thrown as it came, not as a `DocumentStoreError`. The upload
1192
- handler answers it `500` with `{ "error": "Upload failed." }` when it has no `status` (or
1193
- `statusCode`) from 400 to 599 and is not a Node system error with `code` and `syscall`. Its message
1194
- is your database's own and may name its host, so it is not sent, and the handlers log nothing.
1304
+ ### `500` "Upload failed." for a file your own `ingest` refused
1195
1305
 
1196
- Two paths answer it `422` with your database's message instead, as a file that cannot be read: an
1197
- `ingest` of your own that throws a new error in its place, as `ingestInProcess` in
1198
- [Deployment](./guides/deployment.md#uploads-and-ingest) does, and a route of your own, as in
1199
- [Web app](./guides/web-app.md#filesingest-and-its-errors). Every case is in the
1200
- [node reference](./reference/node.md#uploadrequest-response).
1306
+ **Cause.** Since 0.9.0, the upload handler answers `422` only an `IngestError`. A `LargeFiles` of
1307
+ your own whose `ingest` throws a plain `Error` for a file it refuses gets `500` "Upload failed.",
1308
+ without its message, which could name a host.
1201
1309
 
1202
- **Fix.** In a store of your own, log a write that fails, and throw an error with a `status` (a
1203
- `503`, say) whose message is fit for a user. An `ingest` of your own must copy that status, and a
1204
- system error's `code` and `syscall`, onto the error it throws, as `ingestInProcess` in
1205
- [Deployment](./guides/deployment.md#uploads-and-ingest) does.
1310
+ **Fix.** Throw `new IngestError(code, message)` (exported from `llm-large-files`), with a message
1311
+ written for the user. Its code says why: `"unreadable"`, `"too_large"`, `"no_text"`…
1206
1312
 
1207
1313
  See [Storage](./guides/storage.md) and [`llm-large-files/node` reference](./reference/node.md).
1208
1314
 
1209
- ### `500`: "Upload failed (ENOSPC)."
1315
+ ### `503`: "The document could not be stored (ENOSPC). Try again."
1210
1316
 
1211
- **Cause.** The disk of a `FileDocumentStore` is full. Expired documents are removed when they are
1317
+ **Cause.** The disk of a `FileDocumentStore` is full. (Before 0.9.0 the answer was `500` "Upload
1318
+ failed (ENOSPC).".) Expired documents are removed when they are
1212
1319
  next looked up, or by `files.sweep()`: one that nobody asks for again stays on disk until a sweep.
1213
1320
  Kept originals (`keepOriginals`) take space up to the upload limit each, until they expire.
1214
1321