llm-large-files 0.3.6 → 0.4.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 +37 -0
- package/dist/cache.d.ts +40 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +81 -0
- package/dist/cache.js.map +1 -0
- package/dist/index.d.ts +1 -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 +28 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +155 -47
- package/dist/library.js.map +1 -1
- package/dist/limiter.d.ts +20 -0
- package/dist/limiter.d.ts.map +1 -0
- package/dist/limiter.js +55 -0
- package/dist/limiter.js.map +1 -0
- package/dist/map-reduce.d.ts +8 -4
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +65 -24
- package/dist/map-reduce.js.map +1 -1
- package/dist/plan.d.ts +7 -5
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +9 -8
- package/dist/plan.js.map +1 -1
- package/dist/ranged.d.ts +102 -0
- package/dist/ranged.d.ts.map +1 -0
- package/dist/ranged.js +314 -0
- package/dist/ranged.js.map +1 -0
- package/dist/search.d.ts +79 -15
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +388 -130
- package/dist/search.js.map +1 -1
- package/dist/stores.d.ts +22 -2
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +132 -15
- package/dist/stores.js.map +1 -1
- package/dist/text-index.d.ts +64 -0
- package/dist/text-index.d.ts.map +1 -0
- package/dist/text-index.js +211 -0
- package/dist/text-index.js.map +1 -0
- package/dist/text.d.ts +2 -1
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +7 -1
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +2 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +20 -14
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/api.md +12 -5
- package/docs/configuration.md +45 -3
- package/docs/how-it-works.md +3 -1
- package/docs/security.md +3 -0
- package/package.json +7 -3
- package/src/cache.ts +83 -0
- package/src/index.ts +1 -1
- package/src/library.ts +176 -44
- package/src/limiter.ts +51 -0
- package/src/map-reduce.ts +70 -25
- package/src/plan.ts +10 -9
- package/src/ranged.ts +348 -0
- package/src/search.ts +432 -120
- package/src/stores.ts +136 -17
- package/src/text-index.ts +228 -0
- package/src/text.ts +7 -1
- package/src/tools.ts +22 -16
- package/src/types.ts +15 -0
package/dist/ranged.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { pagesOfLines } from "./search.js";
|
|
2
|
+
import { canSerialize, parseTextIndex, positionOf, serializeTextIndex, TextIndexBuilder } from "./text-index.js";
|
|
3
|
+
import { foldCase, LineIndex } from "./text.js";
|
|
4
|
+
/** The cache key of piece `at` of a document. All of them start with `${id}#`. */
|
|
5
|
+
export const pieceKey = (id, at) => `${id}#${at}`;
|
|
6
|
+
/** Bytes read at a time to build an index from the text. */
|
|
7
|
+
const BUILD_READ_BYTES = 4 * 1024 * 1024;
|
|
8
|
+
/** A pass shared by several scans lets other work run after this much time on the main thread. */
|
|
9
|
+
const YIELD_AFTER_MS = 15;
|
|
10
|
+
const decoder = new TextDecoder("utf-8");
|
|
11
|
+
const gone = (id) => new Error(`${id} is no longer available on the server. Ask the user to attach the file again.`);
|
|
12
|
+
export class RangedDocument {
|
|
13
|
+
store;
|
|
14
|
+
meta;
|
|
15
|
+
index;
|
|
16
|
+
settings;
|
|
17
|
+
/**
|
|
18
|
+
* Set when the stored text did not agree with the index. The library then drops this object and
|
|
19
|
+
* opens the document again, building its index from the text.
|
|
20
|
+
*/
|
|
21
|
+
broken = false;
|
|
22
|
+
/** The version its pieces are kept under, and whether they are kept at all. */
|
|
23
|
+
pieceVersion;
|
|
24
|
+
keepPieces;
|
|
25
|
+
ranges;
|
|
26
|
+
constructor(store, meta, index, settings) {
|
|
27
|
+
this.store = store;
|
|
28
|
+
this.meta = meta;
|
|
29
|
+
this.index = index;
|
|
30
|
+
this.settings = settings;
|
|
31
|
+
this.pieceVersion = `${meta.createdAt}|${index.textBytes}|${index.characters}|${settings.chunkBytes}`;
|
|
32
|
+
// Decoded text is one byte a character when it is all ASCII, two otherwise; and its lowercased copy as much again.
|
|
33
|
+
const decoded = index.characters * (index.textBytes === index.characters ? 1 : 2) * 2 + index.characterStarts.byteLength;
|
|
34
|
+
this.keepPieces = settings.pieces !== undefined && decoded <= settings.pieces.maxDocumentBytes;
|
|
35
|
+
}
|
|
36
|
+
get lineCount() {
|
|
37
|
+
return this.index.lineCount;
|
|
38
|
+
}
|
|
39
|
+
get characters() {
|
|
40
|
+
return this.index.characters;
|
|
41
|
+
}
|
|
42
|
+
get passageStarts() {
|
|
43
|
+
return this.index.passageStarts;
|
|
44
|
+
}
|
|
45
|
+
get memoryBytes() {
|
|
46
|
+
const { lineStarts, characterStarts, passageStarts, pageStarts } = this.index;
|
|
47
|
+
return lineStarts.byteLength + characterStarts.byteLength + passageStarts.byteLength + pageStarts.byteLength + 2_048;
|
|
48
|
+
}
|
|
49
|
+
pageOfLine(line) {
|
|
50
|
+
const starts = this.index.pageStarts;
|
|
51
|
+
return starts.length === 0 || line < starts[0] ? undefined : positionOf(starts, line);
|
|
52
|
+
}
|
|
53
|
+
pagesOfLines(from, to) {
|
|
54
|
+
return pagesOfLines(this.index.pageStarts, from, to);
|
|
55
|
+
}
|
|
56
|
+
async readLines(from, to) {
|
|
57
|
+
const first = Math.max(1, from);
|
|
58
|
+
const last = Math.min(to, this.index.lineCount);
|
|
59
|
+
if (first > last)
|
|
60
|
+
return [];
|
|
61
|
+
const text = await this.read(...this.bytesOf(first, last));
|
|
62
|
+
const lines = (text.endsWith("\n") ? text.slice(0, -1) : text).split("\n");
|
|
63
|
+
if (lines.length !== last - first + 1)
|
|
64
|
+
throw this.mismatch();
|
|
65
|
+
return lines;
|
|
66
|
+
}
|
|
67
|
+
async readText() {
|
|
68
|
+
const text = await this.read(0, this.index.textBytes);
|
|
69
|
+
if (text.length !== this.index.characters)
|
|
70
|
+
throw this.mismatch();
|
|
71
|
+
return text;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The text in pieces of whole passages, about `chunkBytes` each. A scan waits for a slot of the
|
|
75
|
+
* limiter first, and holds it until it ends or is abandoned. `scan` does the same for several
|
|
76
|
+
* scans at once.
|
|
77
|
+
*/
|
|
78
|
+
async *chunks(signal) {
|
|
79
|
+
const release = await this.settings.limiter.acquire(signal);
|
|
80
|
+
try {
|
|
81
|
+
for await (const chunk of this.pieces()) {
|
|
82
|
+
signal?.throwIfAborted();
|
|
83
|
+
yield chunk;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
release();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Feeds the text, a piece at a time and in order, to `feed` until it returns true or the text
|
|
92
|
+
* ends. Scans asked for while others of this document wait for a slot of the limiter join them:
|
|
93
|
+
* the pieces are then read, decoded and lowercased once, for all of them. A scan asked for once
|
|
94
|
+
* the pass has started waits for the next one, since every scan must see the text from the start.
|
|
95
|
+
*/
|
|
96
|
+
scan(feed, signal) {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
if (signal?.aborted) {
|
|
99
|
+
reject(signal.reason);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const onAbort = () => consumer.settle(signal.reason);
|
|
103
|
+
const consumer = {
|
|
104
|
+
feed,
|
|
105
|
+
done: false,
|
|
106
|
+
settle: (error) => {
|
|
107
|
+
if (consumer.done)
|
|
108
|
+
return;
|
|
109
|
+
consumer.done = true;
|
|
110
|
+
signal?.removeEventListener("abort", onAbort);
|
|
111
|
+
if (error === undefined)
|
|
112
|
+
resolve();
|
|
113
|
+
else
|
|
114
|
+
reject(error);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
118
|
+
if (this.gathering) {
|
|
119
|
+
this.gathering.push(consumer);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const group = [consumer];
|
|
123
|
+
this.gathering = group;
|
|
124
|
+
void this.pass(group);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Scans waiting for a slot, open to more of them. */
|
|
128
|
+
gathering;
|
|
129
|
+
async pass(group) {
|
|
130
|
+
const release = await this.settings.limiter.acquire();
|
|
131
|
+
// From here on the group is closed.
|
|
132
|
+
if (this.gathering === group)
|
|
133
|
+
this.gathering = undefined;
|
|
134
|
+
try {
|
|
135
|
+
if (group.every((consumer) => consumer.done))
|
|
136
|
+
return;
|
|
137
|
+
let slice = performance.now();
|
|
138
|
+
for await (const chunk of this.pieces()) {
|
|
139
|
+
let open = 0;
|
|
140
|
+
for (const consumer of group) {
|
|
141
|
+
if (consumer.done)
|
|
142
|
+
continue;
|
|
143
|
+
try {
|
|
144
|
+
if (consumer.feed(chunk) === true)
|
|
145
|
+
consumer.settle();
|
|
146
|
+
else
|
|
147
|
+
open++;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
consumer.settle(error);
|
|
151
|
+
}
|
|
152
|
+
// Many scans on one piece add up: give other work (answers streaming to other users) a turn.
|
|
153
|
+
if (performance.now() - slice > YIELD_AFTER_MS) {
|
|
154
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
155
|
+
slice = performance.now();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (open === 0)
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
for (const consumer of group)
|
|
162
|
+
consumer.settle();
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
for (const consumer of group)
|
|
166
|
+
consumer.settle(error);
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
release();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The pieces, in order: kept ones from memory, the others read and decoded, the next one read
|
|
174
|
+
* while the current one is used. Line breaks are where the index says, which each piece read is
|
|
175
|
+
* checked against.
|
|
176
|
+
*/
|
|
177
|
+
async *pieces() {
|
|
178
|
+
const count = this.chunkRanges().length;
|
|
179
|
+
const load = (at) => {
|
|
180
|
+
const promise = this.piece(at);
|
|
181
|
+
// Read ahead: if the scan stops before it needs this piece, nobody waits for it.
|
|
182
|
+
promise.catch(() => undefined);
|
|
183
|
+
return promise;
|
|
184
|
+
};
|
|
185
|
+
let next = count > 0 ? load(0) : undefined;
|
|
186
|
+
for (let at = 0; at < count; at++) {
|
|
187
|
+
const chunk = await next;
|
|
188
|
+
next = at + 1 < count ? load(at + 1) : undefined;
|
|
189
|
+
yield chunk;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** Piece `at`, from memory when it is kept there. */
|
|
193
|
+
async piece(at) {
|
|
194
|
+
const cache = this.keepPieces ? this.settings.pieces : undefined;
|
|
195
|
+
const kept = cache?.get(pieceKey(this.meta.id, at), this.pieceVersion);
|
|
196
|
+
if (kept)
|
|
197
|
+
return kept;
|
|
198
|
+
const { firstLine, lastLine, start, end } = this.chunkRanges()[at];
|
|
199
|
+
const text = await this.read(start, end);
|
|
200
|
+
const { characterStarts, characters, lineCount } = this.index;
|
|
201
|
+
const startCharacter = characterStarts[firstLine - 1];
|
|
202
|
+
const endCharacter = lastLine < lineCount ? characterStarts[lastLine] : characters;
|
|
203
|
+
if (text.length !== endCharacter - startCharacter)
|
|
204
|
+
throw this.mismatch();
|
|
205
|
+
const starts = new Uint32Array(lastLine - firstLine + 1);
|
|
206
|
+
for (let line = 0; line < starts.length; line++) {
|
|
207
|
+
const lineStart = characterStarts[firstLine - 1 + line] - startCharacter;
|
|
208
|
+
// Each line but the first starts right after a line break.
|
|
209
|
+
if (line > 0 && text.charCodeAt(lineStart - 1) !== 10)
|
|
210
|
+
throw this.mismatch();
|
|
211
|
+
starts[line] = lineStart;
|
|
212
|
+
}
|
|
213
|
+
if (lastLine < lineCount && text.charCodeAt(text.length - 1) !== 10)
|
|
214
|
+
throw this.mismatch();
|
|
215
|
+
let lower;
|
|
216
|
+
const ascii = end - start === text.length;
|
|
217
|
+
const piece = {
|
|
218
|
+
firstLine,
|
|
219
|
+
startCharacter,
|
|
220
|
+
text,
|
|
221
|
+
lines: new LineIndex(text, starts),
|
|
222
|
+
lower: () => (lower ??= foldCase(text)),
|
|
223
|
+
// The text and, once a search needs it, its lowercased copy.
|
|
224
|
+
memoryBytes: text.length * (ascii ? 1 : 2) * 2 + starts.byteLength + 256,
|
|
225
|
+
};
|
|
226
|
+
cache?.set(pieceKey(this.meta.id, at), this.pieceVersion, piece);
|
|
227
|
+
return piece;
|
|
228
|
+
}
|
|
229
|
+
/** The bytes of lines `first` to `last`, which must exist. */
|
|
230
|
+
bytesOf(first, last) {
|
|
231
|
+
const { lineStarts, lineCount, textBytes } = this.index;
|
|
232
|
+
return [lineStarts[first - 1], last < lineCount ? lineStarts[last] : textBytes];
|
|
233
|
+
}
|
|
234
|
+
/** Line ranges of whole passages, each about `chunkBytes` (one passage at least). */
|
|
235
|
+
chunkRanges() {
|
|
236
|
+
if (this.ranges)
|
|
237
|
+
return this.ranges;
|
|
238
|
+
const { passageStarts, lineStarts, lineCount, textBytes } = this.index;
|
|
239
|
+
const ranges = [];
|
|
240
|
+
for (let passage = 0; passage < passageStarts.length;) {
|
|
241
|
+
const firstLine = passageStarts[passage];
|
|
242
|
+
const start = lineStarts[firstLine - 1];
|
|
243
|
+
let next = passage + 1;
|
|
244
|
+
while (next < passageStarts.length && lineStarts[passageStarts[next] - 1] - start < this.settings.chunkBytes)
|
|
245
|
+
next++;
|
|
246
|
+
const end = next < passageStarts.length ? lineStarts[passageStarts[next] - 1] : textBytes;
|
|
247
|
+
ranges.push({ firstLine, lastLine: next < passageStarts.length ? passageStarts[next] - 1 : lineCount, start, end });
|
|
248
|
+
passage = next;
|
|
249
|
+
}
|
|
250
|
+
this.ranges = ranges;
|
|
251
|
+
return ranges;
|
|
252
|
+
}
|
|
253
|
+
async read(start, end) {
|
|
254
|
+
const bytes = await this.store.readTextRange(this.meta.id, start, end);
|
|
255
|
+
if (!bytes)
|
|
256
|
+
throw gone(this.meta.id);
|
|
257
|
+
if (bytes.length !== end - start)
|
|
258
|
+
throw this.mismatch();
|
|
259
|
+
return decoder.decode(bytes);
|
|
260
|
+
}
|
|
261
|
+
mismatch() {
|
|
262
|
+
if (!this.broken) {
|
|
263
|
+
this.broken = true;
|
|
264
|
+
this.settings.onBroken?.(this.meta.id);
|
|
265
|
+
}
|
|
266
|
+
return new Error(`The stored text of ${this.meta.name} did not match its index. Try the call again.`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/** Builds the index of a stored text by reading all of it once. Undefined when the text is gone. */
|
|
270
|
+
export async function buildIndexFromStore(store, id, limiter) {
|
|
271
|
+
const release = await limiter.acquire();
|
|
272
|
+
try {
|
|
273
|
+
const builder = new TextIndexBuilder();
|
|
274
|
+
for (let position = 0;;) {
|
|
275
|
+
const bytes = await store.readTextRange(id, position, position + BUILD_READ_BYTES);
|
|
276
|
+
if (!bytes)
|
|
277
|
+
return undefined;
|
|
278
|
+
builder.push(bytes);
|
|
279
|
+
position += bytes.length;
|
|
280
|
+
if (bytes.length < BUILD_READ_BYTES)
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
const index = builder.finish();
|
|
284
|
+
return index.lineCount > 0 ? index : undefined;
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
release();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Opens a document to be read by range. Uses the saved index when there is one that fits the
|
|
292
|
+
* document; otherwise builds it from the text and saves it (best effort: a store that cannot
|
|
293
|
+
* write, or another server writing the same index, changes nothing). Undefined when the text is gone.
|
|
294
|
+
*/
|
|
295
|
+
export async function openRangedDocument(store, meta, settings, options = {}) {
|
|
296
|
+
let index;
|
|
297
|
+
if (!options.ignoreSavedIndex && store.getIndex) {
|
|
298
|
+
const saved = await store.getIndex(meta.id).catch(() => undefined);
|
|
299
|
+
if (saved)
|
|
300
|
+
index = parseTextIndex(saved, meta);
|
|
301
|
+
}
|
|
302
|
+
if (!index) {
|
|
303
|
+
index = await buildIndexFromStore(store, meta.id, settings.limiter);
|
|
304
|
+
if (!index)
|
|
305
|
+
return undefined;
|
|
306
|
+
// An index that disagrees with the metadata describes a text that is not what was ingested.
|
|
307
|
+
// It is used, since it is what the store holds, but not saved.
|
|
308
|
+
if (store.putIndex && canSerialize(index) && index.lineCount === meta.lines && index.characters === meta.characters) {
|
|
309
|
+
await store.putIndex(meta.id, serializeTextIndex(index)).catch(() => undefined);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return new RangedDocument(store, meta, index, settings);
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=ranged.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ranged.js","sourceRoot":"","sources":["../src/ranged.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAuC,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAkB,MAAM,iBAAiB,CAAC;AACjI,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AA8BhD,kFAAkF;AAClF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAE,EAAU,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;AAElE,4DAA4D;AAC5D,MAAM,gBAAgB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,kGAAkG;AAClG,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;AAEzC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AC;IACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,MAAM,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpE,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,4FAA4F;QAC5F,+DAA+D;QAC/D,IAAI,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;YACpH,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/search.d.ts
CHANGED
|
@@ -1,18 +1,71 @@
|
|
|
1
1
|
import { LineIndex } from "./text.js";
|
|
2
2
|
import type { DocumentMeta, StoredDocument } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A piece of a document's text: whole lines, in order. A document read by range is scanned in
|
|
5
|
+
* pieces that start at passage starts; a document held in memory is one piece.
|
|
6
|
+
*/
|
|
7
|
+
export type TextChunk = {
|
|
8
|
+
/** The document line of the piece's first line. */
|
|
9
|
+
firstLine: number;
|
|
10
|
+
/** Where the piece starts in the whole text, in UTF-16 units. */
|
|
11
|
+
startCharacter: number;
|
|
12
|
+
text: string;
|
|
13
|
+
lines: LineIndex;
|
|
14
|
+
/** `text` lowercased with `foldCase`: the same length, so offsets match. */
|
|
15
|
+
lower(): string;
|
|
16
|
+
};
|
|
17
|
+
/** A document the tools can read and search: held whole in memory, or read by range from the store. */
|
|
18
|
+
export interface DocumentSource {
|
|
19
|
+
readonly meta: DocumentMeta;
|
|
20
|
+
readonly lineCount: number;
|
|
21
|
+
/** The length of the whole text, in UTF-16 units. */
|
|
22
|
+
readonly characters: number;
|
|
23
|
+
/** The first line of each passage (keyword search). */
|
|
24
|
+
readonly passageStarts: ArrayLike<number>;
|
|
25
|
+
/** Memory this object holds, for the cache. */
|
|
26
|
+
readonly memoryBytes: number;
|
|
27
|
+
/** Set when the stored text turned out not to match what this object knows of it: open it again. */
|
|
28
|
+
readonly broken?: boolean;
|
|
29
|
+
pageOfLine(line: number): number | undefined;
|
|
30
|
+
pagesOfLines(from: number, to: number): string | undefined;
|
|
31
|
+
/** Lines `from` to `to`, clamped to the document. */
|
|
32
|
+
readLines(from: number, to: number): Promise<string[]>;
|
|
33
|
+
readText(): Promise<string>;
|
|
34
|
+
/** The whole text in pieces of whole lines, in order. */
|
|
35
|
+
chunks(signal?: AbortSignal): AsyncIterable<TextChunk>;
|
|
36
|
+
/**
|
|
37
|
+
* Optional: feeds the pieces in order to `feed` until it returns true, sharing one pass over the
|
|
38
|
+
* text with other scans of the same document where it can.
|
|
39
|
+
*/
|
|
40
|
+
scan?(feed: (chunk: TextChunk) => boolean | void, signal?: AbortSignal): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/** Feeds a document's text, a piece at a time, to `feed` until it returns true or the text ends. */
|
|
43
|
+
export declare function scanSource(source: DocumentSource, feed: (chunk: TextChunk) => boolean | void, signal?: AbortSignal): Promise<void>;
|
|
44
|
+
/** Lines as the tools show them: "12| text", one a line. */
|
|
45
|
+
export declare function numberLines(lines: readonly string[], from: number): string;
|
|
46
|
+
/** The pages a range of lines is on, as "12" or "12-14", from the first line of each page. */
|
|
47
|
+
export declare function pagesOfLines(pageStarts: ArrayLike<number>, from: number, to: number): string | undefined;
|
|
48
|
+
/** A stored document held whole in memory, with lazily built search structures. */
|
|
49
|
+
export declare class SearchableDocument implements DocumentSource {
|
|
5
50
|
readonly meta: DocumentMeta;
|
|
6
51
|
readonly text: string;
|
|
7
52
|
readonly lines: LineIndex;
|
|
8
53
|
private lowerText?;
|
|
9
|
-
private
|
|
54
|
+
private passageStartList?;
|
|
10
55
|
private pageStarts?;
|
|
11
56
|
constructor(document: StoredDocument);
|
|
57
|
+
get lineCount(): number;
|
|
58
|
+
get characters(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Memory this document takes once it has been searched: the text, its lowercased copy, and the
|
|
61
|
+
* line index. A text of ASCII only is held at one byte a character, any other at two.
|
|
62
|
+
*/
|
|
63
|
+
get memoryBytes(): number;
|
|
12
64
|
/** The text lowercased for case-insensitive search. Same length as `text`, so offsets match. */
|
|
13
65
|
get lower(): string;
|
|
14
66
|
/** First line of each passage: groups of lines up to about 1,500 characters. */
|
|
15
67
|
get passages(): number[];
|
|
68
|
+
get passageStarts(): ArrayLike<number>;
|
|
16
69
|
passageRange(index: number): {
|
|
17
70
|
from: number;
|
|
18
71
|
to: number;
|
|
@@ -26,6 +79,12 @@ export declare class SearchableDocument {
|
|
|
26
79
|
pageOfLine(line: number): number | undefined;
|
|
27
80
|
/** The pages a range of lines is on, as "12" or "12-14". Undefined for a text without page lines. */
|
|
28
81
|
pagesOfLines(from: number, to: number): string | undefined;
|
|
82
|
+
readLines(from: number, to: number): Promise<string[]>;
|
|
83
|
+
readText(): Promise<string>;
|
|
84
|
+
/** The whole text as one piece. */
|
|
85
|
+
wholeChunk(): TextChunk;
|
|
86
|
+
chunks(): AsyncGenerator<TextChunk>;
|
|
87
|
+
private pageLines;
|
|
29
88
|
}
|
|
30
89
|
export type LineMatch = {
|
|
31
90
|
line: number;
|
|
@@ -39,28 +98,33 @@ export type GrepResult = {
|
|
|
39
98
|
stoppedEarly: boolean;
|
|
40
99
|
matches: LineMatch[];
|
|
41
100
|
};
|
|
101
|
+
export type GrepOptions = {
|
|
102
|
+
regex?: boolean;
|
|
103
|
+
caseSensitive?: boolean;
|
|
104
|
+
maxResults: number;
|
|
105
|
+
contextLines: number;
|
|
106
|
+
/** Regex mode only. Defaults to 3 seconds of scanning. */
|
|
107
|
+
timeLimitMs?: number;
|
|
108
|
+
};
|
|
42
109
|
/**
|
|
43
110
|
* A quick refusal for the most common catastrophic shape, a nested quantifier such as (a+)+.
|
|
44
111
|
* It does not catch every slow pattern; the time limit in `grep` is what bounds the search.
|
|
45
112
|
*/
|
|
46
113
|
export declare function unsafeRegexReason(pattern: string): string | null;
|
|
47
|
-
/** Lines that contain `query` (exact text) or match it (regex). */
|
|
48
|
-
export declare function grep(document: SearchableDocument, query: string, options:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
timeLimitMs?: number;
|
|
54
|
-
}): GrepResult;
|
|
114
|
+
/** Lines that contain `query` (exact text) or match it (regex), in a document held in memory. */
|
|
115
|
+
export declare function grep(document: SearchableDocument, query: string, options: GrepOptions): GrepResult;
|
|
116
|
+
/** `grep` over any document: one held in memory, or one read from the store a piece at a time. */
|
|
117
|
+
export declare function grepSource(source: DocumentSource, query: string, options: GrepOptions & {
|
|
118
|
+
signal?: AbortSignal;
|
|
119
|
+
}): Promise<GrepResult>;
|
|
55
120
|
export declare function queryTerms(query: string): string[];
|
|
56
121
|
export type RankedPassage = {
|
|
57
122
|
from: number;
|
|
58
123
|
to: number;
|
|
59
124
|
score: number;
|
|
60
125
|
};
|
|
61
|
-
/**
|
|
62
|
-
* BM25 over fixed passages, computed at query time from substring hits. No index to build or
|
|
63
|
-
* store, works for any language, and a term also matches longer words ("timeout" → "timeouts").
|
|
64
|
-
*/
|
|
126
|
+
/** BM25 passage ranking over a document held in memory. */
|
|
65
127
|
export declare function rankPassages(document: SearchableDocument, query: string, topK: number): RankedPassage[];
|
|
128
|
+
/** `rankPassages` over any document: one held in memory, or one read from the store a piece at a time. */
|
|
129
|
+
export declare function rankSource(source: DocumentSource, query: string, topK: number, signal?: AbortSignal): Promise<RankedPassage[]>;
|
|
66
130
|
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAc/D;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,4EAA4E;IAC5E,KAAK,IAAI,MAAM,CAAC;CACjB,CAAC;AAEF,uGAAuG;AACvG,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qDAAqD;IACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC1C,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,oGAAoG;IACpG,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC7C,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC3D,qDAAqD;IACrD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;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