@ontos-ai/knowhere-sdk 0.10.0 → 2.1.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/README.md CHANGED
@@ -23,7 +23,7 @@ npm install @ontos-ai/knowhere-sdk
23
23
 
24
24
  **Requirements:**
25
25
 
26
- - Node.js >= 20.19.0
26
+ - Node.js >= 22.13.0
27
27
  - npm >= 10.0.0
28
28
  - TypeScript >= 5.0 (optional, for type checking)
29
29
 
@@ -46,6 +46,7 @@ const result = await client.parse({
46
46
  console.log(`Found ${result.textChunks.length} text chunks`);
47
47
  console.log(`Found ${result.imageChunks.length} images`);
48
48
  console.log(`Found ${result.tableChunks.length} tables`);
49
+ console.log(`Found ${result.pageChunks.length} page chunks`);
49
50
 
50
51
  // Work with chunks — worker metadata is in chunk.metadata
51
52
  result.textChunks.forEach((chunk) => {
@@ -54,6 +55,12 @@ result.textChunks.forEach((chunk) => {
54
55
  console.log(chunk.metadata.summary);
55
56
  });
56
57
 
58
+ result.pageChunks.forEach((chunk) => {
59
+ console.log(chunk.contentSource); // "summary"
60
+ console.log(chunk.content); // page-level summary
61
+ console.log(chunk.metadata.pageNums); // citation pages
62
+ });
63
+
57
64
  // Save results to disk
58
65
  await result.save('./output/');
59
66
  ```
@@ -138,6 +145,53 @@ const result = await client.parse({
138
145
  });
139
146
  ```
140
147
 
148
+ ### Page Citation Assets
149
+
150
+ Page citation assets are generated by Knowhere during page-memory parsing. The
151
+ SDK does not render PDF pages locally; it preserves the page image descriptors
152
+ returned by the server on page chunks and retrieval metadata.
153
+
154
+ ```typescript
155
+ import Knowhere from '@ontos-ai/knowhere-sdk';
156
+
157
+ const client = new Knowhere({ apiKey: process.env.KNOWHERE_API_KEY });
158
+
159
+ const result = await client.parse({
160
+ file: './manual.pdf',
161
+ });
162
+
163
+ for (const chunk of result.pageChunks) {
164
+ console.log(chunk.metadata.pageAssets);
165
+ }
166
+ ```
167
+
168
+ `metadata.pageAssets` entries point at concrete page images stored with the Knowhere
169
+ result. `artifactRef` is the durable result artifact path; `assetUrl` is an
170
+ optional server-generated access URL.
171
+
172
+ ```typescript
173
+ type PageCitationAsset = {
174
+ pageNum: number;
175
+ artifactRef: string;
176
+ assetUrl?: string;
177
+ contentType: 'image/png' | 'image/jpeg';
178
+ width?: number;
179
+ height?: number;
180
+ source: 'knowhere-rendered-page-citation-source';
181
+ };
182
+ ```
183
+
184
+ Document chunk APIs can include signed page image URLs when requested:
185
+
186
+ ```typescript
187
+ const chunks = await client.documents.listChunks('doc_123', {
188
+ chunkType: 'page',
189
+ includeAssetUrls: true,
190
+ });
191
+
192
+ console.log(chunks.chunks[0]?.metadata.pageAssets?.[0]?.assetUrl);
193
+ ```
194
+
141
195
  ### Low-Level API
142
196
 
143
197
  For granular control over the job lifecycle:
@@ -200,6 +254,7 @@ console.log(documentId);
200
254
  const response = await client.retrieval.query({
201
255
  namespace: 'support-center',
202
256
  query: 'How do I reset Bluetooth pairing?',
257
+ chunkTypes: ['page'],
203
258
  topK: 5,
204
259
  useAgentic: true,
205
260
  });
@@ -212,7 +267,9 @@ console.log(response.failureReason); // no-answer reason, when returned
212
267
 
213
268
  for (const result of response.results) {
214
269
  console.log(result.content);
270
+ console.log(result.contentSource);
215
271
  console.log(result.score);
272
+ console.log(result.metadata?.pageNums);
216
273
  console.log(result.source.sourceFileName, result.source.sectionPath);
217
274
  }
218
275
  ```
@@ -221,9 +278,12 @@ Retrieval results use one canonical source object:
221
278
 
222
279
  ```typescript
223
280
  result.content;
281
+ result.chunkId;
224
282
  result.chunkType;
283
+ result.contentSource;
225
284
  result.score;
226
285
  result.assetUrl;
286
+ result.metadata;
227
287
  result.source.documentId;
228
288
  result.source.sourceFileName;
229
289
  result.source.sectionPath;
@@ -237,10 +297,12 @@ const reference = response.referencedChunks[0];
237
297
  reference.chunkId;
238
298
  reference.documentId;
239
299
  reference.chunkType;
300
+ reference.contentSource;
240
301
  reference.sectionPath;
241
302
  reference.filePath;
242
303
  reference.jobId;
243
304
  reference.assetUrl;
305
+ reference.metadata;
244
306
  ```
245
307
 
246
308
  Use `documentId` to update or archive a document:
@@ -261,7 +323,7 @@ const document = await client.documents.get(documentId);
261
323
  const chunks = await client.documents.listChunks(documentId, {
262
324
  page: 1,
263
325
  pageSize: 50,
264
- chunkType: 'image',
326
+ chunkType: 'page',
265
327
  includeAssetUrls: true,
266
328
  });
267
329
  const archived = await client.documents.archive(documentId);
@@ -275,6 +337,8 @@ if (chunks.chunks[0]) {
275
337
  includeAssetUrls: true,
276
338
  });
277
339
  console.log(chunk.chunk.content);
340
+ console.log(chunk.chunk.contentSource);
341
+ console.log(chunk.chunk.metadata.pageNums);
278
342
  console.log(chunk.chunk.assetUrl);
279
343
  }
280
344
  console.log(archived.status);
@@ -282,14 +346,18 @@ console.log(archived.status);
282
346
 
283
347
  ### Local Knowledge Tools
284
348
 
285
- The SDK can also keep parsed results in a local cache and run exact inspection
286
- tools over that cached copy. This is the implementation used by the separate
287
- `@ontos-ai/knowhere-mcp` package.
349
+ The SDK can also run exact inspection tools over parsed results. Local import
350
+ helpers still write under the SDK cache directory by design, while published
351
+ `documentId` reads use configured parsed storage first and fall back to
352
+ Knowhere's remote chunk API without importing the result ZIP into local disk.
353
+ Server workflows can configure parsed storage with
354
+ `client.knowledge.withParsedStorage(...)` so Notebook, MCP, and CLI surfaces
355
+ share the same snapshot model.
288
356
 
289
357
  ```typescript
290
- const parsed = await client.knowledge.parse({
358
+ const parsed = await client.knowledge.parseToLocalCache({
291
359
  file: './manual.pdf',
292
- localDocumentId: 'manual-v1',
360
+ localDocumentId: 'manual',
293
361
  });
294
362
 
295
363
  const outline = await client.knowledge.getDocumentOutline(parsed.document.localDocumentId);
@@ -317,29 +385,51 @@ console.log(grep.matches);
317
385
  console.log(serverSearch.references);
318
386
  ```
319
387
 
320
- Local grep and reads use the cached parse result, not server-side chunk scans.
321
- Search uses the Knowhere API retrieval query; local document IDs only help map
322
- returned server document IDs back to local cache IDs when available.
323
- If a search result only has a published `documentId`, or an async parse flow only
324
- has a completed `jobId`, read-oriented helpers can accept that remote identifier
325
- directly and will sync the result into the local cache before reading. For a
326
- `documentId`, the SDK resolves the document's current published `jobId` and then
327
- downloads the parser result ZIP through the same `cacheJobResult(...)` path:
388
+ Local grep and reads use the cached parse result. Published `documentId` grep
389
+ streams `documents.listChunks(...)` page by page when parsed storage is missing
390
+ or stale. Search uses the Knowhere API retrieval query; local document IDs only
391
+ help map returned server document IDs back to local cache IDs when available.
392
+ When `knowledge.parseToLocalCache(...)`, `knowledge.importJobResult(...)`, or
393
+ `knowledge.loadJobResult(...)` runs with configured parsed storage, the SDK
394
+ writes chunk pages, durable assets, sync progress, and a committed
395
+ `manifest/current.json` before returning. Partial snapshots are ignored until
396
+ the manifest is committed.
328
397
 
329
398
  ```typescript
330
- const remoteRead = await client.knowledge.readChunks({
399
+ const knowledge = client.knowledge.withParsedStorage({
400
+ storage: myParsedDocumentStorage,
401
+ scheduler: myBackgroundScheduler,
402
+ limits: { remotePageSize: 100, maxPagesPerSync: 10 },
403
+ });
404
+ ```
405
+
406
+ If a search result only has a published `documentId`, read-oriented helpers can
407
+ accept that remote identifier directly. `readChunks` supports display paging;
408
+ `assetUrlPolicy: 'durable'` hardens only returned assets through configured
409
+ storage and omits asset URLs if hardening fails:
410
+
411
+ ```typescript
412
+ const remoteRead = await knowledge.readChunks({
331
413
  documentId: 'doc_123',
332
- sectionPath: 'Overview',
333
- limit: 5,
414
+ page: 1,
415
+ pageSize: 20,
416
+ chunkType: 'page',
417
+ assetUrlPolicy: 'durable',
334
418
  });
335
419
 
336
- const remoteOutline = await client.knowledge.getDocumentOutline({
420
+ const remoteOutline = await knowledge.getDocumentOutline({
337
421
  documentId: 'doc_123',
338
422
  });
339
423
 
340
- const jobRead = await client.knowledge.readChunks({
424
+ const grep = await knowledge.grepChunks({
425
+ documentId: 'doc_123',
426
+ pattern: 'warranty',
427
+ maxResults: 10,
428
+ });
429
+
430
+ const jobRead = await knowledge.readChunks({
341
431
  jobId: jobResult.jobId,
342
- localDocumentId: 'manual-v1',
432
+ localDocumentId: 'manual',
343
433
  limit: 5,
344
434
  });
345
435
  ```
@@ -354,7 +444,7 @@ job completes:
354
444
  ```typescript
355
445
  const started = await client.knowledge.startParse({
356
446
  file: './manual.pdf',
357
- localDocumentId: 'manual-v1',
447
+ localDocumentId: 'manual',
358
448
  });
359
449
 
360
450
  const status = await client.knowledge.getJobStatus(started.job.jobId);
@@ -366,9 +456,13 @@ if (status.job.isDone && status.cache.document) {
366
456
 
367
457
  When the job was started through `client.knowledge.startParse(...)`,
368
458
  `getJobStatus(...)` automatically caches the completed result locally the first
369
- time it observes `status.job.isDone`. Use `cacheJobResult(...)` only to recover a
370
- completed job that was not started through the local knowledge helper, or to
371
- retry a cache step explicitly.
459
+ time it observes `status.job.isDone`. Use `importJobResult(...)` to recover a
460
+ completed job into the local cache when it was not started through the local
461
+ knowledge helper, or to retry a local import step explicitly. Use
462
+ `loadJobResult(...)` for server workflows that should load a completed result
463
+ without creating SDK local-disk cache state. Use `syncParsedDocument(...)` to
464
+ explicitly resume or retry parsed-storage sync for an existing `documentId`,
465
+ `jobId`, or local parsed result.
372
466
 
373
467
  Follow-up queries can exclude documents or sections for one request:
374
468