vectra 0.9.0 → 0.10.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/README.md +10 -10
- package/package.json +7 -6
- package/src/ItemSelector.ts +7 -1
- package/src/LocalDocumentIndex.ts +7 -1
- package/src/LocalDocumentResult.ts +70 -22
- package/src/LocalIndex.ts +70 -3
- package/src/internals/Colorize.ts +3 -3
- package/src/internals/wink-bm25-text-search.d.ts +4 -0
- package/src/types.ts +1 -0
- package/src/vectra-cli.ts +13 -2
- package/lib/FileFetcher.d.ts +0 -5
- package/lib/FileFetcher.d.ts.map +0 -1
- package/lib/FileFetcher.js +0 -69
- package/lib/FileFetcher.js.map +0 -1
- package/lib/GPT3Tokenizer.d.ts +0 -9
- package/lib/GPT3Tokenizer.d.ts.map +0 -1
- package/lib/GPT3Tokenizer.js +0 -17
- package/lib/GPT3Tokenizer.js.map +0 -1
- package/lib/ItemSelector.d.ts +0 -41
- package/lib/ItemSelector.d.ts.map +0 -1
- package/lib/ItemSelector.js +0 -162
- package/lib/ItemSelector.js.map +0 -1
- package/lib/LocalDocument.d.ts +0 -54
- package/lib/LocalDocument.d.ts.map +0 -1
- package/lib/LocalDocument.js +0 -146
- package/lib/LocalDocument.js.map +0 -1
- package/lib/LocalDocumentIndex.d.ts +0 -128
- package/lib/LocalDocumentIndex.d.ts.map +0 -1
- package/lib/LocalDocumentIndex.js +0 -446
- package/lib/LocalDocumentIndex.js.map +0 -1
- package/lib/LocalDocumentResult.d.ts +0 -45
- package/lib/LocalDocumentResult.d.ts.map +0 -1
- package/lib/LocalDocumentResult.js +0 -282
- package/lib/LocalDocumentResult.js.map +0 -1
- package/lib/LocalIndex.d.ts +0 -136
- package/lib/LocalIndex.d.ts.map +0 -1
- package/lib/LocalIndex.js +0 -413
- package/lib/LocalIndex.js.map +0 -1
- package/lib/OpenAIEmbeddings.d.ts +0 -126
- package/lib/OpenAIEmbeddings.d.ts.map +0 -1
- package/lib/OpenAIEmbeddings.js +0 -174
- package/lib/OpenAIEmbeddings.js.map +0 -1
- package/lib/TextSplitter.d.ts +0 -20
- package/lib/TextSplitter.d.ts.map +0 -1
- package/lib/TextSplitter.js +0 -537
- package/lib/TextSplitter.js.map +0 -1
- package/lib/WebFetcher.d.ts +0 -15
- package/lib/WebFetcher.d.ts.map +0 -1
- package/lib/WebFetcher.js +0 -224
- package/lib/WebFetcher.js.map +0 -1
- package/lib/index.d.ts +0 -12
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -28
- package/lib/index.js.map +0 -1
- package/lib/internals/Colorize.d.ts +0 -14
- package/lib/internals/Colorize.d.ts.map +0 -1
- package/lib/internals/Colorize.js +0 -64
- package/lib/internals/Colorize.js.map +0 -1
- package/lib/internals/index.d.ts +0 -3
- package/lib/internals/index.d.ts.map +0 -1
- package/lib/internals/index.js +0 -19
- package/lib/internals/index.js.map +0 -1
- package/lib/internals/types.d.ts +0 -43
- package/lib/internals/types.d.ts.map +0 -1
- package/lib/internals/types.js +0 -3
- package/lib/internals/types.js.map +0 -1
- package/lib/types.d.ts +0 -145
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/vectra-cli.d.ts +0 -2
- package/lib/vectra-cli.d.ts.map +0 -1
- package/lib/vectra-cli.js +0 -303
- package/lib/vectra-cli.js.map +0 -1
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.LocalDocumentIndex = void 0;
|
|
36
|
-
const fs = __importStar(require("fs/promises"));
|
|
37
|
-
const path = __importStar(require("path"));
|
|
38
|
-
const uuid_1 = require("uuid");
|
|
39
|
-
const GPT3Tokenizer_1 = require("./GPT3Tokenizer");
|
|
40
|
-
const LocalIndex_1 = require("./LocalIndex");
|
|
41
|
-
const TextSplitter_1 = require("./TextSplitter");
|
|
42
|
-
const LocalDocumentResult_1 = require("./LocalDocumentResult");
|
|
43
|
-
const LocalDocument_1 = require("./LocalDocument");
|
|
44
|
-
/**
|
|
45
|
-
* Represents a local index of documents stored on disk.
|
|
46
|
-
*/
|
|
47
|
-
class LocalDocumentIndex extends LocalIndex_1.LocalIndex {
|
|
48
|
-
/**
|
|
49
|
-
* Creates a new `LocalDocumentIndex` instance.
|
|
50
|
-
* @param config Configuration settings for the document index.
|
|
51
|
-
*/
|
|
52
|
-
constructor(config) {
|
|
53
|
-
var _a, _b;
|
|
54
|
-
super(config.folderPath);
|
|
55
|
-
this._embeddings = config.embeddings;
|
|
56
|
-
this._chunkingConfig = Object.assign({
|
|
57
|
-
keepSeparators: true,
|
|
58
|
-
chunkSize: 512,
|
|
59
|
-
chunkOverlap: 0,
|
|
60
|
-
}, config.chunkingConfig);
|
|
61
|
-
this._tokenizer = (_b = (_a = config.tokenizer) !== null && _a !== void 0 ? _a : this._chunkingConfig.tokenizer) !== null && _b !== void 0 ? _b : new GPT3Tokenizer_1.GPT3Tokenizer();
|
|
62
|
-
this._chunkingConfig.tokenizer = this._tokenizer;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns the embeddings model used by the index (if configured.)
|
|
66
|
-
*/
|
|
67
|
-
get embeddings() {
|
|
68
|
-
return this._embeddings;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Returns the tokenizer used by the index.
|
|
72
|
-
*/
|
|
73
|
-
get tokenizer() {
|
|
74
|
-
return this._tokenizer;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns true if the document catalog exists.
|
|
78
|
-
*/
|
|
79
|
-
isCatalogCreated() {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
try {
|
|
82
|
-
yield fs.access(path.join(this.folderPath, 'catalog.json'));
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Returns the document ID for the given URI.
|
|
92
|
-
* @param uri URI of the document to lookup.
|
|
93
|
-
* @returns Document ID or undefined if not found.
|
|
94
|
-
*/
|
|
95
|
-
getDocumentId(uri) {
|
|
96
|
-
var _a;
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
yield this.loadIndexData();
|
|
99
|
-
return (_a = this._catalog) === null || _a === void 0 ? void 0 : _a.uriToId[uri];
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns the document URI for the given ID.
|
|
104
|
-
* @param documentId ID of the document to lookup.
|
|
105
|
-
* @returns Document URI or undefined if not found.
|
|
106
|
-
*/
|
|
107
|
-
getDocumentUri(documentId) {
|
|
108
|
-
var _a;
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
yield this.loadIndexData();
|
|
111
|
-
return (_a = this._catalog) === null || _a === void 0 ? void 0 : _a.idToUri[documentId];
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Loads the document catalog from disk and returns its stats.
|
|
116
|
-
* @returns Catalog stats.
|
|
117
|
-
*/
|
|
118
|
-
getCatalogStats() {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
const stats = yield this.getIndexStats();
|
|
121
|
-
return {
|
|
122
|
-
version: this._catalog.version,
|
|
123
|
-
documents: this._catalog.count,
|
|
124
|
-
chunks: stats.items,
|
|
125
|
-
metadata_config: stats.metadata_config
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Deletes a document from the index.
|
|
131
|
-
* @param uri URI of the document to delete.
|
|
132
|
-
*/
|
|
133
|
-
deleteDocument(uri) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
// Lookup document ID
|
|
136
|
-
const documentId = yield this.getDocumentId(uri);
|
|
137
|
-
if (documentId == undefined) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// Delete document chunks from index and remove from catalog
|
|
141
|
-
yield this.beginUpdate();
|
|
142
|
-
try {
|
|
143
|
-
// Get list of chunks for document
|
|
144
|
-
const chunks = yield this.listItemsByMetadata({ documentId });
|
|
145
|
-
// Delete chunks
|
|
146
|
-
for (const chunk of chunks) {
|
|
147
|
-
yield this.deleteItem(chunk.id);
|
|
148
|
-
}
|
|
149
|
-
// Remove entry from catalog
|
|
150
|
-
delete this._newCatalog.uriToId[uri];
|
|
151
|
-
delete this._newCatalog.idToUri[documentId];
|
|
152
|
-
this._newCatalog.count--;
|
|
153
|
-
// Commit changes
|
|
154
|
-
yield this.endUpdate();
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
// Cancel update and raise error
|
|
158
|
-
this.cancelUpdate();
|
|
159
|
-
throw new Error(`Error deleting document "${uri}": ${err.toString()}`);
|
|
160
|
-
}
|
|
161
|
-
// Delete text file from disk
|
|
162
|
-
try {
|
|
163
|
-
yield fs.unlink(path.join(this.folderPath, `${documentId}.txt`));
|
|
164
|
-
}
|
|
165
|
-
catch (err) {
|
|
166
|
-
throw new Error(`Error removing text file for document "${uri}" from disk: ${err.toString()}`);
|
|
167
|
-
}
|
|
168
|
-
// Delete metadata file from disk
|
|
169
|
-
try {
|
|
170
|
-
yield fs.unlink(path.join(this.folderPath, `${documentId}.json`));
|
|
171
|
-
}
|
|
172
|
-
catch (err) {
|
|
173
|
-
// Ignore error
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Adds a document to the catalog.
|
|
179
|
-
* @remarks
|
|
180
|
-
* A new update is started if one is not already in progress. If an document with the same uri
|
|
181
|
-
* already exists, it will be replaced.
|
|
182
|
-
* @param uri - Document URI
|
|
183
|
-
* @param text - Document text
|
|
184
|
-
* @param docType - Optional. Document type
|
|
185
|
-
* @param metadata - Optional. Document metadata to index
|
|
186
|
-
* @returns Inserted document
|
|
187
|
-
*/
|
|
188
|
-
upsertDocument(uri, text, docType, metadata) {
|
|
189
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
// Ensure embeddings configured
|
|
191
|
-
if (!this._embeddings) {
|
|
192
|
-
throw new Error(`Embeddings model not configured.`);
|
|
193
|
-
}
|
|
194
|
-
// Check for existing document ID
|
|
195
|
-
let documentId = yield this.getDocumentId(uri);
|
|
196
|
-
if (documentId != undefined) {
|
|
197
|
-
// Delete existing document
|
|
198
|
-
yield this.deleteDocument(uri);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// Generate new document ID
|
|
202
|
-
documentId = (0, uuid_1.v4)();
|
|
203
|
-
}
|
|
204
|
-
// Initialize text splitter settings
|
|
205
|
-
const config = Object.assign({ docType }, this._chunkingConfig);
|
|
206
|
-
if (config.docType == undefined) {
|
|
207
|
-
// Populate docType based on extension
|
|
208
|
-
const pos = uri.lastIndexOf('.');
|
|
209
|
-
if (pos >= 0) {
|
|
210
|
-
const ext = uri.substring(pos + 1).toLowerCase();
|
|
211
|
-
config.docType = ext;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
// Split text into chunks
|
|
215
|
-
const splitter = new TextSplitter_1.TextSplitter(config);
|
|
216
|
-
const chunks = splitter.split(text);
|
|
217
|
-
// Break chunks into batches for embedding generation
|
|
218
|
-
let totalTokens = 0;
|
|
219
|
-
const chunkBatches = [];
|
|
220
|
-
let currentBatch = [];
|
|
221
|
-
for (const chunk of chunks) {
|
|
222
|
-
totalTokens += chunk.tokens.length;
|
|
223
|
-
if (totalTokens > this._embeddings.maxTokens) {
|
|
224
|
-
chunkBatches.push(currentBatch);
|
|
225
|
-
currentBatch = [];
|
|
226
|
-
totalTokens = chunk.tokens.length;
|
|
227
|
-
}
|
|
228
|
-
currentBatch.push(chunk.text.replace(/\n/g, ' '));
|
|
229
|
-
}
|
|
230
|
-
if (currentBatch.length > 0) {
|
|
231
|
-
chunkBatches.push(currentBatch);
|
|
232
|
-
}
|
|
233
|
-
// Generate embeddings for chunks
|
|
234
|
-
const embeddings = [];
|
|
235
|
-
for (const batch of chunkBatches) {
|
|
236
|
-
let response;
|
|
237
|
-
try {
|
|
238
|
-
response = yield this._embeddings.createEmbeddings(batch);
|
|
239
|
-
}
|
|
240
|
-
catch (err) {
|
|
241
|
-
throw new Error(`Error generating embeddings: ${err.toString()}`);
|
|
242
|
-
}
|
|
243
|
-
// Check for error
|
|
244
|
-
if (response.status != 'success') {
|
|
245
|
-
throw new Error(`Error generating embeddings: ${response.message}`);
|
|
246
|
-
}
|
|
247
|
-
// Add embeddings to output
|
|
248
|
-
for (const embedding of response.output) {
|
|
249
|
-
embeddings.push(embedding);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// Add document chunks to index
|
|
253
|
-
yield this.beginUpdate();
|
|
254
|
-
try {
|
|
255
|
-
// Add chunks to index
|
|
256
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
257
|
-
const chunk = chunks[i];
|
|
258
|
-
const embedding = embeddings[i];
|
|
259
|
-
const chunkMetadata = Object.assign({
|
|
260
|
-
documentId,
|
|
261
|
-
startPos: chunk.startPos,
|
|
262
|
-
endPos: chunk.endPos,
|
|
263
|
-
}, metadata);
|
|
264
|
-
yield this.insertItem({
|
|
265
|
-
id: (0, uuid_1.v4)(),
|
|
266
|
-
metadata: chunkMetadata,
|
|
267
|
-
vector: embedding,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
// Save metadata file to disk
|
|
271
|
-
if (metadata != undefined) {
|
|
272
|
-
yield fs.writeFile(path.join(this.folderPath, `${documentId}.json`), JSON.stringify(metadata));
|
|
273
|
-
}
|
|
274
|
-
// Save text file to disk
|
|
275
|
-
yield fs.writeFile(path.join(this.folderPath, `${documentId}.txt`), text);
|
|
276
|
-
// Add entry to catalog
|
|
277
|
-
this._newCatalog.uriToId[uri] = documentId;
|
|
278
|
-
this._newCatalog.idToUri[documentId] = uri;
|
|
279
|
-
this._newCatalog.count++;
|
|
280
|
-
// Commit changes
|
|
281
|
-
yield this.endUpdate();
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
// Cancel update and raise error
|
|
285
|
-
this.cancelUpdate();
|
|
286
|
-
throw new Error(`Error adding document "${uri}": ${err.toString()}`);
|
|
287
|
-
}
|
|
288
|
-
// Return document
|
|
289
|
-
return new LocalDocument_1.LocalDocument(this, documentId, uri);
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Returns all documents in the index.
|
|
294
|
-
* @remarks
|
|
295
|
-
* Each document will contain all of the documents indexed chunks.
|
|
296
|
-
* @returns Array of documents.
|
|
297
|
-
*/
|
|
298
|
-
listDocuments() {
|
|
299
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
-
// Sort chunks by document ID
|
|
301
|
-
const docs = {};
|
|
302
|
-
const chunks = yield this.listItems();
|
|
303
|
-
chunks.forEach(chunk => {
|
|
304
|
-
const metadata = chunk.metadata;
|
|
305
|
-
if (docs[metadata.documentId] == undefined) {
|
|
306
|
-
docs[metadata.documentId] = [];
|
|
307
|
-
}
|
|
308
|
-
docs[metadata.documentId].push({ item: chunk, score: 1.0 });
|
|
309
|
-
});
|
|
310
|
-
// Create document results
|
|
311
|
-
const results = [];
|
|
312
|
-
for (const documentId in docs) {
|
|
313
|
-
const uri = yield this.getDocumentUri(documentId);
|
|
314
|
-
const documentResult = new LocalDocumentResult_1.LocalDocumentResult(this, documentId, uri, docs[documentId], this._tokenizer);
|
|
315
|
-
results.push(documentResult);
|
|
316
|
-
}
|
|
317
|
-
return results;
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Queries the index for documents similar to the given query.
|
|
322
|
-
* @param query Text to query for.
|
|
323
|
-
* @param options Optional. Query options.
|
|
324
|
-
* @returns Array of document results.
|
|
325
|
-
*/
|
|
326
|
-
queryDocuments(query, options) {
|
|
327
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
-
// Ensure embeddings configured
|
|
329
|
-
if (!this._embeddings) {
|
|
330
|
-
throw new Error(`Embeddings model not configured.`);
|
|
331
|
-
}
|
|
332
|
-
// Ensure options are defined
|
|
333
|
-
options = Object.assign({
|
|
334
|
-
maxDocuments: 10,
|
|
335
|
-
maxChunks: 50,
|
|
336
|
-
}, options);
|
|
337
|
-
// Generate embeddings for query
|
|
338
|
-
let embeddings;
|
|
339
|
-
try {
|
|
340
|
-
embeddings = yield this._embeddings.createEmbeddings(query.replace(/\n/g, ' '));
|
|
341
|
-
}
|
|
342
|
-
catch (err) {
|
|
343
|
-
throw new Error(`Error generating embeddings for query: ${err.toString()}`);
|
|
344
|
-
}
|
|
345
|
-
// Check for error
|
|
346
|
-
if (embeddings.status != 'success') {
|
|
347
|
-
throw new Error(`Error generating embeddings for query: ${embeddings.message}`);
|
|
348
|
-
}
|
|
349
|
-
// Query index for chunks
|
|
350
|
-
const results = yield this.queryItems(embeddings.output[0], options.maxChunks, options.filter);
|
|
351
|
-
// Group chunks by document
|
|
352
|
-
const documentChunks = {};
|
|
353
|
-
for (const result of results) {
|
|
354
|
-
const metadata = result.item.metadata;
|
|
355
|
-
if (documentChunks[metadata.documentId] == undefined) {
|
|
356
|
-
documentChunks[metadata.documentId] = [];
|
|
357
|
-
}
|
|
358
|
-
documentChunks[metadata.documentId].push(result);
|
|
359
|
-
}
|
|
360
|
-
// Create a document result for each document
|
|
361
|
-
const documentResults = [];
|
|
362
|
-
for (const documentId in documentChunks) {
|
|
363
|
-
const chunks = documentChunks[documentId];
|
|
364
|
-
const uri = yield this.getDocumentUri(documentId);
|
|
365
|
-
const documentResult = new LocalDocumentResult_1.LocalDocumentResult(this, documentId, uri, chunks, this._tokenizer);
|
|
366
|
-
documentResults.push(documentResult);
|
|
367
|
-
}
|
|
368
|
-
// Sort document results by score and return top results
|
|
369
|
-
return documentResults.sort((a, b) => b.score - a.score).slice(0, options.maxDocuments);
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
// Overrides
|
|
373
|
-
beginUpdate() {
|
|
374
|
-
const _super = Object.create(null, {
|
|
375
|
-
beginUpdate: { get: () => super.beginUpdate }
|
|
376
|
-
});
|
|
377
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
378
|
-
yield _super.beginUpdate.call(this);
|
|
379
|
-
this._newCatalog = Object.assign({}, this._catalog);
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
cancelUpdate() {
|
|
383
|
-
super.cancelUpdate();
|
|
384
|
-
this._newCatalog = undefined;
|
|
385
|
-
}
|
|
386
|
-
createIndex(config) {
|
|
387
|
-
const _super = Object.create(null, {
|
|
388
|
-
createIndex: { get: () => super.createIndex }
|
|
389
|
-
});
|
|
390
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
391
|
-
yield _super.createIndex.call(this, config);
|
|
392
|
-
yield this.loadIndexData();
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
endUpdate() {
|
|
396
|
-
const _super = Object.create(null, {
|
|
397
|
-
endUpdate: { get: () => super.endUpdate }
|
|
398
|
-
});
|
|
399
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
-
yield _super.endUpdate.call(this);
|
|
401
|
-
try {
|
|
402
|
-
// Save catalog
|
|
403
|
-
yield fs.writeFile(path.join(this.folderPath, 'catalog.json'), JSON.stringify(this._newCatalog));
|
|
404
|
-
this._catalog = this._newCatalog;
|
|
405
|
-
this._newCatalog = undefined;
|
|
406
|
-
}
|
|
407
|
-
catch (err) {
|
|
408
|
-
throw new Error(`Error saving document catalog: ${err.toString()}`);
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
loadIndexData() {
|
|
413
|
-
const _super = Object.create(null, {
|
|
414
|
-
loadIndexData: { get: () => super.loadIndexData }
|
|
415
|
-
});
|
|
416
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
417
|
-
yield _super.loadIndexData.call(this);
|
|
418
|
-
if (this._catalog) {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
const catalogPath = path.join(this.folderPath, 'catalog.json');
|
|
422
|
-
if (yield this.isCatalogCreated()) {
|
|
423
|
-
// Load catalog
|
|
424
|
-
const buffer = yield fs.readFile(catalogPath);
|
|
425
|
-
this._catalog = JSON.parse(buffer.toString());
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
try {
|
|
429
|
-
// Initialize catalog
|
|
430
|
-
this._catalog = {
|
|
431
|
-
version: 1,
|
|
432
|
-
count: 0,
|
|
433
|
-
uriToId: {},
|
|
434
|
-
idToUri: {},
|
|
435
|
-
};
|
|
436
|
-
yield fs.writeFile(catalogPath, JSON.stringify(this._catalog));
|
|
437
|
-
}
|
|
438
|
-
catch (err) {
|
|
439
|
-
throw new Error(`Error creating document catalog: ${err.toString()}`);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
exports.LocalDocumentIndex = LocalDocumentIndex;
|
|
446
|
-
//# sourceMappingURL=LocalDocumentIndex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalDocumentIndex.js","sourceRoot":"","sources":["../src/LocalDocumentIndex.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,2CAA6B;AAC7B,+BAA0B;AAC1B,mDAAgD;AAChD,6CAA6D;AAC7D,iDAAkE;AAElE,+DAA4D;AAC5D,mDAAgD;AAmDhD;;GAEG;AACH,MAAa,kBAAmB,SAAQ,uBAAiC;IAOrE;;;OAGG;IACH,YAAmB,MAAgC;;QAC/C,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;YACjC,cAAc,EAAE,IAAI;YACpB,SAA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AC,CAAC,CAAC;iBAClE;gBAAC,OAAM,GAAY,EAAE;oBAClB,MAAM,IAAI,KAAK,CAAC,oCAAqC,GAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;iBAClF;aACJ;QACL,CAAC;KAAA;CACJ;AAhZD,gDAgZC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { LocalDocument } from "./LocalDocument";
|
|
2
|
-
import { LocalDocumentIndex } from "./LocalDocumentIndex";
|
|
3
|
-
import { QueryResult, DocumentChunkMetadata, Tokenizer, DocumentTextSection } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* Represents a search result for a document stored on disk.
|
|
6
|
-
*/
|
|
7
|
-
export declare class LocalDocumentResult extends LocalDocument {
|
|
8
|
-
private readonly _chunks;
|
|
9
|
-
private readonly _tokenizer;
|
|
10
|
-
private readonly _score;
|
|
11
|
-
/**
|
|
12
|
-
* @private
|
|
13
|
-
* Internal constructor for `LocalDocumentResult` instances.
|
|
14
|
-
*/
|
|
15
|
-
constructor(index: LocalDocumentIndex, id: string, uri: string, chunks: QueryResult<DocumentChunkMetadata>[], tokenizer: Tokenizer);
|
|
16
|
-
/**
|
|
17
|
-
* Returns the chunks of the document that matched the query.
|
|
18
|
-
*/
|
|
19
|
-
get chunks(): QueryResult<DocumentChunkMetadata>[];
|
|
20
|
-
/**
|
|
21
|
-
* Returns the average score of the document result.
|
|
22
|
-
*/
|
|
23
|
-
get score(): number;
|
|
24
|
-
/**
|
|
25
|
-
* Renders all of the results chunks as spans of text (sections.)
|
|
26
|
-
* @remarks
|
|
27
|
-
* The returned sections will be sorted by document order and limited to maxTokens in length.
|
|
28
|
-
* @param maxTokens Maximum number of tokens per section.
|
|
29
|
-
* @returns Array of rendered text sections.
|
|
30
|
-
*/
|
|
31
|
-
renderAllSections(maxTokens: number): Promise<DocumentTextSection[]>;
|
|
32
|
-
/**
|
|
33
|
-
* Renders the top spans of text (sections) of the document based on the query result.
|
|
34
|
-
* @remarks
|
|
35
|
-
* The returned sections will be sorted by relevance and limited to the top `maxSections`.
|
|
36
|
-
* @param maxTokens Maximum number of tokens per section.
|
|
37
|
-
* @param maxSections Maximum number of sections to return.
|
|
38
|
-
* @param overlappingChunks Optional. If true, overlapping chunks of text will be added to each section until the maxTokens is reached.
|
|
39
|
-
* @returns Array of rendered text sections.
|
|
40
|
-
*/
|
|
41
|
-
renderSections(maxTokens: number, maxSections: number, overlappingChunks?: boolean): Promise<DocumentTextSection[]>;
|
|
42
|
-
private encodeBeforeText;
|
|
43
|
-
private encodeAfterText;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=LocalDocumentResult.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalDocumentResult.d.ts","sourceRoot":"","sources":["../src/LocalDocumentResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE7F;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;OAGG;gBACgB,KAAK,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,qBAAqB,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS;IAWzI;;OAEG;IACH,IAAW,MAAM,IAAI,WAAW,CAAC,qBAAqB,CAAC,EAAE,CAExD;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED;;;;;;OAMG;IACU,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IA8DjF;;;;;;;;OAQG;IACU,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,UAAO,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAmK7H,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,eAAe;CAM1B"}
|