llm-large-files 0.8.0 → 0.8.1
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 +51 -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.map +1 -1
- package/dist/library.js +9 -2
- package/dist/library.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/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/how-it-works.md +7 -0
- package/docs/reference/library.md +17 -6
- package/docs/reference/node.md +1 -1
- package/docs/reference/tools.md +99 -1
- 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 +9 -2
- package/src/plan.ts +17 -1
- package/src/quality.ts +146 -0
- package/src/tools.ts +249 -5
- package/src/types.ts +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -36,6 +36,57 @@ Grouped by area. One or two lines each, written for an app developer, with the n
|
|
|
36
36
|
matter.
|
|
37
37
|
-->
|
|
38
38
|
|
|
39
|
+
## 0.8.1 — 2026-11-23
|
|
40
|
+
|
|
41
|
+
Exact numbers from tables. `aggregate_table` counts, sums, averages and groups the rows of a CSV
|
|
42
|
+
file, a sheet of a workbook or a `| cell |` table of any document, reading every row, with no code
|
|
43
|
+
run; it finds headers of several rows and a title above them. Search hits say which section and
|
|
44
|
+
which table header they belong to. A file whose name says nothing is known by its bytes, and the
|
|
45
|
+
card says which PDF pages have no text or a garbled one. Checked live with the Gemini API on
|
|
46
|
+
`gemini-3.5-flash-lite` and `gemini-3.8-flash`: a sum and a count by region of a workbook, averages
|
|
47
|
+
per region, refunded orders of a CSV with a title row, and a row found by search named by its
|
|
48
|
+
header; all eight answers right, the counts with one `aggregate_table` call.
|
|
49
|
+
|
|
50
|
+
### Upgrading: what you need to change
|
|
51
|
+
|
|
52
|
+
Code written for 0.8.0 compiles with 0.8.1 as it is: every change to the public types is an
|
|
53
|
+
addition (`TOOL_NAMES.aggregate`, optional fields of `DocumentMeta`, an optional third parameter of
|
|
54
|
+
`detectFormat`). A `Record` of your own keyed by the tool names needs the new one.
|
|
55
|
+
|
|
56
|
+
- **A new tool, `aggregate_table`, is offered with CSV, XLSX, DOCX, PPTX, PDF, HTML and Markdown
|
|
57
|
+
documents**, with one more line in the tool guide. The tool set and the guide the model is sent
|
|
58
|
+
change for those documents, so the provider's prompt cache misses once.
|
|
59
|
+
**What to do:** nothing. A loop of your own that runs `files.tools()` gets it too.
|
|
60
|
+
- **Search results have two more fields:** `section` on a match in a document with an outline, and
|
|
61
|
+
`table_headers` on a result whose matches are rows of a table. Tests that compare whole results
|
|
62
|
+
need them.
|
|
63
|
+
**What to do:** nothing, unless your tests compare search results whole.
|
|
64
|
+
|
|
65
|
+
### New: what you can add
|
|
66
|
+
|
|
67
|
+
- **`aggregate_table`** (see [`aggregate_table`](docs/reference/tools.md#aggregate_table)): `metrics`
|
|
68
|
+
(`count`, `sum:Column`, `avg:`, `min:`, `max:`, `count_distinct:`), `group_by` (up to 3 columns,
|
|
69
|
+
a date column by `:year`, `:month` or `:day`), `filters` (`=`, `!=`, `>`, `>=`, `<`, `<=`,
|
|
70
|
+
`contains`, `not_contains`, `starts_with`, `empty`, `not_empty`), `order_by`, `limit`, `table` (a
|
|
71
|
+
sheet's name or number, a table's number) and `header_rows`. Numbers are read as people write
|
|
72
|
+
them ("1,234.5", "(1,200)", "₪4,750", "12,5"); cells that are not numbers are counted apart. A
|
|
73
|
+
header of two or three rows is joined ("Q1 / January"), a title row above it is left out, and a
|
|
74
|
+
header repeated inside the table is not a row. Each group cites the lines of its first rows.
|
|
75
|
+
- **`DocumentMeta.pagesWithoutText`, `garbledPages` and `scripts`**, worked out at ingest and shown
|
|
76
|
+
on the card: the PDF pages with no text (scans, photos) and those whose text looks garbled, with
|
|
77
|
+
a pointer to `view_pages` when they can be looked at, and the scripts of a text that is not in
|
|
78
|
+
Latin letters alone ("Written in: Hebrew 81%, Latin 19%").
|
|
79
|
+
- **`detectFormat(name, mimeType, bytes?)`** and `ingest`: a file whose name and type give no format
|
|
80
|
+
is known by its bytes (a PDF header, the parts of a DOCX, PPTX or XLSX, a first `<html>`). A file
|
|
81
|
+
named `.txt` stays text.
|
|
82
|
+
|
|
83
|
+
### Changed: what works differently
|
|
84
|
+
|
|
85
|
+
- **Search hits say where they sit** (F15): `section` is the heading above a match ("2.1 Rent",
|
|
86
|
+
"Sheet 2: Sales"); `table_headers` gives the first row of each table a match is in (line 1 of a
|
|
87
|
+
CSV file, a sheet's first row, a `| cell |` table's first row), so a hit like `Row 812: | 4,200 |`
|
|
88
|
+
is understood without another read.
|
|
89
|
+
|
|
39
90
|
## 0.8.0 — 2026-11-23
|
|
40
91
|
|
|
41
92
|
Files from an enterprise, read with their structure, and counted exactly. Word files keep their
|
package/README.md
CHANGED
|
@@ -257,6 +257,8 @@ What each model gets, and what it costs: [An explorer model](docs/guides/explore
|
|
|
257
257
|
| **Formats** | Text, Markdown, logs (UTF-8 and UTF-16, and Hebrew, Arabic, Cyrillic, Japanese and Western European text in its older encoding), JSON/JSONL, CSV/TSV, HTML (the text a browser shows), DOCX (headings, clause numbers, tables, notes and comments), PPTX (slides in show order, tables, speaker notes), XLSX (every sheet, a line per row, with its row number), PDF (text layer, with tables rebuilt so empty cells stay empty; pages with a picture are marked, and the model can look at the pages themselves; scans of up to 30 pages when PDFs are kept) |
|
|
258
258
|
| **Logs** | Detected automatically; the card shows level counts, the time range, and the most frequent errors grouped by shape (`timeout after <n>ms to <ip>`) |
|
|
259
259
|
| **Books and documents** | An outline of headings with line numbers, including Markdown, "Chapter 12", numbered sections, and Hebrew chapter titles |
|
|
260
|
+
| **Counting** | Exact counts of matching lines, per hour, per code or per message shape, in one search; exact sums, averages and groups over the rows of a CSV, an Excel sheet or a table of a document with `aggregate_table`, which reads every row and runs no code |
|
|
261
|
+
| **Every language** | Search finds a Hebrew word with any prefix letter, words written with or without accents, quotes or gershayim either way; regex `\w` and `\b` know every script |
|
|
260
262
|
| **Limits** | One budget covers tokens *and* request bytes, so files fit both your context window and your connector's payload limit. It assumes 1M tokens and 10 MB: set `budget.contextTokens` for your model's window (an adapter's `contextTokens` can only make it smaller) |
|
|
261
263
|
| **Reliability** | Retries, waits on a silent model, recovery from a request too large, error kinds: see [Errors and reliability](docs/guides/errors-and-reliability.md) |
|
|
262
264
|
| **Models** | Gemini and Vertex AI, any OpenAI-compatible endpoint, Claude, or an adapter of your own. Two models of different providers can share a question |
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type DocumentSource } from "./search.js";
|
|
2
|
+
/**
|
|
3
|
+
* `aggregate_table`: counts, sums, averages, minimums and maximums over the rows of one table of a
|
|
4
|
+
* document, with filters and groups, exactly, without code and without the model reading the rows.
|
|
5
|
+
* A model that adds up 50,000 rows by reading them needs hundreds of calls and gets it wrong; this
|
|
6
|
+
* reads them once. Every group says the lines of its first rows, so an answer can cite them.
|
|
7
|
+
*
|
|
8
|
+
* The tables it reads:
|
|
9
|
+
* - a CSV or TSV file (format "csv"): the whole file, its first line the header; the separator is
|
|
10
|
+
* found from the first lines (comma, semicolon, tab or "|"), and quoted fields may hold separators,
|
|
11
|
+
* quotes and line breaks;
|
|
12
|
+
* - a sheet of an Excel workbook (format "xlsx"), as the XLSX extractor writes it: `## Sheet 2:
|
|
13
|
+
* name`, `Columns: …`, then `Row 7: | a | b |` lines; its first row is the header unless every
|
|
14
|
+
* value of it is a number, and then the columns are named by their letters;
|
|
15
|
+
* - any run of `| cell | cell |` lines in another document: the tables of DOCX, PPTX, PDF, HTML and
|
|
16
|
+
* Markdown files, numbered in the order of the file. A Markdown separator row (`|---|`) is skipped.
|
|
17
|
+
*/
|
|
18
|
+
/** The most groups counted one by one; rows of further groups are counted together. */
|
|
19
|
+
export declare const MAX_AGGREGATE_GROUPS = 10000;
|
|
20
|
+
/** The most groups shown in a result. */
|
|
21
|
+
export declare const MAX_SHOWN_GROUPS = 200;
|
|
22
|
+
/** Distinct values `count_distinct` holds, across all groups: past it, values are no longer told apart. */
|
|
23
|
+
export declare const MAX_DISTINCT_VALUES = 1000000;
|
|
24
|
+
export type AggregateOp = "count" | "sum" | "avg" | "min" | "max" | "count_distinct";
|
|
25
|
+
export declare const AGGREGATE_OPS: readonly AggregateOp[];
|
|
26
|
+
export type FilterOp = "=" | "!=" | ">" | ">=" | "<" | "<=" | "contains" | "not_contains" | "starts_with" | "empty" | "not_empty";
|
|
27
|
+
export declare const FILTER_OPS: readonly FilterOp[];
|
|
28
|
+
/** A date column grouped by a part of its dates: `"Date:month"` groups 2026-03-14 under 2026-03. */
|
|
29
|
+
export type DatePart = "year" | "month" | "day";
|
|
30
|
+
export type AggregateRequest = {
|
|
31
|
+
/** Which table: a sheet's name or number for a workbook, a table's number for other documents. Defaults to the first. */
|
|
32
|
+
table?: string | number;
|
|
33
|
+
filters?: Array<{
|
|
34
|
+
column: string;
|
|
35
|
+
op: FilterOp;
|
|
36
|
+
value?: string | number;
|
|
37
|
+
}>;
|
|
38
|
+
/** Up to 3 columns; each may end in ":year", ":month" or ":day" for a column of dates. */
|
|
39
|
+
groupBy?: string[];
|
|
40
|
+
/** "count", or an op and a column: "sum:Revenue", "avg:Price", "count_distinct:Customer". Defaults to ["count"]. */
|
|
41
|
+
metrics?: string[];
|
|
42
|
+
/** "metric" (the default): the largest value of the first metric first; "key": by the groups' values, in order. */
|
|
43
|
+
orderBy?: "metric" | "key";
|
|
44
|
+
/**
|
|
45
|
+
* How many rows at the top of the table are its header: 0 when it has none (columns are named by
|
|
46
|
+
* their letters in a workbook, "Column 1"… elsewhere), up to 5. Unset: one for a CSV file; for a
|
|
47
|
+
* sheet or a `| cell |` table it is found (see `aggregateTable`).
|
|
48
|
+
*/
|
|
49
|
+
headerRows?: number;
|
|
50
|
+
/** Groups shown, at most. Defaults to 50. */
|
|
51
|
+
limit?: number;
|
|
52
|
+
};
|
|
53
|
+
export type AggregateGroup = {
|
|
54
|
+
/** The value of each group-by column, as the first row of the group writes it. */
|
|
55
|
+
key: Record<string, string>;
|
|
56
|
+
count: number;
|
|
57
|
+
/** Each metric by its name ("sum:Revenue"). Null when no row of the group had a number in its column. */
|
|
58
|
+
values: Record<string, number | string | null>;
|
|
59
|
+
/** The lines of the group's first rows. */
|
|
60
|
+
lines: number[];
|
|
61
|
+
};
|
|
62
|
+
export type AggregateResult = {
|
|
63
|
+
/** Which table was read: "Sheet 2: Sales", "table 3 of 5", "the CSV file". */
|
|
64
|
+
table: string;
|
|
65
|
+
/** How many tables the document has: sheets, or `| cell |` tables. */
|
|
66
|
+
tables: number;
|
|
67
|
+
columns: string[];
|
|
68
|
+
headerLine: number;
|
|
69
|
+
rowsRead: number;
|
|
70
|
+
rowsMatched: number;
|
|
71
|
+
groups: AggregateGroup[];
|
|
72
|
+
totalGroups: number;
|
|
73
|
+
/** Rows of groups past `MAX_AGGREGATE_GROUPS`. */
|
|
74
|
+
otherRows: number;
|
|
75
|
+
/** The rows taken for the header, and a title row above them that was left out. */
|
|
76
|
+
headerRows: number;
|
|
77
|
+
title?: string;
|
|
78
|
+
/** Rows the same as the header, found again inside the table (a header a PDF repeats on each page): left out. */
|
|
79
|
+
repeatedHeaders: number;
|
|
80
|
+
/** Rows with another number of cells than the header: read, and counted here, as a sign of a table read wrong. */
|
|
81
|
+
irregularRows: number;
|
|
82
|
+
/** True when `count_distinct` reached `MAX_DISTINCT_VALUES`: its counts are lower bounds. */
|
|
83
|
+
distinctCapped: boolean;
|
|
84
|
+
/** For each numeric metric, how many matched rows had a value in its column that is not a number (left out). */
|
|
85
|
+
notNumbers: Record<string, number>;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* A number as a person writes it in a table: "1,234.5", "-12", "(1,200)" for a negative, "₪4,750",
|
|
89
|
+
* "$ 12.00", "12%" (12), "1.5e3", "1 234" with a space or a no-break space between thousands.
|
|
90
|
+
* A value with a comma and no dot is taken for thousands when the comma is followed by three digits
|
|
91
|
+
* ("4,750"), and for a decimal comma otherwise ("12,5"). Undefined for anything else.
|
|
92
|
+
*/
|
|
93
|
+
export declare function parseNumber(raw: string): number | undefined;
|
|
94
|
+
/** Splits a `| a | b |` row into its cells, honouring `\|` inside a cell. */
|
|
95
|
+
export declare function pipeCells(line: string): string[];
|
|
96
|
+
/** The separator of a CSV file, from its first lines: the one found the same number of times (above 0) on most of them. */
|
|
97
|
+
export declare function csvSeparator(lines: string[]): string;
|
|
98
|
+
/**
|
|
99
|
+
* Reads the rows of one table and aggregates them. Throws an error the model can act on: no table,
|
|
100
|
+
* a table that does not exist, an unknown column or operation.
|
|
101
|
+
*/
|
|
102
|
+
export declare function aggregateTable(source: DocumentSource, request: AggregateRequest, signal?: AbortSignal): Promise<AggregateResult>;
|
|
103
|
+
//# sourceMappingURL=aggregate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../src/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAG9D;;;;;;;;;;;;;;;GAeG;AAEH,uFAAuF;AACvF,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,y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