llm-large-files 0.8.0 → 0.8.2
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 +147 -0
- package/README.md +2 -0
- package/dist/aggregate.d.ts +103 -0
- package/dist/aggregate.d.ts.map +1 -0
- package/dist/aggregate.js +651 -0
- package/dist/aggregate.js.map +1 -0
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +17 -0
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +8 -1
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +40 -2
- package/dist/extract.js.map +1 -1
- package/dist/library.d.ts +7 -0
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +112 -18
- package/dist/library.js.map +1 -1
- package/dist/limiter.d.ts +2 -2
- package/dist/limiter.js +2 -2
- package/dist/node/handlers.d.ts +15 -0
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +155 -36
- package/dist/node/handlers.js.map +1 -1
- package/dist/plan.d.ts +3 -1
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +17 -1
- package/dist/plan.js.map +1 -1
- package/dist/quality.d.ts +16 -0
- package/dist/quality.d.ts.map +1 -0
- package/dist/quality.js +157 -0
- package/dist/quality.js.map +1 -0
- package/dist/ranged.d.ts +7 -0
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +8 -1
- package/dist/ranged.js.map +1 -1
- package/dist/tools.d.ts +9 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +258 -5
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/guides/deployment.md +27 -6
- package/docs/guides/storage.md +5 -2
- package/docs/guides/web-app.md +14 -3
- package/docs/how-it-works.md +7 -0
- package/docs/measurements.md +20 -0
- package/docs/reference/library.md +22 -8
- package/docs/reference/node.md +30 -15
- package/docs/reference/tools.md +99 -1
- package/docs/security.md +15 -6
- package/docs/troubleshooting.md +28 -0
- package/package.json +1 -1
- package/src/aggregate.ts +674 -0
- package/src/evidence.ts +17 -0
- package/src/extract.ts +37 -2
- package/src/library.ts +116 -16
- package/src/limiter.ts +2 -2
- package/src/node/handlers.ts +159 -32
- package/src/plan.ts +17 -1
- package/src/quality.ts +146 -0
- package/src/ranged.ts +8 -1
- package/src/tools.ts +249 -5
- package/src/types.ts +17 -0
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtH,MAAM,MAAM,YAAY,GAAG;IACzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,4FAA4F;IAC5F,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAA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AAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG;IACzB,sDAAsD;IACtD,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,sDAAsD;IACtD,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,iGAAiG;IACjG,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,mGAAmG;IACnG,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B,CAAC"}
|
|
@@ -20,6 +20,8 @@ rebuild from the store.
|
|
|
20
20
|
| Which documents belong to which user or chat | Your application, and `owner` on each document | Yours to share | Yours |
|
|
21
21
|
| Documents ready to search, decoded pieces of large ones, line indexes | A cache in each `LargeFiles`, within `cacheBytes` | No | Empty; filled again from the store |
|
|
22
22
|
| Searches of large files waiting their turn | A queue in each `LargeFiles` (`maxConcurrentScans`) | No | Empty |
|
|
23
|
+
| Ingests waiting their turn | A queue in each `LargeFiles` (`maxConcurrentIngests`, new in 0.8.2) | No | Empty: the uploads in it get no answer, and must be sent again |
|
|
24
|
+
| Uploads being received | A count in each set of `createDocumentHandlers` (`maxPendingUploadBytes`, new in 0.8.2) | No | Empty |
|
|
23
25
|
| The output limit a thinking model needs for whole-file part reads | Each process, by URL and model | No | Learned again, at the cost of one request |
|
|
24
26
|
| The name of the output limit an OpenAI-compatible server takes | Each `openAiCompatible()` adapter | No | Learned again, at the cost of one refused request |
|
|
25
27
|
|
|
@@ -95,10 +97,10 @@ The built-in stores:
|
|
|
95
97
|
| Documents kept ready to search | Up to `cacheBytes`, 256 MB by default | `cacheBytes`; `cacheSize` also caps their number |
|
|
96
98
|
| A document loaded whole: text up to `wholeDocumentBytes` (2 MB), or any size when the store has no `readTextRange` | Its text and a lowercased copy: 2 bytes a character for ASCII text, 4 for any other | Counted in `cacheBytes`. One larger than `cacheBytes` is loaded again for each call and not kept |
|
|
97
99
|
| A document read by range | Its line index: about 8 bytes a line (8.2 MB for a log of a million lines) | Counted in `cacheBytes` |
|
|
98
|
-
| Searches of documents read by range |
|
|
100
|
+
| Searches of documents read by range | Tens of MB each at their peak (60 to 80 MB for a search of a log of 95 MB on Windows; 49 MB above the process for one of 100 MB on Linux, [measurements](../measurements.md#the-server)): `scanChunkBytes` (1 MB) of text read, decoded and lowercased, the next piece read ahead, and what the pieces leave until the next collection | `maxConcurrentScans` (4) per `LargeFiles`. The others wait, and those waiting for the same file share one pass over it |
|
|
99
101
|
| Decoded pieces of a document read by range | Up to its whole decoded text | Kept within `cacheBytes`, and only for a document whose decoded text takes at most a quarter of it |
|
|
100
|
-
| An upload | The body, buffered whole | `maxUploadBytes
|
|
101
|
-
| An ingest |
|
|
102
|
+
| An upload | The body, buffered whole, from the reading of the body to the end of its ingest. 100 uploads of 2 MB sent at once held 190 MB | `maxUploadBytes` (100 MB by default) for one; `maxPendingUploadBytes` of `createDocumentHandlers` (twice `maxUploadBytes`) for all those the handlers hold, the others answered 503 before their body is read. A route of your own must bound them itself (below) |
|
|
103
|
+
| An ingest | Five to seven times the file above the uploaded bytes at its peak (below): several copies of the text at once (below), and what the parsers of PDF, DOCX, PPTX and XLSX take while they read. `maxConcurrentIngests` (2 by default) of them at once in a `LargeFiles`; the others wait, holding only their upload. A crafted PDF can make them take far more: one of 732 bytes ran a heap of 512 MB out of memory, and one of 1.6 KB took 1.6 GB of memory outside the heap, with 20 MB of heap, for a stream that unpacks to 512 MB ([Security](../security.md#uploads)) | `maxTextBytes` bounds the text (100 MB by default). Nothing in the server bounds what the parsers build or unpack: read PDF and Office files with `createIsolatedExtractors`, in child processes with a heap limit of their own, or ingest in a process of its own with a memory limit of its own (below) |
|
|
102
104
|
| A look at the pages of a PDF (`view_pages`) | The whole original, read and parsed: about twice the size of the file, plus 1 to 1.6 KB for each object in it (about 300 MB for a 100 MB file of photos, 700 MB for 54 MB of 330,000 objects). A crafted file can take far more: a look at a PDF of 8 MB that is one array of numbers took 422 to 427 MB of heap, one of 16 MB ran a heap of 512 MB out of memory, and one at the PDF of 1.6 KB above took 1.1 GB outside the heap. What `@cantoo/pdf-lib` keeps after a look adds up from file to file, until the server restarts | Refused for a file that declares more than 1,000,000 objects, or more objects than about 60% of the free heap can hold. A crafted file of few objects passes that check. Ingested in a process of its own (below), with `@cantoo/pdf-lib` installed, a file that needs more than that process's heap fails there and is not stored; one that fits is parsed again by each look, which takes more than its ingest did (232 to 244 MB for that file of 8 MB). For the documents of users you do not trust, `viewPages: false`, or no PDF originals |
|
|
103
105
|
| A question in flight | Its conversation, and each request it builds: up to `maxRequestBytes` (10 MB by default) of JSON, the pages it was shown included as base64 | The budget ([Costs and limits](./costs-and-limits.md)) |
|
|
104
106
|
|
|
@@ -174,6 +176,7 @@ export const files = createLargeFiles({
|
|
|
174
176
|
keepOriginals: ["pdf"], // view_pages: a look reads the whole PDF into this heap
|
|
175
177
|
cacheBytes: 256 * 1024 * 1024, // the default
|
|
176
178
|
maxConcurrentScans: 4, // the default
|
|
179
|
+
maxConcurrentIngests: 2, // the default: the others wait their turn
|
|
177
180
|
maxUploadBytes: 100 * 1024 * 1024, // the default
|
|
178
181
|
});
|
|
179
182
|
```
|
|
@@ -195,6 +198,17 @@ body whose `Content-Length` is over `maxUploadBytes` before reading it, and stop
|
|
|
195
198
|
grows past it (HTTP 413). Node's own `server.requestTimeout` (300,000 ms by default) ends an upload
|
|
196
199
|
that takes longer than five minutes to arrive: raise it for users on slow links.
|
|
197
200
|
|
|
201
|
+
Since 0.8.2 the handlers hold uploads of at most `maxPendingUploadBytes` at once (twice
|
|
202
|
+
`maxUploadBytes` by default), and answer one that would pass it 503 with `Retry-After: 5` before
|
|
203
|
+
reading its body. The room of an upload is taken before its body arrives, from its `Content-Length`
|
|
204
|
+
(or `maxUploadBytes` when it declares none), so a client that sends headers and then nothing, or
|
|
205
|
+
trickles, holds room it does not use: an upload whose body stops arriving for
|
|
206
|
+
`uploadIdleTimeoutMs` (30 s) is answered 408 and its room given back, but a client that sends a byte
|
|
207
|
+
now and then keeps it until `server.requestTimeout`. Behind a reverse proxy that reads the whole
|
|
208
|
+
body before it passes the request on (nginx does by default, `proxy_request_buffering on`), bodies
|
|
209
|
+
arrive at once and none of this happens; otherwise, limit the connections of each client at the
|
|
210
|
+
proxy.
|
|
211
|
+
|
|
198
212
|
An ingest runs in your server's process, a slice at a time. It pauses for other requests about
|
|
199
213
|
every 12 ms of its work, so an answer streaming on the same server waits a fraction of a second,
|
|
200
214
|
not seconds: the longest stall measured was 34 ms for a 99 MB log and 0.16 s for a 2,000-page
|
|
@@ -240,8 +254,14 @@ end after the time limit. Four ways to bound that:
|
|
|
240
254
|
to 704 MB, depending on the version of Node, as the tables above show) and a kill timer (120 s),
|
|
241
255
|
and a file that runs the child out of memory is refused while the server goes on.
|
|
242
256
|
- **Accept one or two ingests at a time** per server, and answer the others with 503: this bounds
|
|
243
|
-
memory and keeps stalls from adding up.
|
|
244
|
-
|
|
257
|
+
memory and keeps stalls from adding up. Since 0.8.2 the library does it by default: each
|
|
258
|
+
`LargeFiles` lets `maxConcurrentIngests` (2) ingests work at once and queues the others, and
|
|
259
|
+
`createDocumentHandlers` answers 503 with `Retry-After` once it holds `maxPendingUploadBytes`
|
|
260
|
+
(twice `maxUploadBytes`) of uploads, before reading the next body. A route of your own around
|
|
261
|
+
`files.ingest` gets the queue, but must bound the bodies it reads itself: count the bytes of the
|
|
262
|
+
uploads it holds, and answer 503 before reading one that would pass your limit.
|
|
263
|
+
`createIsolatedExtractors` bounds the files it reads too (`concurrency` and `maxQueue`); the
|
|
264
|
+
recipe at the end of this section runs whole ingests in a process of their own.
|
|
245
265
|
- **Ingest in a process of its own**, the whole ingest, with a heap limit and a time limit: at the
|
|
246
266
|
end of this section. It also keeps the copies of the text off your server's heap, and runs an
|
|
247
267
|
extractor of your own, such as OCR, apart. A process that runs out of memory stops alone, and the
|
|
@@ -253,7 +273,8 @@ end after the time limit. Four ways to bound that:
|
|
|
253
273
|
own `createLargeFiles` and `createDocumentHandlers`, on servers sized for uploads, can write the
|
|
254
274
|
documents that the chat servers read. Give it the options that apply at ingest, the same as the
|
|
255
275
|
chat servers would have: `ttlMs`, `maxUploadBytes`, `maxTextBytes`, `maxPdfPages`,
|
|
256
|
-
`ingestTimeoutMs`, `extractors`, `keepOriginals` and `
|
|
276
|
+
`ingestTimeoutMs`, `extractors`, `keepOriginals`, `scannedPdfPages` and `maxConcurrentIngests`,
|
|
277
|
+
and to its handlers `maxPendingUploadBytes` and `uploadIdleTimeoutMs`. The chat servers need the
|
|
257
278
|
options that apply to reading: `cacheBytes`, `cacheSize`, `wholeDocumentBytes`, `scanChunkBytes`,
|
|
258
279
|
`maxConcurrentScans` and `budget`.
|
|
259
280
|
|
package/docs/guides/storage.md
CHANGED
|
@@ -268,8 +268,11 @@ MongoDB ObjectIds in lower-case hex, pass it as they are.
|
|
|
268
268
|
|
|
269
269
|
What that costs:
|
|
270
270
|
|
|
271
|
-
- `cacheBytes` and `
|
|
272
|
-
|
|
271
|
+
- `cacheBytes`, `maxConcurrentScans` and `maxConcurrentIngests` bound each library, not the process,
|
|
272
|
+
and `maxPendingUploadBytes` each set of upload handlers. With a library per chat, ingests of
|
|
273
|
+
different chats all work at once, as before 0.8.2: bound them for the process yourself, with one
|
|
274
|
+
queue or count shared by the chats' routes. A library made for one request starts with an empty
|
|
275
|
+
cache, so each question reads its documents from the store again.
|
|
273
276
|
- Each chat's folder needs a sweep of its own: `new FileDocumentStore(folder).sweep()` for each one.
|
|
274
277
|
The store never removes the folder itself.
|
|
275
278
|
- Deleting a chat is removing its folder, once no question of that chat is running.
|
package/docs/guides/web-app.md
CHANGED
|
@@ -211,7 +211,9 @@ for the file saved as UTF-8.
|
|
|
211
211
|
|
|
212
212
|
Everything else is JSON `{ "error": "…" }`, with a message you can show: `400` for a missing name or
|
|
213
213
|
a body another middleware already parsed, `413` over `maxUploadBytes`, `422` for a file that cannot
|
|
214
|
-
be read,
|
|
214
|
+
be read, `503` with `Retry-After` when the server holds as many uploads as it takes at once or its
|
|
215
|
+
readers are busy (send the file again after `Retry-After` seconds), `408` for a body that stopped
|
|
216
|
+
arriving, an error's own status (400 to 599) from `getOwner`, an extractor or your store, and `500`
|
|
215
217
|
for a failure of the server, among them `Upload failed (empty owner).` and
|
|
216
218
|
`Upload failed (owner is not a string).` ([above](#who-owns-an-upload-getowner)). `get` answers
|
|
217
219
|
`404` for a document this owner cannot see, and `get` and `remove` answer `500` when the store
|
|
@@ -417,6 +419,8 @@ export async function uploadFromRequest(request: Request, owner: string): Promis
|
|
|
417
419
|
// Not URI-encoded: keep it as it came.
|
|
418
420
|
}
|
|
419
421
|
if (!name.trim()) return Response.json({ error: "Name the file with an X-File-Name header." }, { status: 400 });
|
|
422
|
+
// This route reads the body before ingest: bound the bytes it holds at once yourself, as
|
|
423
|
+
// createDocumentHandlers does with maxPendingUploadBytes (Deployment, Uploads and ingest).
|
|
420
424
|
|
|
421
425
|
const tooLarge = { error: "The file is larger than the upload limit." };
|
|
422
426
|
if (Number(request.headers.get("content-length")) > files.maxUploadBytes) return Response.json(tooLarge, { status: 413 });
|
|
@@ -506,7 +510,7 @@ import type { DocumentSummary } from "llm-large-files";
|
|
|
506
510
|
|
|
507
511
|
/** Sends one file to POST /api/documents. Throws with a message you can show. */
|
|
508
512
|
export async function uploadFile(file: File): Promise<DocumentSummary> {
|
|
509
|
-
const
|
|
513
|
+
const send = () => fetch("/api/documents", {
|
|
510
514
|
method: "POST",
|
|
511
515
|
headers: {
|
|
512
516
|
"Content-Type": "application/octet-stream",
|
|
@@ -515,6 +519,13 @@ export async function uploadFile(file: File): Promise<DocumentSummary> {
|
|
|
515
519
|
},
|
|
516
520
|
body: file,
|
|
517
521
|
});
|
|
522
|
+
let response = await send();
|
|
523
|
+
// A busy server (503) says when to try again: twice more, then its message is shown.
|
|
524
|
+
for (let attempt = 0; response.status === 503 && attempt < 2; attempt++) {
|
|
525
|
+
const seconds = Number(response.headers.get("retry-after")) || 5;
|
|
526
|
+
await new Promise((resolve) => setTimeout(resolve, seconds * 1_000));
|
|
527
|
+
response = await send();
|
|
528
|
+
}
|
|
518
529
|
// An error page of a proxy (a 413 or a 502) is not JSON: the status then makes the message.
|
|
519
530
|
const result = (await response.json().catch(() => ({}))) as Partial<DocumentSummary> & { error?: string };
|
|
520
531
|
if (!response.ok || !result.id) throw new Error(result.error ?? `The upload failed (HTTP ${response.status}).`);
|
|
@@ -539,7 +550,7 @@ export async function uploadFile(file: File): Promise<DocumentSummary> {
|
|
|
539
550
|
New in 0.7.0. A large PDF or DOCX can take a while to read once it has arrived. Send the same
|
|
540
551
|
request with `Accept: text/event-stream`, and `upload` answers with the ingest's events as
|
|
541
552
|
Server-Sent Events: how far each stage is, then the summary. The checks that run before the ingest
|
|
542
|
-
(the name, `getOwner`, a body already parsed, the size) still answer with their status and JSON, so
|
|
553
|
+
(the name, `getOwner`, a body already parsed, the size, the room for uploads held at once) still answer with their status and JSON, so
|
|
543
554
|
read the response as JSON when it is not `200`:
|
|
544
555
|
|
|
545
556
|
```ts
|
package/docs/how-it-works.md
CHANGED
|
@@ -14,6 +14,7 @@ question ─► plan the documents for the room left in the request, smallest fi
|
|
|
14
14
|
└─ too big ──► its card in the first user turn
|
|
15
15
|
+ the tool guide in the system instruction
|
|
16
16
|
+ tools: search · read · overview
|
|
17
|
+
· aggregate (when a file may hold a table)
|
|
17
18
|
· analyze-all (when the exploring model can read parts
|
|
18
19
|
and a file is within maxMapChunks)
|
|
19
20
|
a kept PDF, in either branch, when every model can be sent a file
|
|
@@ -474,6 +475,12 @@ rules every tool follows, are in the [tools reference](./reference/tools.md).
|
|
|
474
475
|
the first and last lines, and about how many parts a whole-file read would take. That count is
|
|
475
476
|
estimated from the metadata, without reading the text, and the overview says when it is over
|
|
476
477
|
`maxMapChunks`.
|
|
478
|
+
- **`aggregate_table`** (new in 0.8.1) counts, sums, averages and groups the rows of one table of a
|
|
479
|
+
file: a CSV file, a sheet of a workbook, a `| cell |` table of another document. It reads every
|
|
480
|
+
row once, finds the header (a title row above it, a header of two or three rows), and runs no
|
|
481
|
+
code, so a total over 50,000 rows is exact and costs one call; each group cites the lines of its
|
|
482
|
+
first rows ([`aggregate_table`](./reference/tools.md#aggregate_table)). It is declared when a
|
|
483
|
+
searchable file is a CSV, XLSX, DOCX, PPTX, PDF, HTML or Markdown file.
|
|
477
484
|
- **`analyze_whole_document`** reads a whole file in parts ([Map-reduce](#map-reduce)). It is
|
|
478
485
|
declared when the exploring model has a part reader (`generateText`), `wholeDocumentAnalysis` is
|
|
479
486
|
not `false`, and at least one searchable file is estimated within `maxMapChunks`.
|
package/docs/measurements.md
CHANGED
|
@@ -358,6 +358,26 @@ MB, and about 220 MB with `cacheBytes` at 1 GB, which keeps the decoded pieces.
|
|
|
358
358
|
event loop for about 0.8 to 1.5 seconds (25 MB) and 3 to 5 seconds (95 MB). Linux was not
|
|
359
359
|
measured. [Deployment](./guides/deployment.md) turns these into sizing advice.
|
|
360
360
|
|
|
361
|
+
**Many uploads at once (0.8.2, November 2026, Node 22 on Linux, 8 cores).** 100 logs of 2 MB
|
|
362
|
+
(190.7 MB, about 10% of the lines in Hebrew), read into memory first as the upload handler does,
|
|
363
|
+
then all sent to `files.ingest` at once, over a `FileDocumentStore` on a local disk. Peak memory
|
|
364
|
+
is the resident set the kernel recorded; the machine ran other work too.
|
|
365
|
+
|
|
366
|
+
| `maxConcurrentIngests` | Peak memory | Peak heap | First answered | Half answered | All answered |
|
|
367
|
+
|---|---|---|---|---|---|
|
|
368
|
+
| `Infinity` (0.8.1) | 817 to 830 MB | 475 MB | 25 to 39 s | 27 to 40 s | 28 to 42 s |
|
|
369
|
+
| 4 | 391 MB | 105 MB | 0.9 s | 13.8 s | 29.9 s |
|
|
370
|
+
| 2 (the default since 0.8.2), 2 runs | 329 to 356 MB | 48 to 74 MB | 0.5 to 0.7 s | 13.4 to 17.4 s | 27.6 to 33.4 s |
|
|
371
|
+
|
|
372
|
+
About 190 MB of each peak is the 100 uploads, held until their ingest ends. Ingests at once share
|
|
373
|
+
one thread, so taking turns costs no time overall. One upload of 100 MB took a peak of 560 MB, and
|
|
374
|
+
one of 50 MB 325 to 345 MB from a process of about 70 MB. After the ingests the heap is back at
|
|
375
|
+
about 10 MB: nothing of a document stays in memory with a `FileDocumentStore`. Until 0.8.2 the
|
|
376
|
+
meta that `ingest` returned kept the whole text in memory while it was held (194 MB of heap for
|
|
377
|
+
the meta of the 100 MB log). A search of that 100 MB log, read by range in a new process of 59 MB,
|
|
378
|
+
took a peak of 108 MB (49 MB above the process, 1.8 s); eight at once took 115 to 159 MB, and up
|
|
379
|
+
to 9 s.
|
|
380
|
+
|
|
361
381
|
**Ingest of large and hostile files (0.6.0, November 2026, Node 24 on Windows).** Each file was
|
|
362
382
|
ingested into a `MemoryDocumentStore` in a fresh process, with the parsers loaded first, 5157e7f
|
|
363
383
|
(which ingests as 0.5.0 does) and 0.6.0 in turn, on a machine that ran other work too. A stall is
|
|
@@ -45,7 +45,7 @@ Contents:
|
|
|
45
45
|
- [Extraction](#extraction): [`Extractor`](#extractor), [`ExtractInput`](#extractinput),
|
|
46
46
|
[`ExtractProgress`](#extractprogress), [`ExtractedText`](#extractedtext), [`defaultExtractors`](#defaultextractors),
|
|
47
47
|
[`createPdfExtractor(options?)`](#createpdfextractoroptions), [`PdfExtractorOptions`](#pdfextractoroptions),
|
|
48
|
-
[`detectFormat(name, mimeType)`](#detectformatname-mimetype)
|
|
48
|
+
[`detectFormat(name, mimeType)`](#detectformatname-mimetype-bytes)
|
|
49
49
|
- [Text sizes](#text-sizes): [`estimateTokens(text)`](#estimatetokenstext), [`utf8Bytes(text)`](#utf8bytestext),
|
|
50
50
|
[`jsonBytes(text)`](#jsonbytestext)
|
|
51
51
|
- [Document types](#document-types): [`DocumentMeta`](#documentmeta), [`DocumentSummary`](#documentsummary),
|
|
@@ -107,6 +107,7 @@ type LargeFilesOptions = {
|
|
|
107
107
|
wholeDocumentBytes?: number;
|
|
108
108
|
scanChunkBytes?: number;
|
|
109
109
|
maxConcurrentScans?: number;
|
|
110
|
+
maxConcurrentIngests?: number;
|
|
110
111
|
now?: () => Date;
|
|
111
112
|
};
|
|
112
113
|
```
|
|
@@ -119,7 +120,7 @@ type LargeFilesOptions = {
|
|
|
119
120
|
| `maxUploadBytes` | `number` | 100 MB (104,857,600) | The largest file `ingest` accepts. The upload handler of [`llm-large-files/node`](./node.md) reads no more than this. |
|
|
120
121
|
| `maxTextBytes` | `number` | [`DEFAULT_MAX_TEXT_BYTES`](#default_max_text_bytes), 100 MB, or `maxUploadBytes` when that is larger | The most text kept from one file, in UTF-8 bytes. A file's text can be larger than the file: a PDF of 3 KB built for it drew 107 MB. The PDF, DOCX, PPTX and XLSX extractors refuse a file as soon as its text passes this (a PDF page by page, and also past 100 times its size after the first 16 MB; an Office file also past 32 million characters, whatever this allows), and `ingest` refuses a larger text from any other extractor, the text extractor and yours included. Your extractor receives it as `ExtractInput.maxTextBytes`. At least 1. |
|
|
121
122
|
| `maxPdfPages` | `number` | [`DEFAULT_MAX_PDF_PAGES`](#default_max_pdf_pages), 5,000 | The most pages read from one PDF. A PDF with more is refused before any page is read. Your PDF extractor receives it as `ExtractInput.maxPages`. At least 1. |
|
|
122
|
-
| `ingestTimeoutMs` | `number` | [`DEFAULT_INGEST_TIMEOUT_MS`](#default_ingest_timeout_ms), 120,000 (2 minutes) | The most time one `ingest` may take to extract the text, build its line index and profile it, in milliseconds. The store's writes are not counted. Past it, `ingest` throws `<name> took too long to read (more than 2 min). Split it, or save it as plain text, and attach that.`, and stores nothing. 0 sets no limit, and so does a value past what a timer can wait (2,147,483,647 ms, 24.8 days). Your extractor receives the limit as `ExtractInput.signal`. Within one page of a PDF the limit is not looked at: see [security](../security.md#uploads). |
|
|
123
|
+
| `ingestTimeoutMs` | `number` | [`DEFAULT_INGEST_TIMEOUT_MS`](#default_ingest_timeout_ms), 120,000 (2 minutes) | The most time one `ingest` may take to extract the text, build its line index and profile it, in milliseconds. The store's writes are not counted, but a store write that does not end within this time (2 minutes when it is 0) fails the ingest with `The store did not finish writing <name> within 2 min.`, as a failure of the store, and the document is removed once the write ends (new in 0.8.2). Past it, `ingest` throws `<name> took too long to read (more than 2 min). Split it, or save it as plain text, and attach that.`, and stores nothing. 0 sets no limit, and so does a value past what a timer can wait (2,147,483,647 ms, 24.8 days). Your extractor receives the limit as `ExtractInput.signal`. Within one page of a PDF the limit is not looked at: see [security](../security.md#uploads). |
|
|
123
124
|
| `extractors` | `Partial<Record<DocumentFormat, Extractor>>` | the built-ins, [`defaultExtractors`](#defaultextractors) | An [`Extractor`](#extractor) per format, used in place of the built-in one. The formats are fixed ([`DocumentFormat`](#documentformat)): you can replace the extractor of a format, not add a format. |
|
|
124
125
|
| `keepOriginals` | `DocumentFormat[]` | `[]` | Formats whose uploaded file is kept in the store next to its text, for example `["pdf"]`, which `view_pages` needs. Takes effect only with a store that has `putOriginal`. A kept file takes as much space as the upload until its document expires or is deleted. |
|
|
125
126
|
| `scannedPdfPages` | `number` | 30 | The most pages a PDF without any text (a scan) may have and still be accepted, so that its pages can be shown to the model. It applies only when `"pdf"` is in `keepOriginals` and the store has `putOriginal`. Otherwise, and with 0, such a PDF is refused. Your own PDF extractor receives it as `ExtractInput.scannedPages`. |
|
|
@@ -128,10 +129,12 @@ type LargeFilesOptions = {
|
|
|
128
129
|
| `wholeDocumentBytes` | `number` | [`DEFAULT_WHOLE_DOCUMENT_BYTES`](#default_whole_document_bytes), 2 MB | Documents whose text (`textBytes`) is at most this size are loaded whole into memory. Larger ones are read by range when the store has `readTextRange`, as `FileDocumentStore` does: a tool call reads only the lines it needs, and a search reads the text a piece at a time. `Infinity` loads every document whole; 0 reads every one by range. |
|
|
129
130
|
| `scanChunkBytes` | `number` | 1 MB (1,048,576) | Reading by range: about how many bytes of text are read and searched at a time. At least 1. |
|
|
130
131
|
| `maxConcurrentScans` | `number` | 4 | Reading by range: how many scans of whole documents (searches, counting the parts of a file) run at once in this library (each `createLargeFiles` call has its own queue). The others wait their turn. At least 1. |
|
|
132
|
+
| `maxConcurrentIngests` | `number` | 2 | How many ingests do their work at once in this library. The others wait their turn, in the order they came; their `ingestTimeoutMs` starts when their turn comes, and a caller that aborts its `signal` while it waits gets its own reason, with nothing stored. An empty file, or one over `maxUploadBytes`, is refused without waiting. An ingest holds about five times its file in memory while it works, and the steps it runs in your server's thread share that thread with the others: more of them at once do not finish sooner (100 logs of 2 MB: all answered in 28 to 42 s all at once, 28 to 33 s two at a time, with a peak of 817 to 830 MB of memory against 329 to 356 MB). An ingest keeps its turn until its work ends: when its time is up or its caller left while an extractor goes on (one that does not stop on the signal, such as the parse of a PDF by `@cantoo/pdf-lib`), until that extractor ends; such an extractor that never ends gives the turn back after `ingestTimeoutMs` more (2 minutes when that is 0), and a store write that never ends fails the ingest after `ingestTimeoutMs` (above). An extractor of your own must not wait on an ingest of the same library (to store the parts of an archive, say): that ingest waits for a turn like any other, and with every turn held by such extractors, each waits on itself until its time is up. With [`createIsolatedExtractors`](./node.md#createisolatedextractorsoptions), at most this many files reach its readers at once from this library. `Infinity` for no limit, as before 0.8.2. At least 1. New in 0.8.2. |
|
|
131
133
|
| `now` | `() => Date` | `() => new Date()` | The clock, for tests. It dates `createdAt` and `expiresAt`, decides whether a document has expired, and is passed to the store's `sweep`. |
|
|
132
134
|
|
|
133
135
|
Since 0.7.1, `ttlMs`, `maxUploadBytes`, `scannedPdfPages`, `cacheBytes`, `cacheSize`,
|
|
134
|
-
`wholeDocumentBytes`, `scanChunkBytes` and `maxConcurrentScans`
|
|
136
|
+
`wholeDocumentBytes`, `scanChunkBytes` and `maxConcurrentScans` (and `maxConcurrentIngests`, new in
|
|
137
|
+
0.8.2) are checked when the library is
|
|
135
138
|
made: NaN, which `Number(process.env.X)` gives for a variable that is not set, throws a
|
|
136
139
|
`RangeError` ("maxConcurrentScans must be a number, and is NaN. Leave it out for the default."),
|
|
137
140
|
a value that is not a number throws a `TypeError`, and so does `Infinity` for `scanChunkBytes`. NaN
|
|
@@ -179,7 +182,7 @@ Extracts the text of a file, normalizes it, profiles it, and stores it under a n
|
|
|
179
182
|
new document's [`DocumentMeta`](#documentmeta).
|
|
180
183
|
|
|
181
184
|
1. The owner is checked (see [`IngestInput`](#ingestinput)), the name is cleaned, and the format
|
|
182
|
-
is picked by [`detectFormat(name, mimeType)`](#detectformatname-mimetype).
|
|
185
|
+
is picked by [`detectFormat(name, mimeType)`](#detectformatname-mimetype-bytes).
|
|
183
186
|
2. The extractor of that format turns the bytes into text. It receives the limits `maxTextBytes`
|
|
184
187
|
and `maxPdfPages`, the ingest's signal, and, when someone listens to the ingest's events, an
|
|
185
188
|
`onProgress` to report how far it is ([`ExtractInput`](#extractinput)). A text longer
|
|
@@ -1254,14 +1257,19 @@ type PdfExtractorOptions = { tables?: boolean; pictures?: boolean; checkPages?:
|
|
|
1254
1257
|
| `pictures` | `boolean` | `true` | Writes `[Picture on this page. This text cannot show it.]` under the page line of every page that shows a picture or a drawing, so the model knows that the text does not tell all of that page. Needs the optional dependency `@cantoo/pdf-lib`; without it, and with `false`, no page is marked. |
|
|
1255
1258
|
| `checkPages` | `boolean` | `true` | Before pdf.js reads any page, adds up what each page would make it run, and refuses a file with a page that would hold the server for a long time ([Pages that would hold the server](../guides/pdfs.md#pages-that-would-hold-the-server)). Needs the optional dependency `@cantoo/pdf-lib`; without it, and with `false`, every page is read however long it takes. With `false` and `pictures: false`, the file is not read with `@cantoo/pdf-lib` at ingest. New in 0.6.0. |
|
|
1256
1259
|
|
|
1257
|
-
### detectFormat(name, mimeType)
|
|
1260
|
+
### detectFormat(name, mimeType, bytes?)
|
|
1258
1261
|
|
|
1259
1262
|
```ts
|
|
1260
|
-
declare function detectFormat(name: string, mimeType: string): DocumentFormat;
|
|
1263
|
+
declare function detectFormat(name: string, mimeType: string, bytes?: Uint8Array): DocumentFormat;
|
|
1261
1264
|
```
|
|
1262
1265
|
|
|
1263
1266
|
The format of a file: from the extension after the last dot (in any case), then from the MIME type,
|
|
1264
|
-
else `"text"`.
|
|
1267
|
+
else `"text"`. New in 0.8.1: with `bytes`, a file that would be `"text"` and is not named `.txt`
|
|
1268
|
+
is known by its content: `"pdf"` when it starts with `%PDF-` (after a byte order mark or white
|
|
1269
|
+
space), `"docx"`, `"pptx"` or `"xlsx"` for a ZIP archive with the parts of one (`word/document.xml`,
|
|
1270
|
+
`ppt/presentation.xml`, `xl/workbook.xml`), `"html"` when it starts with `<!DOCTYPE html` or
|
|
1271
|
+
`<html`. `ingest` passes the bytes: a DOCX uploaded without its extension was told "This file is a
|
|
1272
|
+
ZIP archive". The MIME type is lowercased and compared whole, so `text/csv; charset=utf-8` names no
|
|
1265
1273
|
format. A name without a dot is looked up whole, so a file named `log` is a `log`. `ingest` uses it,
|
|
1266
1274
|
then turns a `"text"` document that reads like a log into `"log"`.
|
|
1267
1275
|
|
|
@@ -1343,6 +1351,9 @@ type DocumentMeta = {
|
|
|
1343
1351
|
originalKept?: boolean;
|
|
1344
1352
|
outline: OutlineEntry[];
|
|
1345
1353
|
logProfile?: LogProfile;
|
|
1354
|
+
pagesWithoutText?: number[]; // new in 0.8.1
|
|
1355
|
+
garbledPages?: number[]; // new in 0.8.1
|
|
1356
|
+
scripts?: Array<{ script: string; percent: number }>; // new in 0.8.1
|
|
1346
1357
|
createdAt: string;
|
|
1347
1358
|
expiresAt: string;
|
|
1348
1359
|
};
|
|
@@ -1372,6 +1383,9 @@ browser instead.
|
|
|
1372
1383
|
| `originalKept` | `boolean \| undefined` | `true` when the uploaded file is kept in the store (`keepOriginals`). Absent otherwise. Documents ingested before you turned `keepOriginals` on have no original. |
|
|
1373
1384
|
| `outline` | [`OutlineEntry[]`](#outlineentry) | The headings found in the text, at most 400. Empty for `log`, `json` and `csv`. |
|
|
1374
1385
|
| `logProfile` | [`LogProfile`](#logprofile) or `undefined` | The log profile, for a `log` document only. |
|
|
1386
|
+
| `pagesWithoutText` | `number[]` or `undefined` | The pages of a PDF with no text at all (scans, photos, charts), up to 200. Absent when there are none, and on documents from before 0.8.1. The card names them, and points to `view_pages` when they can be looked at. New in 0.8.1. |
|
|
1387
|
+
| `garbledPages` | `number[]` or `undefined` | The pages of a PDF whose text looks garbled: of at least 40 characters, fewer than 3 in 10 letters or digits, or more than max(6, 3%) replacement characters (a font without a Unicode map). Up to 200. The card says not to rely on them. New in 0.8.1. |
|
|
1388
|
+
| `scripts` | `{ script, percent }[]` or `undefined` | The scripts of the text by their share of its letters, from its first 2 MB, those of 5% or more: "Latin", "Hebrew", "Arabic", "Cyrillic", "Greek", "CJK", "Devanagari", "Thai". Absent for a text in Latin letters alone, one with fewer than 200 letters, and documents from before 0.8.1. The card says "Written in: Hebrew 81%, Latin 19%. Search in the language of the text." New in 0.8.1. |
|
|
1375
1389
|
| `createdAt` | `string` | When it was ingested, as an ISO 8601 date. |
|
|
1376
1390
|
| `expiresAt` | `string` | When it expires, as an ISO 8601 date: `createdAt` plus `ttlMs`, or [`NEVER_EXPIRES`](#never_expires). |
|
|
1377
1391
|
|
|
@@ -1411,7 +1425,7 @@ type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "do
|
|
|
1411
1425
|
```
|
|
1412
1426
|
|
|
1413
1427
|
The format of a document. It picks the extractor and decides whether a document gets an outline (not
|
|
1414
|
-
`log`, `json` or `csv`) and a log profile (`log` only). See [`detectFormat`](#detectformatname-mimetype),
|
|
1428
|
+
`log`, `json` or `csv`) and a log profile (`log` only). See [`detectFormat`](#detectformatname-mimetype-bytes),
|
|
1415
1429
|
and for what each extractor writes, [`defaultExtractors`](#defaultextractors).
|
|
1416
1430
|
|
|
1417
1431
|
`"xlsx"` (Excel workbooks) and `"html"` (web pages) are new in 0.8.0: an exhaustive `switch` on a
|
package/docs/reference/node.md
CHANGED
|
@@ -50,10 +50,12 @@ included, and never rejects, so it can be called without a `catch`.
|
|
|
50
50
|
| Parameter | Type | Default | What it does |
|
|
51
51
|
|---|---|---|---|
|
|
52
52
|
| `files` | [`LargeFiles`](./library.md#largefiles) | required | The library that uploads are ingested into and documents are looked up in. Its `maxUploadBytes` ([`LargeFilesOptions`](./library.md#largefilesoptions), 100 MB by default) is the upload limit. |
|
|
53
|
-
| `options` | [`DocumentHandlerOptions`](#documenthandleroptions) | `{}` | Who owns a request. |
|
|
53
|
+
| `options` | [`DocumentHandlerOptions`](#documenthandleroptions) | `{}` | Who owns a request, how many bytes of uploads are held at once, and how long a body may stop arriving. |
|
|
54
54
|
|
|
55
|
-
**Returns** the three [`DocumentHandlers`](#documenthandlers). It makes no request
|
|
56
|
-
store
|
|
55
|
+
**Returns** the three [`DocumentHandlers`](#documenthandlers). It makes no request and reads no
|
|
56
|
+
store. It throws a `RangeError` for a `maxPendingUploadBytes` or `uploadIdleTimeoutMs` that is not
|
|
57
|
+
a number in range, and a `TypeError` when `files` has no `maxUploadBytes` above 0 (a `LargeFiles`
|
|
58
|
+
of your own, from JavaScript, must keep the one of the library it wraps; new in 0.8.2).
|
|
57
59
|
|
|
58
60
|
The handlers do not check the method or the path of a request: route each request to the one you
|
|
59
61
|
mean. Every response they write has the header `Content-Type: application/json; charset=utf-8`
|
|
@@ -94,6 +96,8 @@ upload route of your own for multipart forms or the Fetch API's `Request`.
|
|
|
94
96
|
```ts
|
|
95
97
|
type DocumentHandlerOptions = {
|
|
96
98
|
getOwner?: (request: IncomingMessage) => string | undefined | Promise<string | undefined>;
|
|
99
|
+
maxPendingUploadBytes?: number;
|
|
100
|
+
uploadIdleTimeoutMs?: number;
|
|
97
101
|
};
|
|
98
102
|
```
|
|
99
103
|
|
|
@@ -102,6 +106,8 @@ The options of [`createDocumentHandlers()`](#createdocumenthandlersfiles-options
|
|
|
102
106
|
| Option | Type | Default | What it does |
|
|
103
107
|
|---|---|---|---|
|
|
104
108
|
| `getOwner` | `(request: IncomingMessage) => string \| undefined \| Promise<string \| undefined>` | none: every request is anonymous | The owner of this request, usually the signed-in user's ID. Called at most once per request. In `upload` it runs after the name is read and before the body: an upload without a name is answered `400` without calling it, and a refused upload is never buffered. An empty owner (`""`, or spaces only) is the server's mistake: the upload is answered `500` `{ "error": "Upload failed (empty owner)." }`, before its body is read. So is an owner from JavaScript that is neither a string nor a finite number (`req.user` in place of `req.user.id`, say): `{ "error": "Upload failed (owner is not a string)." }`. |
|
|
109
|
+
| `maxPendingUploadBytes` | `number` | twice `files.maxUploadBytes` (200 MB by default) | The most bytes of uploads these handlers hold at once. An upload is held whole in memory from the moment its body is read until its ingest ends (on the event-stream path too, also after its client went away). Its room is taken before its body is read: its `Content-Length`, or, when it declares none, `maxUploadBytes` (at most this limit) until the body is read, then its size. One that would bring the uploads held past the limit, while another is held, is answered `503` with `Retry-After: 5` before its body is read (the body is drained as for a `413`); one upload alone is always taken. A client that sends its headers and then nothing holds its room until `uploadIdleTimeoutMs` ends it. `Infinity` for no limit, as before 0.8.2. A value that is not a number above 0 throws a `RangeError` when the handlers are made. New in 0.8.2. |
|
|
110
|
+
| `uploadIdleTimeoutMs` | `number` | 30,000 | How long the body of an upload may stop arriving. Past it, the upload is answered `408` `{ "error": "The upload stopped arriving: nothing came for 30 s. Send it again." }` with `Connection: close`, the connection is closed, and the upload's room is given back. It bounds the wait for each piece of the body, not the whole upload: Node's `server.requestTimeout` (300 s by default) bounds that. 0 or `Infinity` for no limit. A value below 0 throws a `RangeError`. New in 0.8.2. |
|
|
105
111
|
|
|
106
112
|
What `getOwner` returns decides what each handler does:
|
|
107
113
|
|
|
@@ -162,7 +168,7 @@ The request:
|
|
|
162
168
|
`files.ingest` then keeps the last path segment of the name, without control characters and
|
|
163
169
|
characters that show nothing, up to 255 characters and never cut in the middle of a character, and takes the format
|
|
164
170
|
from the name's extension first, then from the MIME type
|
|
165
|
-
([`detectFormat`](./library.md#detectformatname-mimetype)).
|
|
171
|
+
([`detectFormat`](./library.md#detectformatname-mimetype-bytes)).
|
|
166
172
|
|
|
167
173
|
What it does, in order:
|
|
168
174
|
|
|
@@ -170,12 +176,17 @@ What it does, in order:
|
|
|
170
176
|
2. Calls `getOwner`, and checks what it returned: `""`, spaces only or `null`, or from JavaScript
|
|
171
177
|
a value that is neither a string nor a finite number, is answered `500` (see
|
|
172
178
|
[`DocumentHandlerOptions`](#documenthandleroptions)).
|
|
173
|
-
3.
|
|
179
|
+
3. Makes room for the upload ([`maxPendingUploadBytes`](#documenthandleroptions)): a
|
|
180
|
+
`Content-Length`, or a body in `request.body`, over `maxUploadBytes` is answered `413` first; an
|
|
181
|
+
upload that would bring the uploads held past the limit, while others are held, is answered
|
|
182
|
+
`503`, before its body is read. New in 0.8.2.
|
|
183
|
+
4. Reads the body, up to `files.maxUploadBytes`:
|
|
174
184
|
- a `Uint8Array` or `Buffer` that a framework left in `request.body` (`express.raw()`) is used
|
|
175
185
|
as the file, with the same limit;
|
|
176
186
|
- an object with fields in `request.body` (`express.json()` on a JSON request) is answered
|
|
177
187
|
`400`;
|
|
178
|
-
- otherwise it reads the request stream
|
|
188
|
+
- otherwise it reads the request stream, waiting at most `uploadIdleTimeoutMs` (30 s) for each
|
|
189
|
+
piece; past that it answers `408` and closes the connection (new in 0.8.2). Past the limit it stops keeping the bytes, and
|
|
179
190
|
answers `413` at once. The rest of the body is then read and dropped, up to 8 MB, and the
|
|
180
191
|
answer ends when the body does: a client that is still sending reads the `413`, and can send
|
|
181
192
|
its next request on the same keep-alive connection. A body that goes on more than 8 MB past
|
|
@@ -188,11 +199,12 @@ What it does, in order:
|
|
|
188
199
|
client stuck sending into it. The answer to such a body has no `Content-Length`. A stream
|
|
189
200
|
that another middleware has already read gives no bytes, and the upload is answered `422` as
|
|
190
201
|
an empty file.
|
|
191
|
-
|
|
192
|
-
only when there are any. The
|
|
193
|
-
|
|
194
|
-
answer
|
|
195
|
-
|
|
202
|
+
5. Ingests it: `files.ingest({ name, bytes, mimeType, owner, signal })`, `mimeType` and `owner`
|
|
203
|
+
only when there are any. The ingest may first wait its turn (`maxConcurrentIngests` of
|
|
204
|
+
`createLargeFiles`, 2 by default). The `signal` aborts when the client closes the connection
|
|
205
|
+
before the answer is sent: the ingest stops between two pages or pieces (or leaves the queue),
|
|
206
|
+
and nothing is stored. The answer then goes to no one.
|
|
207
|
+
6. Answers `201` with the document's summary. With `Accept: text/event-stream`, steps 5 and 6 are
|
|
196
208
|
a stream of events instead ([below](#upload-with-progress-accept-textevent-stream)).
|
|
197
209
|
|
|
198
210
|
The responses:
|
|
@@ -204,13 +216,15 @@ The responses:
|
|
|
204
216
|
| `400` | `{ "error": "The upload body was already parsed by another middleware. Mount the upload route before body parsers, or send Content-Type: application/octet-stream." }` | `request.body` is an object with fields. |
|
|
205
217
|
| `413` | `{ "error": "The file is larger than the 100 MB upload limit." }`, with your `maxUploadBytes` in its place (`512 KB`, `1000 B`) | `Content-Length`, the bytes read, or the `Buffer` in `request.body` are over `maxUploadBytes`. |
|
|
206
218
|
| `422` | `{ "error": <the message of files.ingest> }` | The file cannot be read: `files.ingest` threw an [`IngestError`](./library.md#ingesterror), whose `status` is 422. The message says why and is meant for the user: "app.log is empty.", "app.log did not contain any text.", "This file looks binary, not text. Attach a text, log, PDF, Word, PowerPoint, Excel or HTML file.", "This file is gzip-compressed. Decompress it, then attach the text file inside.", "This file is a ZIP archive. Extract it, then attach the text file you need.", an Office file of before 2007 or with a password, a PDF with a password or with no text layer, and a PDF, DOCX, PPTX or XLSX while the optional dependency that reads it is missing ("Reading PDF files needs the optional dependency "unpdf".") or, for a PDF, cannot run on this Node ("The unpdf installed cannot read PDF files on Node 20 (…). Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 22 or later.", see [defaultExtractors](./library.md#defaultextractors)). A text file is never refused for its encoding. A file past the limits of `createLargeFiles`: more text than `maxTextBytes`, more pages than `maxPdfPages`, longer to read than `ingestTimeoutMs` ("report.pdf took too long to read (more than 2 min). Split it, or save it as plain text, and attach that."), or built to exhaust the server ([every message](../guides/pdfs.md#what-is-refused)). With [`createIsolatedExtractors`](#createisolatedextractorsoptions), also a file whose reader ran out of memory or time. An extractor of your own that throws an `Error` gives its message here too. |
|
|
219
|
+
| `408` | `{ "error": "The upload stopped arriving: nothing came for 30 s. Send it again." }`, with `Connection: close` | The body stopped arriving for `uploadIdleTimeoutMs`. The connection is closed. New in 0.8.2. |
|
|
220
|
+
| `503` | `{ "error": "The server is receiving other files right now. Try again in a moment." }`, with `Retry-After: 5` | Uploads are already held, and this one would bring them past `maxPendingUploadBytes`. Answered before the body is read, also to a request with `Accept: text/event-stream`. New in 0.8.2. |
|
|
207
221
|
| `503` | `{ "error": "The server is reading other files right now. Try again in a moment." }`, with `Retry-After: 5` | The isolated readers of [`createIsolatedExtractors`](#createisolatedextractorsoptions) are all busy and their queue is full: an `IngestError` of code `"busy"`. The header is its `retryAfterMs` in seconds, rounded up, at least 1. While they shut down (`close()`): "The server is shutting down. Try again in a moment." New in 0.8.0. |
|
|
208
222
|
| 400 to 599 | `{ "error": <the error's message> }` | `getOwner`, an extractor or the store threw an error with that `status` or `statusCode`. |
|
|
209
223
|
| `500` | `{ "error": "Upload failed (empty owner)." }` | `getOwner` returned `""`, spaces only or `null`. The body is not read. New in 0.6.0. |
|
|
210
224
|
| `500` | `{ "error": "Upload failed (owner is not a string)." }` | `getOwner` returned, from JavaScript, something that is neither a string nor a finite number: an object such as `req.user`, `true`, `NaN`, an array. The body is not read. New in 0.6.0. |
|
|
211
225
|
| `500` | `{ "error": "Upload failed (ENOSPC)." }` | The store failed with a Node system error, one with a `code` and a `syscall`. Only the code is passed on. |
|
|
212
226
|
| `500` | `{ "error": "Upload failed." }` | `getOwner` threw an error without a status, or the request body could not be read: the client went away, or a proxy cut the upload. Node's error for a client that went away has a `code` (`ECONNRESET`) but no `syscall`, so no code is added. An error of either kind that has a `code` and a `syscall` is answered as in the row above, with its code. |
|
|
213
|
-
| `500` | `{ "error": "Upload failed." }` | The store failed while it wrote the document, with an error that has no `status` or `statusCode` from 400 to 599 and is not a Node system error (a database driver's error, say). Or `files.ingest` threw a value that is not an `Error` (an extractor of your own that throws a string, say). Such a value with a `code` and a `syscall` gets its code, as in the `ENOSPC` row. The error's own message is not sent. See below. |
|
|
227
|
+
| `500` | `{ "error": "Upload failed." }` | The store failed while it wrote the document, with an error that has no `status` or `statusCode` from 400 to 599 and is not a Node system error (a database driver's error, say), or did not finish writing it within `ingestTimeoutMs` (new in 0.8.2). Or `files.ingest` threw a value that is not an `Error` (an extractor of your own that throws a string, say). Such a value with a `code` and a `syscall` gets its code, as in the `ENOSPC` row. The error's own message is not sent. See below. |
|
|
214
228
|
|
|
215
229
|
A store that fails while it writes is answered `500` "Upload failed." when its error has neither a
|
|
216
230
|
`status` (or `statusCode`) from 400 to 599 nor a Node system error's `code` and `syscall`. Its
|
|
@@ -250,7 +264,8 @@ The handler reads the `Accept` header this way:
|
|
|
250
264
|
What stays JSON: every check that runs before the ingest answers as it always did, with its status
|
|
251
265
|
and `{ "error": "…" }`, because the stream has not started yet. That is a missing name (`400`), a
|
|
252
266
|
refusal or a bad owner from `getOwner` (its status, or `500`), a body another middleware parsed
|
|
253
|
-
(`400`),
|
|
267
|
+
(`400`), a file over `maxUploadBytes` (`413`), an upload that finds no room (`503`, new in 0.8.2),
|
|
268
|
+
and a body that stops arriving (`408`, new in 0.8.2). Only a file that passes them is answered `200`
|
|
254
269
|
with the event-stream headers of [`writeSseEvents()`](#writesseeventsresponse-events-options) and
|
|
255
270
|
a `: keep-alive` comment every 15 seconds.
|
|
256
271
|
|
|
@@ -285,7 +300,7 @@ data: {"type":"ingest.finish","document":{"id":"doc_f6502d2f94694d709c7db2ec634c
|
|
|
285
300
|
that a page can say why in its own words.
|
|
286
301
|
- **The status is `200` whatever happens next.** Once the stream has started, a failure can only be
|
|
287
302
|
an `ingest.error` event.
|
|
288
|
-
- **A client that goes away stops the ingest**, as in step
|
|
303
|
+
- **A client that goes away stops the ingest**, as in step 5: nothing is stored, and nothing more
|
|
289
304
|
is written.
|
|
290
305
|
- **The handler still never rejects.**
|
|
291
306
|
|
|
@@ -468,7 +483,7 @@ type IsolatedExtractorOptions = {
|
|
|
468
483
|
|---|---|---|---|
|
|
469
484
|
| `maxHeapMb` | `number` | 512 | The heap of each child process, in MB, given as `--max-old-space-size`. A file that needs more is refused (`"out_of_memory"`), and the server goes on. From 1 to 1,048,576, and finite; a fraction is cut to a whole number. Node reads `--max-old-space-size=0` as its default heap, so a value below 1 is refused rather than cut to 0. |
|
|
470
485
|
| `timeoutMs` | `number` | 120,000 | The most time one file may take, in milliseconds. Past it, its child is killed and the file refused (`"timeout"`). 0 sets none, and so does a value past what a timer can wait (2,147,483,647 ms, 24.8 days), `Infinity` included, as for `ingestTimeoutMs`. With both at their defaults, the `ingestTimeoutMs` of `createLargeFiles` usually ends the ingest first, and its signal kills the child too. |
|
|
471
|
-
| `concurrency` | `number` | 2 | How many files are read at once, each in a child process of its own. At least 1. |
|
|
486
|
+
| `concurrency` | `number` | 2 | How many files are read at once, each in a child process of its own. At least 1. A library sends the readers at most its `maxConcurrentIngests` files at once (2 by default, since 0.8.2): for more children at work, raise that too. |
|
|
472
487
|
| `maxQueue` | `number` | 8 | How many files may wait for a child. Past it, a file is refused at once as `"busy"`. 0: none waits. |
|
|
473
488
|
| `formats` | `DocumentFormat[]` | `["pdf", "docx", "pptx", "xlsx"]` | The formats read in child processes: by default those whose parsers a hostile file can exhaust. `extractors` has an entry for each. |
|
|
474
489
|
| `pdf` | [`PdfExtractorOptions`](./library.md#pdfextractoroptions) | `{}` | Options of the built-in PDF extractor in the children, as for [`createPdfExtractor`](./library.md#createpdfextractoroptions). |
|