@ontos-ai/knowhere-sdk 2.0.0 → 2.1.2

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
 
@@ -145,6 +145,53 @@ const result = await client.parse({
145
145
  });
146
146
  ```
147
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
+
148
195
  ### Low-Level API
149
196
 
150
197
  For granular control over the job lifecycle:
@@ -299,12 +346,16 @@ console.log(archived.status);
299
346
 
300
347
  ### Local Knowledge Tools
301
348
 
302
- The SDK can also keep parsed results in a local cache and run exact inspection
303
- tools over that cached copy. This is the implementation used by the separate
304
- `@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 committed result-layout model.
305
356
 
306
357
  ```typescript
307
- const parsed = await client.knowledge.parse({
358
+ const parsed = await client.knowledge.parseToLocalCache({
308
359
  file: './manual.pdf',
309
360
  localDocumentId: 'manual',
310
361
  });
@@ -334,27 +385,49 @@ console.log(grep.matches);
334
385
  console.log(serverSearch.references);
335
386
  ```
336
387
 
337
- Local grep and reads use the cached parse result, not server-side chunk scans.
338
- Search uses the Knowhere API retrieval query; local document IDs only help map
339
- returned server document IDs back to local cache IDs when available.
340
- If a search result only has a published `documentId`, or an async parse flow only
341
- has a completed `jobId`, read-oriented helpers can accept that remote identifier
342
- directly and will sync the result into the local cache before reading. For a
343
- `documentId`, the SDK resolves the document's current published `jobId` and then
344
- 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 the expanded Knowhere result layout (`manifest.json`, `chunks.json`,
395
+ sidecars, and assets), sync progress, and a final `.knowhere-sdk/commit.json`
396
+ before returning. Partial storage writes are ignored until the commit marker is
397
+ present.
345
398
 
346
399
  ```typescript
347
- const remoteRead = await client.knowledge.readChunks({
400
+ const knowledge = client.knowledge.withParsedStorage({
401
+ storage: myParsedDocumentStorage,
402
+ scheduler: myBackgroundScheduler,
403
+ limits: { remotePageSize: 100, maxPagesPerSync: 10 },
404
+ });
405
+ ```
406
+
407
+ If a search result only has a published `documentId`, read-oriented helpers can
408
+ accept that remote identifier directly. `readChunks` supports display paging;
409
+ remote fallback requests asset URLs from the Knowhere API, and storage hits use
410
+ stored object URLs when the configured storage can resolve them:
411
+
412
+ ```typescript
413
+ const remoteRead = await knowledge.readChunks({
348
414
  documentId: 'doc_123',
349
- sectionPath: 'Overview',
350
- limit: 5,
415
+ page: 1,
416
+ pageSize: 20,
417
+ chunkType: 'page',
351
418
  });
352
419
 
353
- const remoteOutline = await client.knowledge.getDocumentOutline({
420
+ const remoteOutline = await knowledge.getDocumentOutline({
354
421
  documentId: 'doc_123',
355
422
  });
356
423
 
357
- 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({
358
431
  jobId: jobResult.jobId,
359
432
  localDocumentId: 'manual',
360
433
  limit: 5,
@@ -383,9 +456,13 @@ if (status.job.isDone && status.cache.document) {
383
456
 
384
457
  When the job was started through `client.knowledge.startParse(...)`,
385
458
  `getJobStatus(...)` automatically caches the completed result locally the first
386
- time it observes `status.job.isDone`. Use `cacheJobResult(...)` only to recover a
387
- completed job that was not started through the local knowledge helper, or to
388
- 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.
389
466
 
390
467
  Follow-up queries can exclude documents or sections for one request:
391
468