llm-large-files 0.7.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 +319 -1
- package/README.md +10 -8
- package/dist/analyze.d.ts +3 -1
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +109 -14
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +4 -1
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +3 -3
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +72 -17
- 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/errors.d.ts +55 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +5 -1
- package/dist/events.js.map +1 -1
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +6 -0
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +7 -20
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +49 -751
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +9 -5
- package/dist/gemini/adapter.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/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +20 -3
- package/dist/gemini/generate.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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +48 -12
- 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/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +69 -15
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -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/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.map +1 -1
- package/dist/openai/adapter.js +15 -1
- package/dist/openai/adapter.js.map +1 -1
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +2 -6
- package/dist/pdf-pages.js.map +1 -1
- 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.map +1 -1
- package/dist/plan.js +1 -1
- 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/search.d.ts +99 -22
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +744 -140
- package/dist/search.js.map +1 -1
- package/dist/text-index.d.ts +3 -1
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +3 -1
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +27 -3
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +225 -23
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +200 -12
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +3 -3
- 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/docs/README.md +8 -8
- package/docs/getting-started.md +1 -1
- package/docs/guides/costs-and-limits.md +7 -5
- package/docs/guides/deployment.md +95 -29
- package/docs/guides/errors-and-reliability.md +23 -10
- package/docs/guides/pdfs.md +127 -74
- package/docs/guides/storage.md +1 -1
- package/docs/guides/testing.md +5 -1
- package/docs/guides/web-app.md +10 -9
- package/docs/how-it-works.md +73 -50
- package/docs/reference/ask.md +26 -8
- package/docs/reference/errors-and-retries.md +5 -3
- package/docs/reference/events.md +14 -6
- package/docs/reference/gemini.md +6 -2
- package/docs/reference/library.md +205 -74
- package/docs/reference/node.md +200 -22
- package/docs/reference/openai.md +1 -1
- package/docs/reference/tools.md +170 -22
- package/docs/security.md +114 -69
- package/docs/troubleshooting.md +40 -20
- package/package.json +6 -2
- package/src/analyze.ts +117 -13
- package/src/anthropic/adapter.ts +4 -1
- package/src/ask.ts +73 -17
- package/src/decode.ts +89 -0
- package/src/errors.ts +108 -0
- package/src/events.ts +10 -1
- package/src/evidence.ts +6 -0
- package/src/extract.ts +52 -709
- package/src/gemini/adapter.ts +9 -5
- package/src/gemini/endpoints.ts +12 -2
- package/src/gemini/generate.ts +19 -3
- package/src/groups.ts +162 -0
- package/src/html.ts +1071 -0
- package/src/index.ts +2 -1
- package/src/library.ts +43 -12
- package/src/limiter.ts +6 -1
- package/src/model.ts +8 -1
- package/src/node/handlers.ts +66 -16
- package/src/node/index.ts +2 -0
- package/src/node/ingest-child.ts +61 -0
- package/src/node/isolated.ts +464 -0
- package/src/office.ts +1047 -0
- package/src/openai/adapter.ts +14 -1
- package/src/pdf-pages.ts +2 -5
- package/src/peers.ts +29 -0
- package/src/plan.ts +2 -0
- package/src/ranged.ts +4 -2
- package/src/search.ts +738 -146
- package/src/text-index.ts +4 -2
- package/src/text.ts +214 -23
- package/src/tools.ts +192 -12
- package/src/types.ts +3 -3
- package/src/word-styles.ts +420 -0
- package/src/xlsx.ts +478 -0
- package/src/xml-stream.ts +224 -0
|
@@ -8,7 +8,7 @@ an application or write a store, an extractor or a loop of their own.
|
|
|
8
8
|
```ts
|
|
9
9
|
import {
|
|
10
10
|
createLargeFiles, DEFAULT_CACHE_BYTES, DEFAULT_WHOLE_DOCUMENT_BYTES, DEFAULT_MAX_PDF_PAGES, DEFAULT_MAX_TEXT_BYTES,
|
|
11
|
-
DEFAULT_INGEST_TIMEOUT_MS, NEVER_EXPIRES, isDocumentId, toDocumentSummary,
|
|
11
|
+
DEFAULT_INGEST_TIMEOUT_MS, NEVER_EXPIRES, isDocumentId, toDocumentSummary, IngestError, ingestErrorCodeOf,
|
|
12
12
|
DEFAULT_BUDGET, resolveBudget,
|
|
13
13
|
MemoryDocumentStore, FileDocumentStore, DOCUMENT_ID_PATTERN, DocumentStoreError,
|
|
14
14
|
createPdfExtractor, defaultExtractors, detectFormat,
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
LargeFilesOptions, LargeFiles, AccessOptions, IngestInput, PrepareOptions, ToolOptions, PreparedContext, DocumentPlan,
|
|
19
19
|
Budget, ModelLimits, DocumentStore, StoredDocument, PdfExtractorOptions, Extractor, ExtractInput, ExtractProgress,
|
|
20
20
|
ExtractedText, DocumentMeta, DocumentSummary, DocumentFormat, OutlineEntry, LogIssue, LogProfile, ProgressEvent,
|
|
21
|
-
ProgressListener, ToolCallHooks, ToolRequestHandle, ToolRequestStart, ToolRequestEnd, IngestEvent,
|
|
21
|
+
ProgressListener, ToolCallHooks, ToolRequestHandle, ToolRequestStart, ToolRequestEnd, IngestEvent, IngestErrorCode,
|
|
22
22
|
} from "llm-large-files";
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -29,6 +29,7 @@ Contents:
|
|
|
29
29
|
|
|
30
30
|
- [The library](#the-library): [`createLargeFiles(options)`](#createlargefilesoptions),
|
|
31
31
|
[`LargeFilesOptions`](#largefilesoptions), [`LargeFiles`](#largefiles), [`IngestInput`](#ingestinput),
|
|
32
|
+
[`IngestError`](#ingesterror), [`ingestErrorCodeOf(message)`](#ingesterrorcodeofmessage),
|
|
32
33
|
[`AccessOptions`](#accessoptions), [`PrepareOptions`](#prepareoptions), [`ToolOptions`](#tooloptions),
|
|
33
34
|
[`PreparedContext`](#preparedcontext), [`DocumentPlan`](#documentplan),
|
|
34
35
|
[`DEFAULT_CACHE_BYTES`](#default_cache_bytes), [`DEFAULT_WHOLE_DOCUMENT_BYTES`](#default_whole_document_bytes),
|
|
@@ -116,7 +117,7 @@ type LargeFilesOptions = {
|
|
|
116
117
|
| `budget` | `Partial<Budget>` | [`DEFAULT_BUDGET`](#default_budget) | The limits of your model connection. Fields you leave out follow `contextTokens` (see [`Budget`](#budget)): for a model with a smaller window, setting `contextTokens` is enough. |
|
|
117
118
|
| `ttlMs` | `number` | 72 hours (259,200,000) | How long a document is kept after it is ingested. `expiresAt` is set at ingest, and the library never extends it. `Infinity`, or any time that would end at or after the end of year 9999, keeps documents until they are deleted: `expiresAt` is then [`NEVER_EXPIRES`](#never_expires). |
|
|
118
119
|
| `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. |
|
|
119
|
-
| `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 and
|
|
120
|
+
| `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. |
|
|
120
121
|
| `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. |
|
|
121
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). |
|
|
122
123
|
| `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. |
|
|
@@ -129,6 +130,16 @@ type LargeFilesOptions = {
|
|
|
129
130
|
| `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. |
|
|
130
131
|
| `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`. |
|
|
131
132
|
|
|
133
|
+
Since 0.7.1, `ttlMs`, `maxUploadBytes`, `scannedPdfPages`, `cacheBytes`, `cacheSize`,
|
|
134
|
+
`wholeDocumentBytes`, `scanChunkBytes` and `maxConcurrentScans` are checked when the library is
|
|
135
|
+
made: NaN, which `Number(process.env.X)` gives for a variable that is not set, throws a
|
|
136
|
+
`RangeError` ("maxConcurrentScans must be a number, and is NaN. Leave it out for the default."),
|
|
137
|
+
a value that is not a number throws a `TypeError`, and so does `Infinity` for `scanChunkBytes`. NaN
|
|
138
|
+
used to pass through: `maxConcurrentScans` left every scan of a document read by range waiting
|
|
139
|
+
forever, `ttlMs` failed every upload, `maxUploadBytes` took off the upload limit. A number below
|
|
140
|
+
the least an option takes is raised to it, as before. `maxTextBytes`, `maxPdfPages` and
|
|
141
|
+
`ingestTimeoutMs` take NaN as left out, as they have since 0.6.0.
|
|
142
|
+
|
|
132
143
|
Guides: [storage](../guides/storage.md) for the store, owners and retention,
|
|
133
144
|
[costs and limits](../guides/costs-and-limits.md) for the budget, [PDFs](../guides/pdfs.md) for
|
|
134
145
|
`keepOriginals`, `scannedPdfPages`, `extractors` and the files the limits refuse,
|
|
@@ -179,24 +190,26 @@ new document's [`DocumentMeta`](#documentmeta).
|
|
|
179
190
|
([Text encodings](../guides/pdfs.md#text-encodings)).
|
|
180
191
|
3. The text is normalized: a byte-order mark is removed, line endings become `\n`, and terminal
|
|
181
192
|
escape sequences and control characters other than tab and newline are removed, C1 controls
|
|
182
|
-
(U+0080-U+009F) included. So are most characters that show nothing: Unicode tag characters
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
(U+0080-U+009F) included. So are most characters that show nothing: Unicode tag characters (the
|
|
194
|
+
flags of England, Scotland and Wales are kept), the text-direction embeddings, overrides and
|
|
195
|
+
isolates (U+202A-U+202E, U+2066-U+2069), the zero-width space, the word joiner and the invisible
|
|
196
|
+
operators (U+200B, U+2060-U+2064), the deprecated format characters (U+206A-U+206F), a byte-order
|
|
197
|
+
mark inside the text, and a soft hyphen that is not at the end of a line. The characters that
|
|
198
|
+
scripts and emoji need are kept: LRM, RLM and ALM, zero-width joiners and non-joiners, variation
|
|
199
|
+
selectors. In a text with no other line break, U+0085 (next line) ends a line, except right after
|
|
200
|
+
U+0080-U+00FF; elsewhere it is removed. No other line moves. The text is then composed (NFC), as
|
|
201
|
+
a model writes its queries: "e" followed by a combining accent becomes "é" (new in 0.8.0; line
|
|
202
|
+
counts do not change, and `characters` can be a little smaller). Lines longer than 2,000
|
|
203
|
+
characters are split, so every line can be read by number (`wrappedLines` counts them).
|
|
192
204
|
4. A `text` document becomes a `log`, and gets a `logProfile`, when it has at least 5 non-blank
|
|
193
205
|
lines and at least 40% of its first 200 non-blank lines start with a timestamp or a log level
|
|
194
|
-
(`ERROR`, `WARN`, `INFO`...)
|
|
206
|
+
(`ERROR`, `WARN`, `INFO`...), or have the shape of an access log of nginx or Apache, a JSON log
|
|
207
|
+
line, klog or logfmt (since 0.8.0).
|
|
195
208
|
5. The store is written: the original file (when it is kept), then the line index (when the store
|
|
196
209
|
has `putIndex`), then `put` last.
|
|
197
210
|
|
|
198
211
|
Steps 2 to 4 work in slices of about 12 ms, with a pause for other requests between two slices:
|
|
199
|
-
between the pages of a PDF, as a DOCX or
|
|
212
|
+
between the pages of a PDF, as a DOCX, PPTX or XLSX is unpacked, and while the text is normalized,
|
|
200
213
|
measured, outlined, profiled and indexed. Ingests that run at once take turns, one slice each.
|
|
201
214
|
They run under one signal, aborted by `IngestInput.signal` or after `ingestTimeoutMs` (2 minutes
|
|
202
215
|
by default). When it aborts, `ingest` stops waiting for the extractor, throws, and writes nothing
|
|
@@ -205,48 +218,52 @@ pause, and the signal is looked at only between pages.
|
|
|
205
218
|
|
|
206
219
|
**Events.** New in 0.7.0. With `IngestInput.onEvent`, the ingest tells what it does as typed
|
|
207
220
|
[`IngestEvent`](./events.md#ingestevent)s, in order: `ingest.start` first (the cleaned name, the
|
|
208
|
-
format the name and type say, the size), even for a file that is then refused; `ingest.progress` for
|
|
209
|
-
that reports; and last `ingest.finish`, with the document's
|
|
221
|
+
format the name and type say, the size), even for a file that is then refused; `ingest.progress` for
|
|
222
|
+
each stage that reports; and last `ingest.finish`, with the document's
|
|
210
223
|
[`DocumentSummary`](#documentsummary), or `ingest.error`. The stages, in the order they run:
|
|
211
224
|
`decode` (a text file that is not UTF-8, once, when it is decoded), `check` (the pages of a PDF
|
|
212
|
-
checked before they are read, with `@cantoo/pdf-lib`), `extract` (the pages of a PDF, the parts of
|
|
213
|
-
a
|
|
214
|
-
`prepare` and `index` (characters of the text), and `store` (each
|
|
215
|
-
([stages and units](./events.md#stages-and-units)). A stage sends at
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
whatever it threw, and the store's own error is the
|
|
220
|
-
ends the ingest with that error, and nothing is stored;
|
|
221
|
-
document that was just stored. `createDocumentHandlers` sends
|
|
222
|
-
asks for them with `Accept: text/event-stream`
|
|
223
|
-
|
|
225
|
+
checked before they are read, with `@cantoo/pdf-lib`), `extract` (the pages of a PDF, the parts of a
|
|
226
|
+
DOCX, the slides of a PPTX, the sheets of an XLSX), `pictures` (the pages of a PDF looked at for
|
|
227
|
+
pictures, with `@cantoo/pdf-lib`), `prepare` and `index` (characters of the text), and `store` (each
|
|
228
|
+
write) ([stages and units](./events.md#stages-and-units)). A stage sends at most one
|
|
229
|
+
`ingest.progress` about every 12 ms, and its last one when it ends. An extractor of your own reports
|
|
230
|
+
only what it passes to `onProgress`. The error of `ingest.error` is told in words for users, with
|
|
231
|
+
the `code` of an [`IngestError`](#ingesterror) (new in 0.8.0): a store that failed to write is "The
|
|
232
|
+
document could not be stored. Try again later.", whatever it threw, and the store's own error is the
|
|
233
|
+
one `ingest` throws. A listener that throws ends the ingest with that error, and nothing is stored;
|
|
234
|
+
a throw on `ingest.finish` removes the document that was just stored. `createDocumentHandlers` sends
|
|
235
|
+
these events to a client that asks for them with `Accept: text/event-stream` ([upload with
|
|
236
|
+
progress](./node.md#upload-with-progress-accept-textevent-stream)).
|
|
224
237
|
|
|
225
238
|
| It throws | When |
|
|
226
239
|
|---|---|
|
|
227
240
|
| `TypeError("owner must be a string that is not empty or only spaces, such as the signed-in user's ID. To let anyone with the document's ID use it, leave owner out.")` | `owner` is `""`, spaces only or `null`, or, from JavaScript, neither a string nor a finite number (an object, `true`, `NaN`). Before anything is read. New in 0.6.0: 0.5.0 accepted them. |
|
|
228
|
-
| `
|
|
229
|
-
| `
|
|
230
|
-
|
|
|
231
|
-
| `
|
|
232
|
-
| `
|
|
241
|
+
| [`IngestError`](#ingesterror) `"empty"`: `<name> is empty.` | The file has no bytes. |
|
|
242
|
+
| `IngestError` `"too_large"`: `<name> is larger than the 100 MB upload limit.` | The file is larger than `maxUploadBytes`. The message gives your limit. |
|
|
243
|
+
| An `IngestError` with the extractor's message | The extractor refused the file: a binary or compressed file, an Office file of before 2007 or with a password, a PDF with a password or without text, a missing optional dependency or an `unpdf` that cannot run on this Node, a possible zip bomb, a file past `maxTextBytes` or `maxPdfPages`, a file built to exhaust the server; or a parser failed on a damaged file. The `code` comes from the message ([`ingestErrorCodeOf`](#ingesterrorcodeofmessage)), `"unreadable"` for one the library does not know, and the extractor's error is `cause`. A text file is never refused for its encoding. The built-in messages, listed under [`defaultExtractors`](#defaultextractors), are written for a user. |
|
|
244
|
+
| `IngestError` `"too_much_text"`: `<name> holds more than 100 MB of text, more than is kept from one file. Split it, and attach the part you need.` | The text an extractor returned is larger than `maxTextBytes`. The message gives your limit. |
|
|
245
|
+
| `IngestError` `"timeout"`: `<name> took too long to read (more than 2 min). Split it, or save it as plain text, and attach that.` | The ingest took longer than `ingestTimeoutMs`. The message gives your limit: "500 ms" below a second, "45 s" below 2 minutes, "2 min" from there. |
|
|
233
246
|
| `signal.reason` | `IngestInput.signal` was aborted, before or during the ingest. |
|
|
234
|
-
| `
|
|
247
|
+
| `IngestError` `"no_text"`: `<name> did not contain any text.` | The extracted text is blank. |
|
|
248
|
+
| What an extractor of your own threw | An error with a `status` or `statusCode`, a Node system error (one with a `code` and a `syscall`), and a value that is not an `Error`, as they are. Any other `Error` becomes an `IngestError`, as above. |
|
|
235
249
|
| The store's own error | A write failed. `ingest` first calls `store.delete(id)` to remove what was written (an error of that call is ignored), then throws the store's error unchanged. It is not a `DocumentStoreError`. |
|
|
236
250
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
a
|
|
248
|
-
|
|
249
|
-
|
|
251
|
+
Until 0.8.0 the refusals were plain `Error`s, with the same messages. The `TypeError` of an owner is
|
|
252
|
+
a mistake of the server's code, not of the file: the upload handler of
|
|
253
|
+
[`llm-large-files/node`](./node.md) checks the owner itself, and answers `500` before it reads the
|
|
254
|
+
body. The store's error, a listener of the events that threw, and the reason of an aborted signal
|
|
255
|
+
are thrown as they are, never as an `IngestError`. The upload handler of
|
|
256
|
+
[`llm-large-files/node`](./node.md) takes an error that carries an HTTP `status` or `statusCode`
|
|
257
|
+
(400 to 599), or a Node system error (`code` and `syscall`), for the store's: it answers with that
|
|
258
|
+
status, or with 500 and the code. An `IngestError` carries a `status` too, and is answered with it:
|
|
259
|
+
422, 413 for `"too_large"`, 503 with `Retry-After` for `"busy"`. `ingest` also keeps a mark of each
|
|
260
|
+
error a store throws while it writes. The handler answers a marked error without a status or a code,
|
|
261
|
+
and a thrown value that is not an `Error`, with 500 `{ "error": "Upload failed." }`, without its
|
|
262
|
+
message. It answers any other `Error` with 422 and its message, as a file that cannot be read. The
|
|
263
|
+
package does not export the mark: behind an `ingest` of your own that throws a new error, or in a
|
|
264
|
+
route of your own, a store's error is answered as a file that cannot be read (see [the upload
|
|
265
|
+
handler](./node.md#uploadrequest-response)). Give your store's write errors a `status` and a message
|
|
266
|
+
of your own. See [errors and reliability](../guides/errors-and-reliability.md).
|
|
250
267
|
|
|
251
268
|
Guides: [web app](../guides/web-app.md) for uploads, [PDFs](../guides/pdfs.md) for what PDF
|
|
252
269
|
extraction writes.
|
|
@@ -411,12 +428,105 @@ The argument of [`files.ingest`](#filesingestinput).
|
|
|
411
428
|
| `mimeType` | `string` | `"application/octet-stream"` | The MIME type, trimmed. Blank counts as absent. Used when the extension names no format. |
|
|
412
429
|
| `bytes` | `Uint8Array` | required | The file. A Node `Buffer` is one. Empty, or larger than `maxUploadBytes`, is refused. |
|
|
413
430
|
| `owner` | `string` | none | The user or tenant the document belongs to. Every later call must pass the same owner. Without one, anyone who has the ID can use the document. It must be a string that is not empty or only spaces: `""`, spaces only and `null` throw a `TypeError` (see [`files.ingest`](#filesingestinput)), since each would be one owner shared by every caller without a user. A number from JavaScript is taken, as before. Reads with the owner `""` work as before. |
|
|
414
|
-
| `signal` | `AbortSignal` | none | Stops the ingest when it aborts, for example when the uploader goes away: `ingest` throws `signal.reason` and stores nothing. The PDF, DOCX and
|
|
431
|
+
| `signal` | `AbortSignal` | none | Stops the ingest when it aborts, for example when the uploader goes away: `ingest` throws `signal.reason` and stores nothing. The PDF, DOCX, PPTX, XLSX and HTML extractors stop between pages and pieces; `ingest` stops waiting for an extractor of your own at once. A signal that aborts once the store is being written changes nothing. `createDocumentHandlers` passes one that aborts when the client closes the connection before the answer. |
|
|
415
432
|
| `onEvent` | `(event: IngestEvent) => void` | none | What the ingest does as it goes: `ingest.start`, `ingest.progress` for each stage, then `ingest.finish` or `ingest.error` (see [`files.ingest`](#filesingestinput) and [events](./events.md)). Progress is worked out only when it is given. New in 0.7.0. |
|
|
416
433
|
| `runId` | `string` | `"ing_"` and 16 hex digits | The `runId` of those events. New in 0.7.0. |
|
|
417
434
|
|
|
418
435
|
Guide: [web app](../guides/web-app.md).
|
|
419
436
|
|
|
437
|
+
### `IngestError`
|
|
438
|
+
|
|
439
|
+
```ts
|
|
440
|
+
declare class IngestError extends Error {
|
|
441
|
+
readonly code: IngestErrorCode;
|
|
442
|
+
readonly status: number;
|
|
443
|
+
readonly retryAfterMs?: number;
|
|
444
|
+
constructor(code: IngestErrorCode, message: string, options?: { cause?: unknown; retryAfterMs?: number });
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
type IngestErrorCode =
|
|
448
|
+
| "empty" | "too_large" | "too_much_text" | "too_many_pages" | "not_text" | "compressed" | "legacy_office"
|
|
449
|
+
| "encrypted" | "no_text" | "hostile" | "timeout" | "out_of_memory" | "busy" | "missing_dependency" | "unreadable";
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
New in 0.8.0. [`files.ingest`](#filesingestinput) could not read a file. The message says why, in
|
|
453
|
+
words for the person who uploaded it, as it did before; `code` says it for your application, so
|
|
454
|
+
that it can tell the user in its own words or language. Until 0.8.0 the same refusals were plain
|
|
455
|
+
`Error`s, with the same messages.
|
|
456
|
+
|
|
457
|
+
| Field | Type | What it holds |
|
|
458
|
+
|---|---|---|
|
|
459
|
+
| `name` | `string` | `"IngestError"`. |
|
|
460
|
+
| `message` | `string` | The reason, written for a user: "app.log is empty.", "This PDF has no text layer (it may be scanned). …". |
|
|
461
|
+
| `code` | `IngestErrorCode` | Why, as one of the codes below. |
|
|
462
|
+
| `status` | `number` | The HTTP status the upload handler of [`llm-large-files/node`](./node.md#uploadrequest-response) answers with: 413 for `"too_large"`, 503 for `"busy"`, 422 for every other code. |
|
|
463
|
+
| `retryAfterMs` | `number \| undefined` | For `"busy"`: how long to wait before trying again, in milliseconds (5,000 from `createIsolatedExtractors`). The upload handler sends it as `Retry-After`, in seconds. |
|
|
464
|
+
| `cause` | `unknown` | The error of the extractor, the parser or the isolated reader, when there is one. Its message is in `message`. |
|
|
465
|
+
|
|
466
|
+
| `code` | What the file is |
|
|
467
|
+
|---|---|
|
|
468
|
+
| `"empty"` | It has no bytes. |
|
|
469
|
+
| `"too_large"` | It is larger than `maxUploadBytes`. |
|
|
470
|
+
| `"too_much_text"` | It has more text than `maxTextBytes`, or more than one file is read for (an Office file of more than 32 million characters, or of more than 128 MB of XML). |
|
|
471
|
+
| `"too_many_pages"` | A PDF with more pages than `maxPdfPages`. |
|
|
472
|
+
| `"not_text"` | A binary file of a kind the library does not read. |
|
|
473
|
+
| `"compressed"` | A gzip or ZIP archive, to extract first. |
|
|
474
|
+
| `"legacy_office"` | A Word, Excel or PowerPoint file of before 2007 (`.doc`, `.xls`, `.ppt`), an Outlook message (`.msg`), or an Office file protected by a password: all are stored the same way, and none can be read. |
|
|
475
|
+
| `"encrypted"` | A PDF protected by a password. |
|
|
476
|
+
| `"no_text"` | Nothing to read: a PDF without a text layer (a scan), a deck without slides, a workbook without sheets, a file of white space. |
|
|
477
|
+
| `"hostile"` | A file built the way files that exhaust a server are: a zip bomb, a PDF that draws far more text than its size or lists a page twice, pages that would hold the server, a structure no program writes. Most of these messages say "it may be built to exhaust the server" or "it may be a zip bomb". |
|
|
478
|
+
| `"timeout"` | Reading it took longer than `ingestTimeoutMs`, or the kill timer of an isolated reader ([`createIsolatedExtractors`](./node.md#createisolatedextractorsoptions)). |
|
|
479
|
+
| `"out_of_memory"` | An isolated reader ran out of the memory it is given (`maxHeapMb`). |
|
|
480
|
+
| `"busy"` | Every isolated reader is busy and its queue is full, it is shutting down, or a reader process could not be started for want of process slots or file handles: try again in a moment (`retryAfterMs`). |
|
|
481
|
+
| `"missing_dependency"` | The optional dependency for the format is not installed, is installed and could not be loaded, or (unpdf) cannot run on this version of Node. |
|
|
482
|
+
| `"unreadable"` | Any other error of reading the file: it is damaged, or not of the type its name says. |
|
|
483
|
+
|
|
484
|
+
`ingest.error` events carry the code as [`EventError.code`](./events.md#errors-eventerror).
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
import { IngestError, toDocumentSummary, type IngestErrorCode, type LargeFiles } from "llm-large-files";
|
|
488
|
+
|
|
489
|
+
// Your words for some codes; the library's message for the others.
|
|
490
|
+
const hebrew: Partial<Record<IngestErrorCode, string>> = {
|
|
491
|
+
too_large: "הקובץ גדול מדי.",
|
|
492
|
+
no_text: "אין בקובץ טקסט לקרוא.",
|
|
493
|
+
busy: "השרת עסוק. נסו שוב בעוד רגע.",
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// `files` is your library.
|
|
497
|
+
async function upload(files: LargeFiles, name: string, bytes: Uint8Array, owner: string) {
|
|
498
|
+
try {
|
|
499
|
+
return { status: 201, body: toDocumentSummary(await files.ingest({ name, bytes, owner })) };
|
|
500
|
+
} catch (error) {
|
|
501
|
+
if (!(error instanceof IngestError)) throw error; // the store, an abort, your own code
|
|
502
|
+
return { status: error.status, body: { error: hebrew[error.code] ?? error.message, code: error.code } };
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
Guide: [errors and reliability](../guides/errors-and-reliability.md).
|
|
508
|
+
|
|
509
|
+
### ingestErrorCodeOf(message)
|
|
510
|
+
|
|
511
|
+
```ts
|
|
512
|
+
declare function ingestErrorCodeOf(message: string): IngestErrorCode;
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
New in 0.8.0. The code of a refusal of the library, read from its message: `"hostile"` for
|
|
516
|
+
"…It may be built to exhaust the server, so it is not read.", `"compressed"` for "This file is a ZIP
|
|
517
|
+
archive. …", `"busy"` for the busy and shutting-down refusals of the isolated readers, and so on.
|
|
518
|
+
`"unreadable"` for any other message. It gives the code only: an `IngestError` made from a message
|
|
519
|
+
has no `retryAfterMs`, so wait your own time before a retry of a `"busy"` one. `ingest` gives the
|
|
520
|
+
plain `Error` of an extractor its code this way. Use it where only the message is left, such as a reply from a
|
|
521
|
+
process of your own that ingests:
|
|
522
|
+
|
|
523
|
+
```ts
|
|
524
|
+
import { IngestError, ingestErrorCodeOf } from "llm-large-files";
|
|
525
|
+
|
|
526
|
+
// `message` came back from your ingest process.
|
|
527
|
+
const error = new IngestError(ingestErrorCodeOf(message), message);
|
|
528
|
+
```
|
|
529
|
+
|
|
420
530
|
### `AccessOptions`
|
|
421
531
|
|
|
422
532
|
```ts
|
|
@@ -477,7 +587,7 @@ The options of [`files.tools`](#filestoolsdocuments-options).
|
|
|
477
587
|
| `onProgress` | [`ProgressListener`](#progresslistener) | none | Progress of whole-document reads, for status messages. |
|
|
478
588
|
| `signal` | `AbortSignal` | none | Stops searches and whole-document reads. Once it has aborted, a call that fails throws instead of answering `{ error }`. |
|
|
479
589
|
| `regexBudgetMs` | `number` | [`REGEX_BUDGET_MS`](./tools.md#regex_budget_ms), 6,000 | The most time, in milliseconds, that the regex searches of this tool set may take together. Past it, a regex search answers with an error that tells the model to search another way. One search stops after 3,000 ms on its own. |
|
|
480
|
-
| `maxWholeDocumentReads` | `number` | [`MAX_WHOLE_DOCUMENT_READS`](./tools.md#max_whole_document_reads), 1 | How many times each document may be read whole by this tool set. A call past it answers with an error that tells the model to use what it has. 0 turns whole reads off. |
|
|
590
|
+
| `maxWholeDocumentReads` | `number` | [`MAX_WHOLE_DOCUMENT_READS`](./tools.md#max_whole_document_reads), 1 | How many times each document may be read whole by this tool set. A call past it answers with an error that tells the model to use what it has. 0 turns whole reads off. NaN throws a `RangeError`, and a value that is not a number a `TypeError` (since 0.7.1: NaN allowed any number of whole reads). |
|
|
481
591
|
| `retry` | [`RetryOptions`](./errors-and-retries.md#retryoptions) | 3 retries, a first wait of 250 to 500 ms (500 ms before the jitter) that doubles, 60 s at most | How a failed model request of a whole-document read is sent again. An error without an HTTP status is sent again once, at once. |
|
|
482
592
|
| `budget` | `Partial<Budget>` | the library's | The budget fields to change for these tools: their result cap and part size. Use the budget you planned the request with. |
|
|
483
593
|
| `viewPages` | `boolean \| DocumentMeta[]` | none | Offers `view_pages`, which hands the model real pages of a PDF as a file. `true` offers it for the PDFs among `documents`; a list offers it for exactly those, which may include PDFs whose text is already in the prompt: pass `prepared.viewable`. Only PDFs with `originalKept` count, and only with a store that has `getOriginal`. Turn it on only when your loop runs tools with `executeWithFiles` and sends the files to the model. |
|
|
@@ -943,7 +1053,9 @@ type Extractor = (bytes: Uint8Array, input: ExtractInput) => Promise<ExtractedTe
|
|
|
943
1053
|
```
|
|
944
1054
|
|
|
945
1055
|
Turns the bytes of an uploaded file into text, for one format. To refuse a file, throw an `Error`
|
|
946
|
-
whose message a user can read: `ingest`
|
|
1056
|
+
whose message a user can read: `ingest` throws it as an [`IngestError`](#ingesterror) with the same
|
|
1057
|
+
message, the code its message gives (`"unreadable"` for words the library does not know), and your
|
|
1058
|
+
error as `cause`. Throw an `IngestError` yourself to choose the code. The library then normalizes the
|
|
947
1059
|
text, splits long lines and refuses blank text, as described under
|
|
948
1060
|
[`files.ingest`](#filesingestinput). For a PDF, write a line `--- Page N ---` before the text of
|
|
949
1061
|
each page, counting from 1, as the built-in one does: the page numbers in tool results and
|
|
@@ -952,11 +1064,11 @@ each page, counting from 1, as the built-in one does: the page numbers in tool r
|
|
|
952
1064
|
```ts
|
|
953
1065
|
import { createLargeFiles, defaultExtractors, MemoryDocumentStore, type Extractor } from "llm-large-files";
|
|
954
1066
|
|
|
955
|
-
// An .
|
|
1067
|
+
// An .xml file is detected as "text". This extractor drops its tags before the text is stored.
|
|
956
1068
|
const text: Extractor = async (bytes, input) => {
|
|
957
1069
|
const extracted = await defaultExtractors.text(bytes, input);
|
|
958
|
-
if (!input.name.toLowerCase().endsWith(".
|
|
959
|
-
return { text: extracted.text.replace(/<
|
|
1070
|
+
if (!input.name.toLowerCase().endsWith(".xml")) return extracted;
|
|
1071
|
+
return { ...extracted, text: extracted.text.replace(/<[^>]+>/g, " ") };
|
|
960
1072
|
};
|
|
961
1073
|
|
|
962
1074
|
const files = createLargeFiles({ store: new MemoryDocumentStore(), extractors: { text } });
|
|
@@ -985,10 +1097,10 @@ type ExtractInput = {
|
|
|
985
1097
|
| `mimeType` | `string` | The MIME type, `"application/octet-stream"` when none was given. |
|
|
986
1098
|
| `format` | [`DocumentFormat`](#documentformat) | The format from `detectFormat`. A text file that turns out to be a log is still `"text"` here: logs are recognized after extraction. |
|
|
987
1099
|
| `scannedPages` | `number \| undefined` | Set for a PDF when one without any text may be accepted: `"pdf"` is in `keepOriginals`, the store has `putOriginal`, and `scannedPdfPages` is above 0. It is the most pages such a PDF may have. Unset, a PDF without text is to be refused. An extractor of your own may ignore it. |
|
|
988
|
-
| `signal` | `AbortSignal \| undefined` | The signal of the ingest: aborted after `ingestTimeoutMs`, or when `IngestInput.signal` aborts. Its `reason` is the error to throw. The PDF, DOCX and
|
|
1100
|
+
| `signal` | `AbortSignal \| undefined` | The signal of the ingest: aborted after `ingestTimeoutMs`, or when `IngestInput.signal` aborts. Its `reason` is the error to throw. The PDF, DOCX, PPTX, XLSX and HTML extractors stop between pages and pieces. The text extractor decodes valid UTF-8 and UTF-16 in one step, and a file that is not valid UTF-8 a step at a time, whatever it is read in, stopping between two steps. `ingest` sets it, and stops waiting for your extractor when it aborts, but cannot stop the work your extractor does: pass it on (to `fetch`, for example), or check it between steps with `signal.throwIfAborted()`. |
|
|
989
1101
|
| `maxTextBytes` | `number \| undefined` | `LargeFilesOptions.maxTextBytes`: the most text to keep, in UTF-8 bytes. `ingest` sets it, and refuses a larger text from any extractor once it returns. An extractor that refuses as soon as its text grows past it spares the memory. |
|
|
990
1102
|
| `maxPages` | `number \| undefined` | `LargeFilesOptions.maxPdfPages`: the most pages to read from one PDF. `ingest` sets it for every format; only the built-in PDF extractor uses it. `ingest` does not check it for you. |
|
|
991
|
-
| `onProgress` | `((progress: ExtractProgress) => void) \| undefined` | Call it as the extraction goes on, so that `ingest` can report progress ([`ExtractProgress`](#extractprogress)). Set only when someone listens to the ingest's events (`IngestInput.onEvent`). The built-in extractors call it for each page of a PDF
|
|
1103
|
+
| `onProgress` | `((progress: ExtractProgress) => void) \| undefined` | Call it as the extraction goes on, so that `ingest` can report progress ([`ExtractProgress`](#extractprogress)). Set only when someone listens to the ingest's events (`IngestInput.onEvent`). The built-in extractors call it for each page of a PDF, each part of a DOCX, each slide of a PPTX and each sheet of an XLSX, and once when an HTML file is decoded. An extractor of your own may ignore it: the ingest then sends no `extract` progress. What it reports after it returned is dropped. It can throw, when the listener of the events throws: let that error end the extraction. New in 0.7.0. |
|
|
992
1104
|
|
|
993
1105
|
### `ExtractProgress`
|
|
994
1106
|
|
|
@@ -1043,7 +1155,7 @@ type ExtractedText = { text: string; pages?: number; encoding?: string; replaced
|
|
|
1043
1155
|
| Field | Type | What it holds |
|
|
1044
1156
|
|---|---|---|
|
|
1045
1157
|
| `text` | `string` | The text of the file. |
|
|
1046
|
-
| `pages` | `number \| undefined` | The number of pages (
|
|
1158
|
+
| `pages` | `number \| undefined` | The number of pages (the slides of a PPTX, the sheets of an XLSX), stored as `DocumentMeta.pages`. |
|
|
1047
1159
|
| `encoding` | `string \| undefined` | The older encoding the file was read in, when it is not UTF-8, such as `"windows-1255"`. Stored as `DocumentMeta.encoding` when it is a name (letters, digits, `.`, `_`, `:` and `-`, up to 40 characters) and not a name of UTF-8 or UTF-16 (`utf-8`, `utf8`, `unicode`, `utf-16be`…): a name `TextDecoder` does not know is kept. New in 0.6.0. |
|
|
1048
1160
|
| `replacedCharacters` | `number \| undefined` | The characters that were not valid in the encoding the file was read in, each now U+FFFD (�). Stored as `DocumentMeta.replacedCharacters` when it is a whole number above 0. New in 0.6.0. |
|
|
1049
1161
|
|
|
@@ -1061,23 +1173,31 @@ The built-in extractor of each format, used for every format you do not replace
|
|
|
1061
1173
|
|
|
1062
1174
|
| Format | What the extractor does |
|
|
1063
1175
|
|---|---|
|
|
1064
|
-
| `text`, `markdown`, `log`, `json`, `csv` | Decodes the bytes as UTF-8, or as UTF-16 when they start with a byte-order mark or look like little-endian UTF-16 without one. A file that is not valid UTF-8 is read as UTF-8 when it starts with a UTF-8 byte-order mark, when at least as many of its lines count as UTF-8 as count as not (a line counts as UTF-8 when it holds at least as many characters of more than one byte as characters that are not valid), or when at most one line in 200 is not UTF-8. Otherwise it is read in windows-1255, windows-1256, windows-1251, Shift_JIS or windows-1252 when its lines with letters fit one, its lines that are valid UTF-8 as UTF-8; and when none fits, as UTF-8, as 0.5.0 read it. Each character that is not valid in the encoding it is read in becomes U+FFFD. It returns `encoding` and `replacedCharacters` ([`ExtractedText`](#extractedtext)), and reads such a file a step at a time, with pauses for other requests. It never refuses a file for its encoding. It refuses gzip, ZIP and other binary files. See [Text encodings](../guides/pdfs.md#text-encodings). |
|
|
1176
|
+
| `text`, `markdown`, `log`, `json`, `csv` | Decodes the bytes as UTF-8, or as UTF-16 when they start with a byte-order mark or look like little-endian UTF-16 without one. A file that is not valid UTF-8 is read as UTF-8 when it starts with a UTF-8 byte-order mark, when at least as many of its lines count as UTF-8 as count as not (a line counts as UTF-8 when it holds at least as many characters of more than one byte as characters that are not valid), or when at most one line in 200 is not UTF-8. Otherwise it is read in windows-1255, windows-1256, windows-1251, Shift_JIS or windows-1252 when its lines with letters fit one, its lines that are valid UTF-8 as UTF-8; and when none fits, as UTF-8, as 0.5.0 read it. Each character that is not valid in the encoding it is read in becomes U+FFFD. It returns `encoding` and `replacedCharacters` ([`ExtractedText`](#extractedtext)), and reads such a file a step at a time, with pauses for other requests. It never refuses a file for its encoding. It refuses gzip, ZIP and other binary files, and the Office files of before 2007 or with a password. See [Text encodings](../guides/pdfs.md#text-encodings). |
|
|
1065
1177
|
| `pdf` | [`createPdfExtractor()`](#createpdfextractoroptions). Needs the optional dependency `unpdf`, in a version that runs on this Node, and `@cantoo/pdf-lib` to mark pages with pictures and to refuse a page that would hold the server. |
|
|
1066
|
-
| `docx` | The paragraphs of the main document first,
|
|
1067
|
-
| `pptx` | One `## Slide N` section per slide, in order, with `[No text on this slide]` for a slide without text. A slide that the slide show skips (`show="0"`) keeps its text, under `## Slide N (hidden, not shown in the slide show)`. `pages` is the number of slides. Needs `jszip`. |
|
|
1178
|
+
| `docx` | The paragraphs of the main document first, one line each. A paragraph of a heading style (`Heading 1` to `Heading 6`, also in a Hebrew document, whose styles keep English names), of the `Title` style or with an outline level is a Markdown heading (`## 2.1 Rent`). A paragraph of a list starts with the number Word shows before it, in Word's formats (`2.1`, `(a)`, roman numerals, Hebrew letters and numerals, `-` for a bullet, lists that restart). A table is a line a row, `\| cell \| cell \| \|`, its empty cells kept, and a merged cell followed by an empty cell for each column it covers. Non-breaking hyphens and the characters of symbol fonts are kept. Then the footnotes, endnotes, comments, headers and footers, in that order, each part under a heading of its own (`# Footnotes`, `# Endnotes`, `# Comments`, `# Header`, `# Footer`), with a blank line between parts; a header or footer whose text repeats one already read is left out. A text box is read once. The text of a run that Word hides (`<w:vanish/>`) comes after the text of its paragraph that shows, each of its lines starting with `[Hidden text, not shown in the document]`: a carriage return, a U+0085 or a line separator in it starts a new marked line, a line of more than about 1,950 characters is cut into marked pieces, and the text of a run inside a hidden run (the reading of a ruby) is marked too. The marks count toward the limits of text. Text hidden through a style is read as ordinary text. Needs the optional dependency `jszip`. Headings, numbers, tables and comments are new in 0.8.0: documents ingested before keep their text until they are uploaded again. |
|
|
1179
|
+
| `pptx` | One `## Slide N` section per slide, numbered in the order of the slide show (the list in `ppt/presentation.xml`; the part names when it has none), with its text, its tables as rows of `\| cell \| cell \|`, and its speaker notes after a line `[Speaker notes]`. `[No text on this slide]` for a slide without text. A slide that the slide show skips (`show="0"`) keeps its text, under `## Slide N (hidden, not shown in the slide show)`. `pages` is the number of slides. Needs `jszip`. Until 0.8.0 slides were numbered in the order of their part names, without tables or notes. |
|
|
1180
|
+
| `xlsx` | New in 0.8.0. Excel workbooks (`.xlsx`, `.xlsm`, `.xltx`, `.xltm`). Each sheet, in the order of the workbook, is a section: `## Sheet 1: Sales` (with ` (hidden sheet)` for a hidden one), then a line `Columns: \| A \| B \| C \|` (`Columns: A to BZ` past 52 columns), then a line a row, `Row 12: \| East \| 2026-03-01 \| 1200.5 \|`, numbered as in Excel, its empty cells kept up to its last value. A cell holds the value Excel last computed (a formula without one is written as `=` and the formula); dates and times from their number formats (1900 and 1904 date systems), percentages as `12.5%`, numbers to 15 significant digits. Empty rows are left out, and a sheet without a value says `[No values on this sheet]`. Every row of every sheet is read, within the limits on text. `pages` is the number of sheets. Needs `jszip`. |
|
|
1181
|
+
| `html` | New in 0.8.0. The text a browser shows: scripts, styles and other content that is not read are dropped; headings become Markdown headings, list items `- item` (or `1. item`), table rows `\| cell \| cell \|`, a link `text (https://…)`, a picture its alt text. A cell that spans columns or rows (`colspan`, `rowspan`) is followed by empty cells, so each row keeps its columns. Text the page hides (the `hidden` attribute, an inline `display: none` or `visibility: hidden`) is kept, each line marked `[Hidden text, not shown in the document]` as Word's hidden text is; hiding through a style sheet or a class is not seen. The title becomes a `#` heading when no heading of the page holds it; a `<title>` never closed names nothing, and the text after it is read as the page. Entities are decoded: `AT&T` is found as "AT&T". The bytes are decoded as a text file's are, in an older encoding when it is not UTF-8, and binary files are refused the same way. |
|
|
1068
1182
|
|
|
1069
|
-
The messages they refuse a file with, which `ingest` throws
|
|
1183
|
+
The messages they refuse a file with, which `ingest` throws as [`IngestError`](#ingesterror)s, each
|
|
1184
|
+
with the code of its words ([`ingestErrorCodeOf`](#ingesterrorcodeofmessage)):
|
|
1070
1185
|
|
|
1071
|
-
- `This file looks binary, not text. Attach a text, log, PDF, DOCX, or PPTX file.`
|
|
1186
|
+
- `This file looks binary, not text. Attach a text, log, PDF, Word, PowerPoint, Excel or HTML file.` (until 0.8.0: `… Attach a text, log, PDF, DOCX, or PPTX file.`)
|
|
1072
1187
|
- `This file is gzip-compressed. Decompress it, then attach the text file inside.`
|
|
1073
|
-
- `This file is a ZIP archive. Extract it, then attach the text file you need.`
|
|
1188
|
+
- `This file is a ZIP archive. Extract it, then attach the text file you need.` (a ZIP whose name is not of a DOCX, PPTX or XLSX: `.zip`, `.odt`)
|
|
1189
|
+
- `This is a Word, Excel or PowerPoint file of before 2007 (.doc, .xls, .ppt), an Outlook message (.msg), or an Office file protected by a password and stored that way. None of these can be read: save it as .docx, .xlsx, .pptx, PDF or text, without a password, and attach that.` (new in 0.8.0: until then such a file was refused as binary, or failed as a damaged file)
|
|
1190
|
+
- `This PDF is protected by a password, so it cannot be read. Open it, print it to a new PDF without the password, and attach that.` (new in 0.8.0: pdf.js said "No password given")
|
|
1074
1191
|
- `Reading PDF files needs the optional dependency "unpdf".`
|
|
1192
|
+
- `The optional dependency "<name>" is installed but could not be loaded (<the reason>). Reinstall it, or install a version this Node can run.` (new in 0.8.0: it was reported as missing; the failure is `cause`)
|
|
1075
1193
|
- `The unpdf installed would stop the whole server at the first PDF file on Node <n>, so PDF files are not read.`, followed by what to install: before Node 22 `Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 24 or later.`, on Node 22 and 23 `Install unpdf 1.6.1 or later, or run Node 24 or later.`, on a later Node `Install unpdf 1.6.1 or later.` (an `unpdf` from 1.5.0 to 1.6.0, which loads a pdf.js that calls `Promise.try` where Node does not have it; new in 0.6.0)
|
|
1076
1194
|
- `The unpdf installed cannot read PDF files on Node <n> (<unpdf's message>). Install unpdf 1.7.0 (npm install unpdf@1.7.0), or run Node 22 or later.` (before Node 22, an `unpdf` that cannot load its pdf.js: 1.9 and later, 2.x included; new in 0.6.0. From Node 22 on, unpdf's own error is thrown as it is.)
|
|
1077
1195
|
- `This PDF has no text layer (it may be scanned). It needs OCR before it can be searched.`
|
|
1078
1196
|
- `This PDF has no text layer (it may be scanned) and <n> pages. Without text it can only be read by looking at its pages, which works for up to <m> pages. It needs OCR first.`
|
|
1079
|
-
- `Reading DOCX and
|
|
1080
|
-
- `This DOCX does not contain word/document.xml.` and `This
|
|
1197
|
+
- `Reading DOCX, PPTX and XLSX files needs the optional dependency "jszip".` (until 0.8.0: `Reading DOCX and PPTX files …`)
|
|
1198
|
+
- `This DOCX does not contain word/document.xml.`, `This PPTX does not contain any slides.`, `This XLSX does not contain xl/workbook.xml.` and `This XLSX does not contain any sheets with cells.`
|
|
1199
|
+
- `This XLSX has more than 2,097,152 different texts, more than a workbook holds. It may be built to exhaust the server, so it is not read.`
|
|
1200
|
+
- `This XLSX holds more text than is kept from one file. Split it, and attach the part you need.` (`maxTextBytes`; `… than is read from one file.` past 32 million characters)
|
|
1081
1201
|
- `This DOCX unpacks to more than <n> MB, over 100 times its size. A file that grows that much is not read: it may be a zip bomb. Save it as text or PDF, and attach that.` (past the first 16 MB; `PPTX` for a presentation)
|
|
1082
1202
|
- `This DOCX unpacks to more than 128 MB of XML, more than is read from one file. Save it as text or PDF, and attach that.`
|
|
1083
1203
|
- `This PDF has <n> pages, more than the <m> read from one file. Split it, and attach the part you need.` (`maxPdfPages`, before any page is read)
|
|
@@ -1086,14 +1206,16 @@ The messages they refuse a file with, which `ingest` throws:
|
|
|
1086
1206
|
- `This PDF lists the same page more than once. A file built that way can hold far more text than its size, so it is not read. Print it to a new PDF, and attach that.`
|
|
1087
1207
|
- `This DOCX holds more than 32 million characters of text, more than is read from one file. Split it, and attach the part you need.` (from one Office file, whatever `maxTextBytes` allows; the marks of hidden text count)
|
|
1088
1208
|
- `This DOCX holds more than <n> MB of text, more than is kept from one file. Split it, and attach the part you need.` (when `maxTextBytes` is below 32 million)
|
|
1089
|
-
- `This DOCX has more than 1,000,000 paragraphs, more than a document holds. It may be built to exhaust the server, so it is not read.` (paragraphs with text)
|
|
1209
|
+
- `This DOCX has more than 1,000,000 paragraphs, more than a document holds. It may be built to exhaust the server, so it is not read.` (paragraphs with text), or `… 1,000,000 paragraphs and table cells, …` when table cells, empty ones included, bring the count past it
|
|
1210
|
+
- `The XML has a tag far longer than any Office file writes. It may be built to exhaust the server, so it is not read.`
|
|
1090
1211
|
- `This DOCX nests paragraphs more than 32 deep, which no document does. It may be built to exhaust the server, so it is not read.`
|
|
1091
1212
|
- `This DOCX has more than 20,000 parts, more than an Office document has. It may be built to exhaust the server, so it is not read.` (before JSZip reads the file: its ZIP directory is read the way JSZip will read it, record by record, whatever count of parts the file gives)
|
|
1092
1213
|
- `This DOCX lists its parts in a way that no Office program does: reading the list would take far more memory or time than an Office document needs. It may be built to exhaust the server, so it is not read.` (more than 80,000 extra fields, or more than 8 MB of names, comments and extra-field data that JSZip would turn into text or go through byte by byte: a name is counted once for each part that points to it, and a field for all the data it says it has, even past its record)
|
|
1093
1214
|
- `This DOCX ends with a ZIP64 record that cannot be read, and reading it could hold the server without end. It may be built to exhaust the server, so it is not read.` (a ZIP64 end record that says it is longer than its fields, which JSZip reads in a loop that does not move on)
|
|
1094
1215
|
|
|
1095
|
-
The Office messages say `PPTX` for a presentation. A PDF or an Office
|
|
1096
|
-
with the
|
|
1216
|
+
The Office messages say `PPTX` for a presentation and `XLSX` for a workbook. A PDF or an Office
|
|
1217
|
+
file that is damaged fails with the message of pdf.js or JSZip, as an `IngestError` of code
|
|
1218
|
+
`"unreadable"` whose `cause` is their error.
|
|
1097
1219
|
|
|
1098
1220
|
### createPdfExtractor(options?)
|
|
1099
1221
|
|
|
@@ -1150,10 +1272,15 @@ then turns a `"text"` document that reads like a log into `"log"`.
|
|
|
1150
1272
|
| `json` | `.json`, `.jsonl`, `.ndjson` | `application/json` |
|
|
1151
1273
|
| `csv` | `.csv`, `.tsv` | `text/csv` |
|
|
1152
1274
|
| `pdf` | `.pdf` | `application/pdf` |
|
|
1153
|
-
| `docx` | `.docx` | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` |
|
|
1154
|
-
| `pptx` | `.pptx` | `application/vnd.openxmlformats-officedocument.presentationml.presentation` |
|
|
1275
|
+
| `docx` | `.docx`, `.docm` | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` |
|
|
1276
|
+
| `pptx` | `.pptx`, `.pptm` | `application/vnd.openxmlformats-officedocument.presentationml.presentation` |
|
|
1277
|
+
| `xlsx` | `.xlsx`, `.xlsm`, `.xltx`, `.xltm` | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`, `application/vnd.ms-excel.sheet.macroenabled.12` |
|
|
1278
|
+
| `html` | `.html`, `.htm`, `.xhtml` | `text/html`, `application/xhtml+xml` |
|
|
1155
1279
|
| `text` | any other | any other |
|
|
1156
1280
|
|
|
1281
|
+
`xlsx` and `html` are new in 0.8.0: until then an `.xlsx` was refused as a ZIP archive, and an
|
|
1282
|
+
`.html` file was `text`, read with its tags.
|
|
1283
|
+
|
|
1157
1284
|
Guide: [PDFs](../guides/pdfs.md).
|
|
1158
1285
|
|
|
1159
1286
|
## Text sizes
|
|
@@ -1239,8 +1366,8 @@ browser instead.
|
|
|
1239
1366
|
| `lines` | `number` | The number of lines of the text. A final line break does not start another line. |
|
|
1240
1367
|
| `estimatedTokens` | `number` | [`estimateTokens`](#estimatetokenstext) of the text. |
|
|
1241
1368
|
| `wrappedLines` | `number` | How many lines longer than 2,000 characters were split into several, so that every line can be read by number. |
|
|
1242
|
-
| `pages` | `number \| undefined` | The pages of a PDF, the slides of a PPTX, or what your extractor returned. |
|
|
1243
|
-
| `encoding` | `string \| undefined` | The older encoding a text file was read in, because it is not UTF-8, as `TextDecoder` names it: `"windows-1255"` for a Hebrew CSV that Excel saved, or `"windows-1256"`, `"windows-1251"`, `"shift_jis"`, `"windows-1252"`. Lines of it that are valid UTF-8 are read as UTF-8 all the same. Absent for valid UTF-8, for a file read as UTF-8 with characters that are not valid (see `replacedCharacters`), for UTF-16, for PDF, DOCX and
|
|
1369
|
+
| `pages` | `number \| undefined` | The pages of a PDF, the slides of a PPTX, the sheets of an XLSX, or what your extractor returned. |
|
|
1370
|
+
| `encoding` | `string \| undefined` | The older encoding a text file was read in, because it is not UTF-8, as `TextDecoder` names it: `"windows-1255"` for a Hebrew CSV that Excel saved, or `"windows-1256"`, `"windows-1251"`, `"shift_jis"`, `"windows-1252"`. Lines of it that are valid UTF-8 are read as UTF-8 all the same. Absent for valid UTF-8, for a file read as UTF-8 with characters that are not valid (see `replacedCharacters`), for UTF-16, for PDF, DOCX, PPTX and XLSX, and on documents from before 0.6.0. An HTML file is decoded as a text file is, and can have one. An extractor of your own may set another name ([`ExtractedText`](#extractedtext)). How the encoding is chosen: [Text encodings](../guides/pdfs.md#text-encodings). New in 0.6.0. |
|
|
1244
1371
|
| `replacedCharacters` | `number \| undefined` | The characters of a text file that were not valid in the encoding it was read in (UTF-8, or `encoding`), such as a character cut in two at the end of a UTF-8 log, or a byte that `encoding` does not have: each is stored as U+FFFD (�). Absent when there were none, and on documents from before 0.6.0. New in 0.6.0. |
|
|
1245
1372
|
| `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. |
|
|
1246
1373
|
| `outline` | [`OutlineEntry[]`](#outlineentry) | The headings found in the text, at most 400. Empty for `log`, `json` and `csv`. |
|
|
@@ -1280,11 +1407,15 @@ Guide: [web app](../guides/web-app.md).
|
|
|
1280
1407
|
### `DocumentFormat`
|
|
1281
1408
|
|
|
1282
1409
|
```ts
|
|
1283
|
-
type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "docx" | "pptx";
|
|
1410
|
+
type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "docx" | "pptx" | "xlsx" | "html";
|
|
1284
1411
|
```
|
|
1285
1412
|
|
|
1286
1413
|
The format of a document. It picks the extractor and decides whether a document gets an outline (not
|
|
1287
|
-
`log`, `json` or `csv`) and a log profile (`log` only). See [`detectFormat`](#detectformatname-mimetype)
|
|
1414
|
+
`log`, `json` or `csv`) and a log profile (`log` only). See [`detectFormat`](#detectformatname-mimetype),
|
|
1415
|
+
and for what each extractor writes, [`defaultExtractors`](#defaultextractors).
|
|
1416
|
+
|
|
1417
|
+
`"xlsx"` (Excel workbooks) and `"html"` (web pages) are new in 0.8.0: an exhaustive `switch` on a
|
|
1418
|
+
document's format, or a `Record<DocumentFormat, …>` of your own, needs the two cases.
|
|
1288
1419
|
|
|
1289
1420
|
### `OutlineEntry`
|
|
1290
1421
|
|