@ontos-ai/knowhere-sdk 0.9.0 → 2.0.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 +29 -5
- package/dist/index.d.mts +87 -21
- package/dist/index.d.ts +87 -21
- package/dist/index.js +104 -21
- package/dist/index.mjs +104 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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
|
```
|
|
@@ -200,6 +207,7 @@ console.log(documentId);
|
|
|
200
207
|
const response = await client.retrieval.query({
|
|
201
208
|
namespace: 'support-center',
|
|
202
209
|
query: 'How do I reset Bluetooth pairing?',
|
|
210
|
+
chunkTypes: ['page'],
|
|
203
211
|
topK: 5,
|
|
204
212
|
useAgentic: true,
|
|
205
213
|
});
|
|
@@ -212,7 +220,9 @@ console.log(response.failureReason); // no-answer reason, when returned
|
|
|
212
220
|
|
|
213
221
|
for (const result of response.results) {
|
|
214
222
|
console.log(result.content);
|
|
223
|
+
console.log(result.contentSource);
|
|
215
224
|
console.log(result.score);
|
|
225
|
+
console.log(result.metadata?.pageNums);
|
|
216
226
|
console.log(result.source.sourceFileName, result.source.sectionPath);
|
|
217
227
|
}
|
|
218
228
|
```
|
|
@@ -221,9 +231,12 @@ Retrieval results use one canonical source object:
|
|
|
221
231
|
|
|
222
232
|
```typescript
|
|
223
233
|
result.content;
|
|
234
|
+
result.chunkId;
|
|
224
235
|
result.chunkType;
|
|
236
|
+
result.contentSource;
|
|
225
237
|
result.score;
|
|
226
238
|
result.assetUrl;
|
|
239
|
+
result.metadata;
|
|
227
240
|
result.source.documentId;
|
|
228
241
|
result.source.sourceFileName;
|
|
229
242
|
result.source.sectionPath;
|
|
@@ -237,10 +250,12 @@ const reference = response.referencedChunks[0];
|
|
|
237
250
|
reference.chunkId;
|
|
238
251
|
reference.documentId;
|
|
239
252
|
reference.chunkType;
|
|
253
|
+
reference.contentSource;
|
|
240
254
|
reference.sectionPath;
|
|
241
255
|
reference.filePath;
|
|
242
256
|
reference.jobId;
|
|
243
257
|
reference.assetUrl;
|
|
258
|
+
reference.metadata;
|
|
244
259
|
```
|
|
245
260
|
|
|
246
261
|
Use `documentId` to update or archive a document:
|
|
@@ -252,16 +267,22 @@ const updateJob = await client.jobs.create({
|
|
|
252
267
|
documentId,
|
|
253
268
|
});
|
|
254
269
|
|
|
255
|
-
const documents = await client.documents.list({
|
|
270
|
+
const documents = await client.documents.list({
|
|
271
|
+
namespace: 'support-center',
|
|
272
|
+
page: 1,
|
|
273
|
+
pageSize: 50,
|
|
274
|
+
});
|
|
256
275
|
const document = await client.documents.get(documentId);
|
|
257
276
|
const chunks = await client.documents.listChunks(documentId, {
|
|
258
277
|
page: 1,
|
|
259
278
|
pageSize: 50,
|
|
260
|
-
chunkType: '
|
|
279
|
+
chunkType: 'page',
|
|
280
|
+
includeAssetUrls: true,
|
|
261
281
|
});
|
|
262
282
|
const archived = await client.documents.archive(documentId);
|
|
263
283
|
|
|
264
284
|
console.log(documents.documents.length);
|
|
285
|
+
console.log(documents.pagination.totalPages);
|
|
265
286
|
console.log(document.status);
|
|
266
287
|
console.log(chunks.pagination.total);
|
|
267
288
|
if (chunks.chunks[0]) {
|
|
@@ -269,6 +290,9 @@ if (chunks.chunks[0]) {
|
|
|
269
290
|
includeAssetUrls: true,
|
|
270
291
|
});
|
|
271
292
|
console.log(chunk.chunk.content);
|
|
293
|
+
console.log(chunk.chunk.contentSource);
|
|
294
|
+
console.log(chunk.chunk.metadata.pageNums);
|
|
295
|
+
console.log(chunk.chunk.assetUrl);
|
|
272
296
|
}
|
|
273
297
|
console.log(archived.status);
|
|
274
298
|
```
|
|
@@ -282,7 +306,7 @@ tools over that cached copy. This is the implementation used by the separate
|
|
|
282
306
|
```typescript
|
|
283
307
|
const parsed = await client.knowledge.parse({
|
|
284
308
|
file: './manual.pdf',
|
|
285
|
-
localDocumentId: 'manual
|
|
309
|
+
localDocumentId: 'manual',
|
|
286
310
|
});
|
|
287
311
|
|
|
288
312
|
const outline = await client.knowledge.getDocumentOutline(parsed.document.localDocumentId);
|
|
@@ -332,7 +356,7 @@ const remoteOutline = await client.knowledge.getDocumentOutline({
|
|
|
332
356
|
|
|
333
357
|
const jobRead = await client.knowledge.readChunks({
|
|
334
358
|
jobId: jobResult.jobId,
|
|
335
|
-
localDocumentId: 'manual
|
|
359
|
+
localDocumentId: 'manual',
|
|
336
360
|
limit: 5,
|
|
337
361
|
});
|
|
338
362
|
```
|
|
@@ -347,7 +371,7 @@ job completes:
|
|
|
347
371
|
```typescript
|
|
348
372
|
const started = await client.knowledge.startParse({
|
|
349
373
|
file: './manual.pdf',
|
|
350
|
-
localDocumentId: 'manual
|
|
374
|
+
localDocumentId: 'manual',
|
|
351
375
|
});
|
|
352
376
|
|
|
353
377
|
const status = await client.knowledge.getJobStatus(started.job.jobId);
|
package/dist/index.d.mts
CHANGED
|
@@ -300,6 +300,8 @@ interface Statistics {
|
|
|
300
300
|
imageChunks: number;
|
|
301
301
|
/** Number of table chunks */
|
|
302
302
|
tableChunks: number;
|
|
303
|
+
/** Number of page chunks */
|
|
304
|
+
pageChunks?: number;
|
|
303
305
|
/** Total number of pages (if applicable) */
|
|
304
306
|
totalPages?: number;
|
|
305
307
|
}
|
|
@@ -417,6 +419,7 @@ interface DocNav {
|
|
|
417
419
|
interface ChunkMetadata {
|
|
418
420
|
length?: number;
|
|
419
421
|
pageNums?: number[];
|
|
422
|
+
entities?: Record<string, unknown>[];
|
|
420
423
|
tokens?: string[];
|
|
421
424
|
keywords?: string[];
|
|
422
425
|
summary?: string;
|
|
@@ -435,7 +438,9 @@ interface BaseChunk {
|
|
|
435
438
|
/** Unique chunk identifier */
|
|
436
439
|
chunkId: string;
|
|
437
440
|
/** Chunk type */
|
|
438
|
-
type: 'text' | 'image' | 'table';
|
|
441
|
+
type: 'text' | 'image' | 'table' | 'page';
|
|
442
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
443
|
+
contentSource?: string;
|
|
439
444
|
/** Main content */
|
|
440
445
|
content: string;
|
|
441
446
|
/** Relative path in ZIP */
|
|
@@ -447,7 +452,7 @@ interface BaseChunk {
|
|
|
447
452
|
* Minimal chunk representation emitted in chunks_slim.json (legacy).
|
|
448
453
|
*/
|
|
449
454
|
interface SlimChunk {
|
|
450
|
-
type: 'text' | 'image' | 'table';
|
|
455
|
+
type: 'text' | 'image' | 'table' | 'page';
|
|
451
456
|
path: string;
|
|
452
457
|
content: string;
|
|
453
458
|
}
|
|
@@ -483,10 +488,16 @@ interface TableChunk extends BaseChunk {
|
|
|
483
488
|
/** Save table HTML to disk */
|
|
484
489
|
save(directory: string): Promise<string>;
|
|
485
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Page chunk
|
|
493
|
+
*/
|
|
494
|
+
interface PageChunk extends BaseChunk {
|
|
495
|
+
type: 'page';
|
|
496
|
+
}
|
|
486
497
|
/**
|
|
487
498
|
* Union type of all chunk types
|
|
488
499
|
*/
|
|
489
|
-
type Chunk = TextChunk | ImageChunk | TableChunk;
|
|
500
|
+
type Chunk = TextChunk | ImageChunk | TableChunk | PageChunk;
|
|
490
501
|
/**
|
|
491
502
|
* Complete parse result
|
|
492
503
|
*/
|
|
@@ -517,6 +528,8 @@ interface ParseResult {
|
|
|
517
528
|
readonly imageChunks: ImageChunk[];
|
|
518
529
|
/** Table chunks only */
|
|
519
530
|
readonly tableChunks: TableChunk[];
|
|
531
|
+
/** Page chunks only */
|
|
532
|
+
readonly pageChunks: PageChunk[];
|
|
520
533
|
/** Job ID */
|
|
521
534
|
readonly jobId: string;
|
|
522
535
|
/** Effective retrieval namespace when loaded from a job result */
|
|
@@ -602,6 +615,7 @@ declare class HttpClient {
|
|
|
602
615
|
declare abstract class BaseResource {
|
|
603
616
|
protected httpClient: HttpClient;
|
|
604
617
|
constructor(httpClient: HttpClient);
|
|
618
|
+
protected endpoint(path: string): string;
|
|
605
619
|
}
|
|
606
620
|
|
|
607
621
|
/**
|
|
@@ -651,6 +665,7 @@ type RetrievalChannel = 'path' | 'content' | 'term';
|
|
|
651
665
|
* Path filtering mode for retrieval queries.
|
|
652
666
|
*/
|
|
653
667
|
type RetrievalFilterMode = 'delete' | 'keep';
|
|
668
|
+
type RetrievalChunkType = 'text' | 'image' | 'table' | 'page';
|
|
654
669
|
/**
|
|
655
670
|
* Retrieval query parameters.
|
|
656
671
|
*/
|
|
@@ -669,8 +684,10 @@ interface RetrievalQueryParams {
|
|
|
669
684
|
* - ``undefined`` / omitted — server default
|
|
670
685
|
*/
|
|
671
686
|
useAgentic?: boolean;
|
|
672
|
-
/** Chunk type filter: 1=all, 2=text, 3=image, 4=table, 5=text+image, 6=text+table */
|
|
673
|
-
dataType?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
687
|
+
/** Chunk type filter: 1=all, 2=text, 3=image, 4=table, 5=text+image, 6=text+table, 7=page, 8=text+image+table */
|
|
688
|
+
dataType?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
689
|
+
/** Allowed chunk types. Overrides dataType when provided. */
|
|
690
|
+
chunkTypes?: RetrievalChunkType[];
|
|
674
691
|
/** Path keywords for include/exclude filtering */
|
|
675
692
|
signalPaths?: string[];
|
|
676
693
|
/** Signal path filter mode */
|
|
@@ -705,14 +722,24 @@ interface RetrievalSource {
|
|
|
705
722
|
* Canonical chunk result returned by retrieval query.
|
|
706
723
|
*/
|
|
707
724
|
interface RetrievalResult {
|
|
725
|
+
/** Parser-provided chunk identifier when included by the API */
|
|
726
|
+
chunkId?: string;
|
|
708
727
|
/** Knowledge content to use directly in the caller's answer */
|
|
709
728
|
content: string;
|
|
710
|
-
/** Chunk type, for example text, image, or
|
|
729
|
+
/** Chunk type, for example text, image, table, or page */
|
|
711
730
|
chunkType: string;
|
|
731
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
732
|
+
contentSource?: string;
|
|
712
733
|
/** Retrieval score returned by the API. Null when no score is available (agentic navigation-only results). */
|
|
713
734
|
score: number | null;
|
|
714
735
|
/** Presigned asset URL for media chunks when available */
|
|
715
736
|
assetUrl?: string;
|
|
737
|
+
/** Source chunk path when returned by the API */
|
|
738
|
+
sourceChunkPath?: string | null;
|
|
739
|
+
/** Generated artifact file path for media chunks */
|
|
740
|
+
filePath?: string | null;
|
|
741
|
+
/** Chunk metadata returned by the API */
|
|
742
|
+
metadata?: Record<string, unknown>;
|
|
716
743
|
/** Source reference for this result */
|
|
717
744
|
source: RetrievalSource;
|
|
718
745
|
}
|
|
@@ -724,19 +751,25 @@ interface RetrievalReferencedChunk {
|
|
|
724
751
|
chunkId: string;
|
|
725
752
|
/** Stable document identifier */
|
|
726
753
|
documentId: string;
|
|
727
|
-
/** Chunk type, for example text, image, or
|
|
754
|
+
/** Chunk type, for example text, image, table, or page */
|
|
728
755
|
chunkType: string;
|
|
756
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
757
|
+
contentSource?: string | null;
|
|
729
758
|
/** Human-readable section path */
|
|
730
759
|
sectionPath: string;
|
|
760
|
+
/** Source chunk path when returned by the API */
|
|
761
|
+
sourceChunkPath?: string | null;
|
|
731
762
|
/** Generated artifact file path for media chunks */
|
|
732
763
|
filePath?: string | null;
|
|
733
764
|
/** Published job identifier for the referenced chunk */
|
|
734
765
|
jobId?: string | null;
|
|
735
766
|
/** Presigned asset URL for media chunks when available */
|
|
736
767
|
assetUrl?: string | null;
|
|
768
|
+
/** Chunk metadata returned by the API */
|
|
769
|
+
metadata?: Record<string, unknown>;
|
|
737
770
|
}
|
|
738
771
|
/**
|
|
739
|
-
* Response from POST /
|
|
772
|
+
* Response from POST /v2/retrieval/query.
|
|
740
773
|
*
|
|
741
774
|
* Three PRIMARY output fields for downstream agent consumption:
|
|
742
775
|
* - `evidenceText`: hierarchical evidence tree for LLM context
|
|
@@ -800,18 +833,44 @@ interface Document {
|
|
|
800
833
|
archivedAt?: Date;
|
|
801
834
|
}
|
|
802
835
|
/**
|
|
803
|
-
*
|
|
836
|
+
* Pagination metadata returned by document list endpoints.
|
|
837
|
+
*/
|
|
838
|
+
interface DocumentListPagination {
|
|
839
|
+
/** Current page number */
|
|
840
|
+
page: number;
|
|
841
|
+
/** Number of items requested per page */
|
|
842
|
+
pageSize: number;
|
|
843
|
+
/** Total matching documents */
|
|
844
|
+
total: number;
|
|
845
|
+
/** Total number of pages */
|
|
846
|
+
totalPages: number;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Query parameters for GET /v2/documents.
|
|
850
|
+
*/
|
|
851
|
+
interface DocumentListParams {
|
|
852
|
+
/** Retrieval namespace */
|
|
853
|
+
namespace?: string;
|
|
854
|
+
/** Page number (default: 1) */
|
|
855
|
+
page?: number;
|
|
856
|
+
/** Items per page (default: 50, maximum: 200) */
|
|
857
|
+
pageSize?: number;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Response from GET /v2/documents.
|
|
804
861
|
*/
|
|
805
862
|
interface DocumentListResponse {
|
|
806
863
|
/** Namespace listed by the API */
|
|
807
864
|
namespace: string;
|
|
808
865
|
/** Documents visible in the namespace */
|
|
809
866
|
documents: Document[];
|
|
867
|
+
/** Pagination metadata */
|
|
868
|
+
pagination: DocumentListPagination;
|
|
810
869
|
}
|
|
811
870
|
/**
|
|
812
871
|
* Document chunk types supported by document chunk endpoints.
|
|
813
872
|
*/
|
|
814
|
-
type DocumentChunkType = 'text' | 'image' | 'table';
|
|
873
|
+
type DocumentChunkType = 'text' | 'image' | 'table' | 'page';
|
|
815
874
|
/**
|
|
816
875
|
* Pagination metadata returned by chunk list endpoints.
|
|
817
876
|
*/
|
|
@@ -826,7 +885,7 @@ interface DocumentChunkPagination {
|
|
|
826
885
|
totalPages: number;
|
|
827
886
|
}
|
|
828
887
|
/**
|
|
829
|
-
* Query parameters for GET /
|
|
888
|
+
* Query parameters for GET /v2/documents/{document_id}/chunks.
|
|
830
889
|
*/
|
|
831
890
|
interface DocumentChunkListParams {
|
|
832
891
|
/** Page number (default: 1) */
|
|
@@ -835,14 +894,14 @@ interface DocumentChunkListParams {
|
|
|
835
894
|
pageSize?: number;
|
|
836
895
|
/** Optional chunk type filter */
|
|
837
896
|
chunkType?: DocumentChunkType;
|
|
838
|
-
/**
|
|
897
|
+
/** Set true to include 7-day asset URLs for media chunks */
|
|
839
898
|
includeAssetUrls?: boolean;
|
|
840
899
|
}
|
|
841
900
|
/**
|
|
842
|
-
* Query parameters for GET /
|
|
901
|
+
* Query parameters for GET /v2/documents/{document_id}/chunks/{document_chunk_id}.
|
|
843
902
|
*/
|
|
844
903
|
interface DocumentChunkGetParams {
|
|
845
|
-
/**
|
|
904
|
+
/** Set true to include 7-day asset URLs for media chunks */
|
|
846
905
|
includeAssetUrls?: boolean;
|
|
847
906
|
}
|
|
848
907
|
/**
|
|
@@ -855,6 +914,8 @@ interface DocumentChunk {
|
|
|
855
914
|
chunkId: string;
|
|
856
915
|
/** Chunk content type */
|
|
857
916
|
chunkType: DocumentChunkType;
|
|
917
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
918
|
+
contentSource?: string | null;
|
|
858
919
|
/** Chunk text or generated summary content */
|
|
859
920
|
content?: string | null;
|
|
860
921
|
/** Parent section identifier */
|
|
@@ -869,13 +930,13 @@ interface DocumentChunk {
|
|
|
869
930
|
sortOrder: number;
|
|
870
931
|
/** Chunk metadata returned by the API */
|
|
871
932
|
metadata: Record<string, unknown>;
|
|
872
|
-
/**
|
|
933
|
+
/** 7-day asset URL for media chunks when available */
|
|
873
934
|
assetUrl?: string | null;
|
|
874
935
|
/** Chunk creation timestamp */
|
|
875
936
|
createdAt?: Date;
|
|
876
937
|
}
|
|
877
938
|
/**
|
|
878
|
-
* Response from GET /
|
|
939
|
+
* Response from GET /v2/documents/{document_id}/chunks.
|
|
879
940
|
*/
|
|
880
941
|
interface DocumentChunkListResponse {
|
|
881
942
|
/** Stable document identifier */
|
|
@@ -892,7 +953,7 @@ interface DocumentChunkListResponse {
|
|
|
892
953
|
pagination: DocumentChunkPagination;
|
|
893
954
|
}
|
|
894
955
|
/**
|
|
895
|
-
* Response from GET /
|
|
956
|
+
* Response from GET /v2/documents/{document_id}/chunks/{document_chunk_id}.
|
|
896
957
|
*/
|
|
897
958
|
interface DocumentChunkResponse {
|
|
898
959
|
/** Stable document identifier */
|
|
@@ -914,9 +975,7 @@ declare class Documents extends BaseResource {
|
|
|
914
975
|
/**
|
|
915
976
|
* List canonical documents in a namespace.
|
|
916
977
|
*/
|
|
917
|
-
list(params?:
|
|
918
|
-
namespace?: string;
|
|
919
|
-
}): Promise<DocumentListResponse>;
|
|
978
|
+
list(params?: DocumentListParams): Promise<DocumentListResponse>;
|
|
920
979
|
/**
|
|
921
980
|
* Get one canonical document by ID.
|
|
922
981
|
*/
|
|
@@ -933,6 +992,8 @@ declare class Documents extends BaseResource {
|
|
|
933
992
|
* Archive one canonical document by ID.
|
|
934
993
|
*/
|
|
935
994
|
archive(documentId: string): Promise<Document>;
|
|
995
|
+
private createDocumentListRequestConfig;
|
|
996
|
+
private normalizeDocumentListResponse;
|
|
936
997
|
private createChunkListRequestConfig;
|
|
937
998
|
private createChunkGetRequestConfig;
|
|
938
999
|
}
|
|
@@ -1040,10 +1101,15 @@ interface KnowledgeReadChunk {
|
|
|
1040
1101
|
position: number;
|
|
1041
1102
|
chunkId: string;
|
|
1042
1103
|
chunkType: KnowledgeChunkType;
|
|
1104
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
1105
|
+
contentSource?: string;
|
|
1043
1106
|
content: string;
|
|
1107
|
+
/** Display-safe text. For page chunks this prefers metadata.summary. */
|
|
1108
|
+
readableContent: string;
|
|
1044
1109
|
sectionPath: string;
|
|
1045
1110
|
sourceChunkPath: string;
|
|
1046
1111
|
filePath?: string;
|
|
1112
|
+
pageNumbers?: number[];
|
|
1047
1113
|
metadata: Record<string, unknown>;
|
|
1048
1114
|
}
|
|
1049
1115
|
interface KnowledgeReadResponse {
|
|
@@ -1358,4 +1424,4 @@ declare class JobFailedError extends KnowhereError {
|
|
|
1358
1424
|
constructor(message: string, code: string, jobResult: JobResult);
|
|
1359
1425
|
}
|
|
1360
1426
|
|
|
1361
|
-
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListResponse, type DocumentMetadata, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NetworkError, NotFoundError, type ParseParams, type ParseResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default };
|
|
1427
|
+
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListPagination, type DocumentListParams, type DocumentListResponse, type DocumentMetadata, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NetworkError, NotFoundError, type PageChunk, type ParseParams, type ParseResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalChunkType, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -300,6 +300,8 @@ interface Statistics {
|
|
|
300
300
|
imageChunks: number;
|
|
301
301
|
/** Number of table chunks */
|
|
302
302
|
tableChunks: number;
|
|
303
|
+
/** Number of page chunks */
|
|
304
|
+
pageChunks?: number;
|
|
303
305
|
/** Total number of pages (if applicable) */
|
|
304
306
|
totalPages?: number;
|
|
305
307
|
}
|
|
@@ -417,6 +419,7 @@ interface DocNav {
|
|
|
417
419
|
interface ChunkMetadata {
|
|
418
420
|
length?: number;
|
|
419
421
|
pageNums?: number[];
|
|
422
|
+
entities?: Record<string, unknown>[];
|
|
420
423
|
tokens?: string[];
|
|
421
424
|
keywords?: string[];
|
|
422
425
|
summary?: string;
|
|
@@ -435,7 +438,9 @@ interface BaseChunk {
|
|
|
435
438
|
/** Unique chunk identifier */
|
|
436
439
|
chunkId: string;
|
|
437
440
|
/** Chunk type */
|
|
438
|
-
type: 'text' | 'image' | 'table';
|
|
441
|
+
type: 'text' | 'image' | 'table' | 'page';
|
|
442
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
443
|
+
contentSource?: string;
|
|
439
444
|
/** Main content */
|
|
440
445
|
content: string;
|
|
441
446
|
/** Relative path in ZIP */
|
|
@@ -447,7 +452,7 @@ interface BaseChunk {
|
|
|
447
452
|
* Minimal chunk representation emitted in chunks_slim.json (legacy).
|
|
448
453
|
*/
|
|
449
454
|
interface SlimChunk {
|
|
450
|
-
type: 'text' | 'image' | 'table';
|
|
455
|
+
type: 'text' | 'image' | 'table' | 'page';
|
|
451
456
|
path: string;
|
|
452
457
|
content: string;
|
|
453
458
|
}
|
|
@@ -483,10 +488,16 @@ interface TableChunk extends BaseChunk {
|
|
|
483
488
|
/** Save table HTML to disk */
|
|
484
489
|
save(directory: string): Promise<string>;
|
|
485
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Page chunk
|
|
493
|
+
*/
|
|
494
|
+
interface PageChunk extends BaseChunk {
|
|
495
|
+
type: 'page';
|
|
496
|
+
}
|
|
486
497
|
/**
|
|
487
498
|
* Union type of all chunk types
|
|
488
499
|
*/
|
|
489
|
-
type Chunk = TextChunk | ImageChunk | TableChunk;
|
|
500
|
+
type Chunk = TextChunk | ImageChunk | TableChunk | PageChunk;
|
|
490
501
|
/**
|
|
491
502
|
* Complete parse result
|
|
492
503
|
*/
|
|
@@ -517,6 +528,8 @@ interface ParseResult {
|
|
|
517
528
|
readonly imageChunks: ImageChunk[];
|
|
518
529
|
/** Table chunks only */
|
|
519
530
|
readonly tableChunks: TableChunk[];
|
|
531
|
+
/** Page chunks only */
|
|
532
|
+
readonly pageChunks: PageChunk[];
|
|
520
533
|
/** Job ID */
|
|
521
534
|
readonly jobId: string;
|
|
522
535
|
/** Effective retrieval namespace when loaded from a job result */
|
|
@@ -602,6 +615,7 @@ declare class HttpClient {
|
|
|
602
615
|
declare abstract class BaseResource {
|
|
603
616
|
protected httpClient: HttpClient;
|
|
604
617
|
constructor(httpClient: HttpClient);
|
|
618
|
+
protected endpoint(path: string): string;
|
|
605
619
|
}
|
|
606
620
|
|
|
607
621
|
/**
|
|
@@ -651,6 +665,7 @@ type RetrievalChannel = 'path' | 'content' | 'term';
|
|
|
651
665
|
* Path filtering mode for retrieval queries.
|
|
652
666
|
*/
|
|
653
667
|
type RetrievalFilterMode = 'delete' | 'keep';
|
|
668
|
+
type RetrievalChunkType = 'text' | 'image' | 'table' | 'page';
|
|
654
669
|
/**
|
|
655
670
|
* Retrieval query parameters.
|
|
656
671
|
*/
|
|
@@ -669,8 +684,10 @@ interface RetrievalQueryParams {
|
|
|
669
684
|
* - ``undefined`` / omitted — server default
|
|
670
685
|
*/
|
|
671
686
|
useAgentic?: boolean;
|
|
672
|
-
/** Chunk type filter: 1=all, 2=text, 3=image, 4=table, 5=text+image, 6=text+table */
|
|
673
|
-
dataType?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
687
|
+
/** Chunk type filter: 1=all, 2=text, 3=image, 4=table, 5=text+image, 6=text+table, 7=page, 8=text+image+table */
|
|
688
|
+
dataType?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
689
|
+
/** Allowed chunk types. Overrides dataType when provided. */
|
|
690
|
+
chunkTypes?: RetrievalChunkType[];
|
|
674
691
|
/** Path keywords for include/exclude filtering */
|
|
675
692
|
signalPaths?: string[];
|
|
676
693
|
/** Signal path filter mode */
|
|
@@ -705,14 +722,24 @@ interface RetrievalSource {
|
|
|
705
722
|
* Canonical chunk result returned by retrieval query.
|
|
706
723
|
*/
|
|
707
724
|
interface RetrievalResult {
|
|
725
|
+
/** Parser-provided chunk identifier when included by the API */
|
|
726
|
+
chunkId?: string;
|
|
708
727
|
/** Knowledge content to use directly in the caller's answer */
|
|
709
728
|
content: string;
|
|
710
|
-
/** Chunk type, for example text, image, or
|
|
729
|
+
/** Chunk type, for example text, image, table, or page */
|
|
711
730
|
chunkType: string;
|
|
731
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
732
|
+
contentSource?: string;
|
|
712
733
|
/** Retrieval score returned by the API. Null when no score is available (agentic navigation-only results). */
|
|
713
734
|
score: number | null;
|
|
714
735
|
/** Presigned asset URL for media chunks when available */
|
|
715
736
|
assetUrl?: string;
|
|
737
|
+
/** Source chunk path when returned by the API */
|
|
738
|
+
sourceChunkPath?: string | null;
|
|
739
|
+
/** Generated artifact file path for media chunks */
|
|
740
|
+
filePath?: string | null;
|
|
741
|
+
/** Chunk metadata returned by the API */
|
|
742
|
+
metadata?: Record<string, unknown>;
|
|
716
743
|
/** Source reference for this result */
|
|
717
744
|
source: RetrievalSource;
|
|
718
745
|
}
|
|
@@ -724,19 +751,25 @@ interface RetrievalReferencedChunk {
|
|
|
724
751
|
chunkId: string;
|
|
725
752
|
/** Stable document identifier */
|
|
726
753
|
documentId: string;
|
|
727
|
-
/** Chunk type, for example text, image, or
|
|
754
|
+
/** Chunk type, for example text, image, table, or page */
|
|
728
755
|
chunkType: string;
|
|
756
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
757
|
+
contentSource?: string | null;
|
|
729
758
|
/** Human-readable section path */
|
|
730
759
|
sectionPath: string;
|
|
760
|
+
/** Source chunk path when returned by the API */
|
|
761
|
+
sourceChunkPath?: string | null;
|
|
731
762
|
/** Generated artifact file path for media chunks */
|
|
732
763
|
filePath?: string | null;
|
|
733
764
|
/** Published job identifier for the referenced chunk */
|
|
734
765
|
jobId?: string | null;
|
|
735
766
|
/** Presigned asset URL for media chunks when available */
|
|
736
767
|
assetUrl?: string | null;
|
|
768
|
+
/** Chunk metadata returned by the API */
|
|
769
|
+
metadata?: Record<string, unknown>;
|
|
737
770
|
}
|
|
738
771
|
/**
|
|
739
|
-
* Response from POST /
|
|
772
|
+
* Response from POST /v2/retrieval/query.
|
|
740
773
|
*
|
|
741
774
|
* Three PRIMARY output fields for downstream agent consumption:
|
|
742
775
|
* - `evidenceText`: hierarchical evidence tree for LLM context
|
|
@@ -800,18 +833,44 @@ interface Document {
|
|
|
800
833
|
archivedAt?: Date;
|
|
801
834
|
}
|
|
802
835
|
/**
|
|
803
|
-
*
|
|
836
|
+
* Pagination metadata returned by document list endpoints.
|
|
837
|
+
*/
|
|
838
|
+
interface DocumentListPagination {
|
|
839
|
+
/** Current page number */
|
|
840
|
+
page: number;
|
|
841
|
+
/** Number of items requested per page */
|
|
842
|
+
pageSize: number;
|
|
843
|
+
/** Total matching documents */
|
|
844
|
+
total: number;
|
|
845
|
+
/** Total number of pages */
|
|
846
|
+
totalPages: number;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Query parameters for GET /v2/documents.
|
|
850
|
+
*/
|
|
851
|
+
interface DocumentListParams {
|
|
852
|
+
/** Retrieval namespace */
|
|
853
|
+
namespace?: string;
|
|
854
|
+
/** Page number (default: 1) */
|
|
855
|
+
page?: number;
|
|
856
|
+
/** Items per page (default: 50, maximum: 200) */
|
|
857
|
+
pageSize?: number;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Response from GET /v2/documents.
|
|
804
861
|
*/
|
|
805
862
|
interface DocumentListResponse {
|
|
806
863
|
/** Namespace listed by the API */
|
|
807
864
|
namespace: string;
|
|
808
865
|
/** Documents visible in the namespace */
|
|
809
866
|
documents: Document[];
|
|
867
|
+
/** Pagination metadata */
|
|
868
|
+
pagination: DocumentListPagination;
|
|
810
869
|
}
|
|
811
870
|
/**
|
|
812
871
|
* Document chunk types supported by document chunk endpoints.
|
|
813
872
|
*/
|
|
814
|
-
type DocumentChunkType = 'text' | 'image' | 'table';
|
|
873
|
+
type DocumentChunkType = 'text' | 'image' | 'table' | 'page';
|
|
815
874
|
/**
|
|
816
875
|
* Pagination metadata returned by chunk list endpoints.
|
|
817
876
|
*/
|
|
@@ -826,7 +885,7 @@ interface DocumentChunkPagination {
|
|
|
826
885
|
totalPages: number;
|
|
827
886
|
}
|
|
828
887
|
/**
|
|
829
|
-
* Query parameters for GET /
|
|
888
|
+
* Query parameters for GET /v2/documents/{document_id}/chunks.
|
|
830
889
|
*/
|
|
831
890
|
interface DocumentChunkListParams {
|
|
832
891
|
/** Page number (default: 1) */
|
|
@@ -835,14 +894,14 @@ interface DocumentChunkListParams {
|
|
|
835
894
|
pageSize?: number;
|
|
836
895
|
/** Optional chunk type filter */
|
|
837
896
|
chunkType?: DocumentChunkType;
|
|
838
|
-
/**
|
|
897
|
+
/** Set true to include 7-day asset URLs for media chunks */
|
|
839
898
|
includeAssetUrls?: boolean;
|
|
840
899
|
}
|
|
841
900
|
/**
|
|
842
|
-
* Query parameters for GET /
|
|
901
|
+
* Query parameters for GET /v2/documents/{document_id}/chunks/{document_chunk_id}.
|
|
843
902
|
*/
|
|
844
903
|
interface DocumentChunkGetParams {
|
|
845
|
-
/**
|
|
904
|
+
/** Set true to include 7-day asset URLs for media chunks */
|
|
846
905
|
includeAssetUrls?: boolean;
|
|
847
906
|
}
|
|
848
907
|
/**
|
|
@@ -855,6 +914,8 @@ interface DocumentChunk {
|
|
|
855
914
|
chunkId: string;
|
|
856
915
|
/** Chunk content type */
|
|
857
916
|
chunkType: DocumentChunkType;
|
|
917
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
918
|
+
contentSource?: string | null;
|
|
858
919
|
/** Chunk text or generated summary content */
|
|
859
920
|
content?: string | null;
|
|
860
921
|
/** Parent section identifier */
|
|
@@ -869,13 +930,13 @@ interface DocumentChunk {
|
|
|
869
930
|
sortOrder: number;
|
|
870
931
|
/** Chunk metadata returned by the API */
|
|
871
932
|
metadata: Record<string, unknown>;
|
|
872
|
-
/**
|
|
933
|
+
/** 7-day asset URL for media chunks when available */
|
|
873
934
|
assetUrl?: string | null;
|
|
874
935
|
/** Chunk creation timestamp */
|
|
875
936
|
createdAt?: Date;
|
|
876
937
|
}
|
|
877
938
|
/**
|
|
878
|
-
* Response from GET /
|
|
939
|
+
* Response from GET /v2/documents/{document_id}/chunks.
|
|
879
940
|
*/
|
|
880
941
|
interface DocumentChunkListResponse {
|
|
881
942
|
/** Stable document identifier */
|
|
@@ -892,7 +953,7 @@ interface DocumentChunkListResponse {
|
|
|
892
953
|
pagination: DocumentChunkPagination;
|
|
893
954
|
}
|
|
894
955
|
/**
|
|
895
|
-
* Response from GET /
|
|
956
|
+
* Response from GET /v2/documents/{document_id}/chunks/{document_chunk_id}.
|
|
896
957
|
*/
|
|
897
958
|
interface DocumentChunkResponse {
|
|
898
959
|
/** Stable document identifier */
|
|
@@ -914,9 +975,7 @@ declare class Documents extends BaseResource {
|
|
|
914
975
|
/**
|
|
915
976
|
* List canonical documents in a namespace.
|
|
916
977
|
*/
|
|
917
|
-
list(params?:
|
|
918
|
-
namespace?: string;
|
|
919
|
-
}): Promise<DocumentListResponse>;
|
|
978
|
+
list(params?: DocumentListParams): Promise<DocumentListResponse>;
|
|
920
979
|
/**
|
|
921
980
|
* Get one canonical document by ID.
|
|
922
981
|
*/
|
|
@@ -933,6 +992,8 @@ declare class Documents extends BaseResource {
|
|
|
933
992
|
* Archive one canonical document by ID.
|
|
934
993
|
*/
|
|
935
994
|
archive(documentId: string): Promise<Document>;
|
|
995
|
+
private createDocumentListRequestConfig;
|
|
996
|
+
private normalizeDocumentListResponse;
|
|
936
997
|
private createChunkListRequestConfig;
|
|
937
998
|
private createChunkGetRequestConfig;
|
|
938
999
|
}
|
|
@@ -1040,10 +1101,15 @@ interface KnowledgeReadChunk {
|
|
|
1040
1101
|
position: number;
|
|
1041
1102
|
chunkId: string;
|
|
1042
1103
|
chunkType: KnowledgeChunkType;
|
|
1104
|
+
/** Content source marker. Page chunks normally expose summaries as content. */
|
|
1105
|
+
contentSource?: string;
|
|
1043
1106
|
content: string;
|
|
1107
|
+
/** Display-safe text. For page chunks this prefers metadata.summary. */
|
|
1108
|
+
readableContent: string;
|
|
1044
1109
|
sectionPath: string;
|
|
1045
1110
|
sourceChunkPath: string;
|
|
1046
1111
|
filePath?: string;
|
|
1112
|
+
pageNumbers?: number[];
|
|
1047
1113
|
metadata: Record<string, unknown>;
|
|
1048
1114
|
}
|
|
1049
1115
|
interface KnowledgeReadResponse {
|
|
@@ -1358,4 +1424,4 @@ declare class JobFailedError extends KnowhereError {
|
|
|
1358
1424
|
constructor(message: string, code: string, jobResult: JobResult);
|
|
1359
1425
|
}
|
|
1360
1426
|
|
|
1361
|
-
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListResponse, type DocumentMetadata, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NetworkError, NotFoundError, type ParseParams, type ParseResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default };
|
|
1427
|
+
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListPagination, type DocumentListParams, type DocumentListResponse, type DocumentMetadata, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NetworkError, NotFoundError, type PageChunk, type ParseParams, type ParseResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalChunkType, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default };
|
package/dist/index.js
CHANGED
|
@@ -756,6 +756,9 @@ var BaseResource = class {
|
|
|
756
756
|
constructor(httpClient) {
|
|
757
757
|
this.httpClient = httpClient;
|
|
758
758
|
}
|
|
759
|
+
endpoint(path3) {
|
|
760
|
+
return `/v2${path3.startsWith("/") ? path3 : `/${path3}`}`;
|
|
761
|
+
}
|
|
759
762
|
};
|
|
760
763
|
|
|
761
764
|
// src/lib/upload.ts
|
|
@@ -806,7 +809,7 @@ async function pollJobStatus(httpClient, jobId, options) {
|
|
|
806
809
|
if (signal?.aborted) {
|
|
807
810
|
throw new Error("Polling aborted");
|
|
808
811
|
}
|
|
809
|
-
const jobResult = await httpClient.get(`/
|
|
812
|
+
const jobResult = await httpClient.get(`/v2/jobs/${jobId}`);
|
|
810
813
|
enrichJobResult(jobResult);
|
|
811
814
|
const elapsed = Date.now() - startTime;
|
|
812
815
|
const elapsedSeconds = Math.floor(elapsed / 1e3);
|
|
@@ -1067,6 +1070,9 @@ function createParseResult(parts) {
|
|
|
1067
1070
|
get tableChunks() {
|
|
1068
1071
|
return chunks.filter((c) => c.type === "table");
|
|
1069
1072
|
},
|
|
1073
|
+
get pageChunks() {
|
|
1074
|
+
return chunks.filter((c) => c.type === "page");
|
|
1075
|
+
},
|
|
1070
1076
|
get jobId() {
|
|
1071
1077
|
return manifest.jobId;
|
|
1072
1078
|
},
|
|
@@ -1144,6 +1150,17 @@ function buildTextChunk(chunkData) {
|
|
|
1144
1150
|
return {
|
|
1145
1151
|
chunkId: chunkData.chunkId ?? "",
|
|
1146
1152
|
type: "text",
|
|
1153
|
+
contentSource: chunkData.contentSource ?? "content",
|
|
1154
|
+
content: chunkData.content ?? "",
|
|
1155
|
+
path: chunkData.path ?? "",
|
|
1156
|
+
metadata: chunkData.metadata ?? {}
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function buildPageChunk(chunkData) {
|
|
1160
|
+
return {
|
|
1161
|
+
chunkId: chunkData.chunkId ?? "",
|
|
1162
|
+
type: "page",
|
|
1163
|
+
contentSource: chunkData.contentSource ?? "summary",
|
|
1147
1164
|
content: chunkData.content ?? "",
|
|
1148
1165
|
path: chunkData.path ?? "",
|
|
1149
1166
|
metadata: chunkData.metadata ?? {}
|
|
@@ -1153,6 +1170,7 @@ function buildImageChunk(chunkData, filePath, imageBuffer) {
|
|
|
1153
1170
|
return {
|
|
1154
1171
|
chunkId: chunkData.chunkId ?? "",
|
|
1155
1172
|
type: "image",
|
|
1173
|
+
contentSource: chunkData.contentSource,
|
|
1156
1174
|
content: chunkData.content ?? "",
|
|
1157
1175
|
path: chunkData.path ?? "",
|
|
1158
1176
|
filePath,
|
|
@@ -1170,6 +1188,7 @@ function buildTableChunk(chunkData, filePath, html) {
|
|
|
1170
1188
|
return {
|
|
1171
1189
|
chunkId: chunkData.chunkId ?? "",
|
|
1172
1190
|
type: "table",
|
|
1191
|
+
contentSource: chunkData.contentSource,
|
|
1173
1192
|
content: chunkData.content ?? "",
|
|
1174
1193
|
path: chunkData.path ?? "",
|
|
1175
1194
|
filePath,
|
|
@@ -1184,6 +1203,9 @@ async function processChunk(zip, chunkData) {
|
|
|
1184
1203
|
if (chunkData.type === "text") {
|
|
1185
1204
|
return buildTextChunk(chunkData);
|
|
1186
1205
|
}
|
|
1206
|
+
if (chunkData.type === "page") {
|
|
1207
|
+
return buildPageChunk(chunkData);
|
|
1208
|
+
}
|
|
1187
1209
|
if (chunkData.type === "image") {
|
|
1188
1210
|
const filePath = getChunkFilePath(chunkData);
|
|
1189
1211
|
if (!filePath) {
|
|
@@ -1216,6 +1238,9 @@ async function processDirectoryChunk(directory, chunkData) {
|
|
|
1216
1238
|
if (chunkData.type === "text") {
|
|
1217
1239
|
return buildTextChunk(chunkData);
|
|
1218
1240
|
}
|
|
1241
|
+
if (chunkData.type === "page") {
|
|
1242
|
+
return buildPageChunk(chunkData);
|
|
1243
|
+
}
|
|
1219
1244
|
if (chunkData.type === "image") {
|
|
1220
1245
|
const filePath = getChunkFilePath(chunkData);
|
|
1221
1246
|
if (!filePath) {
|
|
@@ -1254,6 +1279,7 @@ function serializeChunks(chunks) {
|
|
|
1254
1279
|
const rawChunk = {
|
|
1255
1280
|
chunkId: chunk.chunkId,
|
|
1256
1281
|
type: chunk.type,
|
|
1282
|
+
contentSource: chunk.contentSource,
|
|
1257
1283
|
content: chunk.content,
|
|
1258
1284
|
path: chunk.path,
|
|
1259
1285
|
metadata: chunk.metadata
|
|
@@ -1322,7 +1348,7 @@ var Jobs = class extends BaseResource {
|
|
|
1322
1348
|
* Create a new parsing job
|
|
1323
1349
|
*/
|
|
1324
1350
|
async create(params) {
|
|
1325
|
-
const job = await this.httpClient.post("/
|
|
1351
|
+
const job = await this.httpClient.post(this.endpoint("/jobs"), params);
|
|
1326
1352
|
if (job.uploadUrl) {
|
|
1327
1353
|
this.pendingUploadJobs.set(job.jobId, job);
|
|
1328
1354
|
}
|
|
@@ -1332,7 +1358,7 @@ var Jobs = class extends BaseResource {
|
|
|
1332
1358
|
* Get job status
|
|
1333
1359
|
*/
|
|
1334
1360
|
async get(jobId) {
|
|
1335
|
-
const jobResult = await this.httpClient.get(`/
|
|
1361
|
+
const jobResult = await this.httpClient.get(this.endpoint(`/jobs/${jobId}`));
|
|
1336
1362
|
enrichJobResult(jobResult);
|
|
1337
1363
|
return jobResult;
|
|
1338
1364
|
}
|
|
@@ -1428,7 +1454,7 @@ var Retrieval = class extends BaseResource {
|
|
|
1428
1454
|
* Query published documents.
|
|
1429
1455
|
*/
|
|
1430
1456
|
async query(params) {
|
|
1431
|
-
return this.httpClient.post("/
|
|
1457
|
+
return this.httpClient.post(this.endpoint("/retrieval/query"), params);
|
|
1432
1458
|
}
|
|
1433
1459
|
};
|
|
1434
1460
|
|
|
@@ -1438,25 +1464,24 @@ var Documents = class extends BaseResource {
|
|
|
1438
1464
|
* List canonical documents in a namespace.
|
|
1439
1465
|
*/
|
|
1440
1466
|
async list(params) {
|
|
1441
|
-
const
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
return this.httpClient.get("/v1/documents", requestConfig);
|
|
1467
|
+
const response = await this.httpClient.get(
|
|
1468
|
+
this.endpoint("/documents"),
|
|
1469
|
+
this.createDocumentListRequestConfig(params)
|
|
1470
|
+
);
|
|
1471
|
+
return this.normalizeDocumentListResponse(response);
|
|
1447
1472
|
}
|
|
1448
1473
|
/**
|
|
1449
1474
|
* Get one canonical document by ID.
|
|
1450
1475
|
*/
|
|
1451
1476
|
async get(documentId) {
|
|
1452
|
-
return this.httpClient.get(`/
|
|
1477
|
+
return this.httpClient.get(this.endpoint(`/documents/${documentId}`));
|
|
1453
1478
|
}
|
|
1454
1479
|
/**
|
|
1455
1480
|
* List current-revision chunks for one canonical document.
|
|
1456
1481
|
*/
|
|
1457
1482
|
async listChunks(documentId, params) {
|
|
1458
1483
|
return this.httpClient.get(
|
|
1459
|
-
`/
|
|
1484
|
+
this.endpoint(`/documents/${documentId}/chunks`),
|
|
1460
1485
|
this.createChunkListRequestConfig(params)
|
|
1461
1486
|
);
|
|
1462
1487
|
}
|
|
@@ -1465,7 +1490,7 @@ var Documents = class extends BaseResource {
|
|
|
1465
1490
|
*/
|
|
1466
1491
|
async getChunk(documentId, documentChunkId, params) {
|
|
1467
1492
|
return this.httpClient.get(
|
|
1468
|
-
`/
|
|
1493
|
+
this.endpoint(`/documents/${documentId}/chunks/${documentChunkId}`),
|
|
1469
1494
|
this.createChunkGetRequestConfig(params)
|
|
1470
1495
|
);
|
|
1471
1496
|
}
|
|
@@ -1473,7 +1498,39 @@ var Documents = class extends BaseResource {
|
|
|
1473
1498
|
* Archive one canonical document by ID.
|
|
1474
1499
|
*/
|
|
1475
1500
|
async archive(documentId) {
|
|
1476
|
-
return this.httpClient.post(`/
|
|
1501
|
+
return this.httpClient.post(this.endpoint(`/documents/${documentId}/archive`));
|
|
1502
|
+
}
|
|
1503
|
+
createDocumentListRequestConfig(params) {
|
|
1504
|
+
if (!params) {
|
|
1505
|
+
return void 0;
|
|
1506
|
+
}
|
|
1507
|
+
const queryParams = {};
|
|
1508
|
+
if (params.namespace !== void 0) {
|
|
1509
|
+
queryParams.namespace = params.namespace;
|
|
1510
|
+
}
|
|
1511
|
+
if (params.page !== void 0) {
|
|
1512
|
+
queryParams.page = params.page;
|
|
1513
|
+
}
|
|
1514
|
+
if (params.pageSize !== void 0) {
|
|
1515
|
+
queryParams.page_size = params.pageSize;
|
|
1516
|
+
}
|
|
1517
|
+
return Object.keys(queryParams).length > 0 ? { params: queryParams } : void 0;
|
|
1518
|
+
}
|
|
1519
|
+
normalizeDocumentListResponse(response) {
|
|
1520
|
+
const maybePaginatedResponse = response;
|
|
1521
|
+
if (maybePaginatedResponse.pagination) {
|
|
1522
|
+
return response;
|
|
1523
|
+
}
|
|
1524
|
+
const total = response.documents.length;
|
|
1525
|
+
return {
|
|
1526
|
+
...response,
|
|
1527
|
+
pagination: {
|
|
1528
|
+
page: 1,
|
|
1529
|
+
pageSize: total,
|
|
1530
|
+
total,
|
|
1531
|
+
totalPages: total > 0 ? 1 : 0
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1477
1534
|
}
|
|
1478
1535
|
createChunkListRequestConfig(params) {
|
|
1479
1536
|
if (!params) {
|
|
@@ -1489,18 +1546,18 @@ var Documents = class extends BaseResource {
|
|
|
1489
1546
|
if (params.chunkType !== void 0) {
|
|
1490
1547
|
queryParams.chunk_type = params.chunkType;
|
|
1491
1548
|
}
|
|
1492
|
-
if (params.includeAssetUrls
|
|
1493
|
-
queryParams.include_asset_urls =
|
|
1549
|
+
if (params.includeAssetUrls !== void 0) {
|
|
1550
|
+
queryParams.include_asset_urls = params.includeAssetUrls;
|
|
1494
1551
|
}
|
|
1495
1552
|
return Object.keys(queryParams).length > 0 ? { params: queryParams } : void 0;
|
|
1496
1553
|
}
|
|
1497
1554
|
createChunkGetRequestConfig(params) {
|
|
1498
|
-
if (params?.includeAssetUrls
|
|
1555
|
+
if (params?.includeAssetUrls === void 0) {
|
|
1499
1556
|
return void 0;
|
|
1500
1557
|
}
|
|
1501
1558
|
return {
|
|
1502
1559
|
params: {
|
|
1503
|
-
include_asset_urls:
|
|
1560
|
+
include_asset_urls: params.includeAssetUrls
|
|
1504
1561
|
}
|
|
1505
1562
|
};
|
|
1506
1563
|
}
|
|
@@ -1703,7 +1760,7 @@ function countChunkTypes(result) {
|
|
|
1703
1760
|
counts[chunk.type] += 1;
|
|
1704
1761
|
return counts;
|
|
1705
1762
|
},
|
|
1706
|
-
{ text: 0, image: 0, table: 0 }
|
|
1763
|
+
{ text: 0, image: 0, table: 0, page: 0 }
|
|
1707
1764
|
);
|
|
1708
1765
|
}
|
|
1709
1766
|
function toLocalKnowledgeDocument(stored) {
|
|
@@ -2030,19 +2087,40 @@ function createLocalDocumentIdForRemote(documentId) {
|
|
|
2030
2087
|
function indexChunks(result) {
|
|
2031
2088
|
return result.chunks.map((chunk, index) => {
|
|
2032
2089
|
const filePath = getChunkFilePath2(chunk);
|
|
2090
|
+
const readableContent = getReadableChunkContent(chunk);
|
|
2033
2091
|
return {
|
|
2034
2092
|
source: chunk,
|
|
2035
2093
|
position: index + 1,
|
|
2036
2094
|
chunkId: chunk.chunkId,
|
|
2037
2095
|
chunkType: chunk.type,
|
|
2096
|
+
contentSource: chunk.contentSource,
|
|
2038
2097
|
content: chunk.content,
|
|
2098
|
+
readableContent,
|
|
2039
2099
|
sectionPath: normalizeSectionPath(chunk.path, result.manifest.sourceFileName),
|
|
2040
2100
|
sourceChunkPath: chunk.path,
|
|
2041
2101
|
filePath,
|
|
2102
|
+
pageNumbers: getChunkPageNumbers(chunk.metadata),
|
|
2042
2103
|
metadata: chunk.metadata
|
|
2043
2104
|
};
|
|
2044
2105
|
});
|
|
2045
2106
|
}
|
|
2107
|
+
function getReadableChunkContent(chunk) {
|
|
2108
|
+
if (chunk.type !== "page") {
|
|
2109
|
+
return chunk.content;
|
|
2110
|
+
}
|
|
2111
|
+
const summary = chunk.metadata.summary;
|
|
2112
|
+
return typeof summary === "string" && summary.trim().length > 0 ? summary : chunk.content;
|
|
2113
|
+
}
|
|
2114
|
+
function getChunkPageNumbers(metadata) {
|
|
2115
|
+
const value = metadata.pageNums;
|
|
2116
|
+
if (!Array.isArray(value)) {
|
|
2117
|
+
return void 0;
|
|
2118
|
+
}
|
|
2119
|
+
const pageNumbers = value.filter(
|
|
2120
|
+
(pageNumber) => Number.isInteger(pageNumber) && pageNumber > 0
|
|
2121
|
+
);
|
|
2122
|
+
return pageNumbers.length > 0 ? [...new Set(pageNumbers)].sort((left, right) => left - right) : void 0;
|
|
2123
|
+
}
|
|
2046
2124
|
function getChunkFilePath2(chunk) {
|
|
2047
2125
|
if (chunk.type === "image" || chunk.type === "table") {
|
|
2048
2126
|
return chunk.filePath;
|
|
@@ -2116,7 +2194,7 @@ function createSectionFromChunk(pathValue, chunk) {
|
|
|
2116
2194
|
startChunk: chunk.position,
|
|
2117
2195
|
endChunk: chunk.position,
|
|
2118
2196
|
chunkCount: 1,
|
|
2119
|
-
typeCounts: { text: 0, image: 0, table: 0, [chunk.chunkType]: 1 },
|
|
2197
|
+
typeCounts: { text: 0, image: 0, table: 0, page: 0, [chunk.chunkType]: 1 },
|
|
2120
2198
|
children: []
|
|
2121
2199
|
};
|
|
2122
2200
|
}
|
|
@@ -2175,7 +2253,7 @@ function countIndexedTypes(chunks) {
|
|
|
2175
2253
|
counts[chunk.chunkType] += 1;
|
|
2176
2254
|
return counts;
|
|
2177
2255
|
},
|
|
2178
|
-
{ text: 0, image: 0, table: 0 }
|
|
2256
|
+
{ text: 0, image: 0, table: 0, page: 0 }
|
|
2179
2257
|
);
|
|
2180
2258
|
}
|
|
2181
2259
|
function isInSection(chunkSectionPath, sectionPath) {
|
|
@@ -2212,10 +2290,13 @@ function toReadChunk(chunk) {
|
|
|
2212
2290
|
position: chunk.position,
|
|
2213
2291
|
chunkId: chunk.chunkId,
|
|
2214
2292
|
chunkType: chunk.chunkType,
|
|
2293
|
+
contentSource: chunk.contentSource,
|
|
2215
2294
|
content: chunk.content,
|
|
2295
|
+
readableContent: chunk.readableContent,
|
|
2216
2296
|
sectionPath: chunk.sectionPath,
|
|
2217
2297
|
sourceChunkPath: chunk.sourceChunkPath,
|
|
2218
2298
|
filePath: chunk.filePath,
|
|
2299
|
+
pageNumbers: chunk.pageNumbers,
|
|
2219
2300
|
metadata: chunk.metadata
|
|
2220
2301
|
};
|
|
2221
2302
|
}
|
|
@@ -2267,6 +2348,7 @@ function toResultReference(result, documentByServerId) {
|
|
|
2267
2348
|
return {
|
|
2268
2349
|
localDocumentId: documentId ? documentByServerId.get(documentId)?.localDocumentId : void 0,
|
|
2269
2350
|
documentId,
|
|
2351
|
+
chunkId: result.chunkId,
|
|
2270
2352
|
sectionPath: result.source.sectionPath ?? void 0,
|
|
2271
2353
|
chunkType: result.chunkType,
|
|
2272
2354
|
score: result.score
|
|
@@ -2277,6 +2359,7 @@ function toRemoteSearchResult(result, documentByServerId) {
|
|
|
2277
2359
|
return {
|
|
2278
2360
|
localDocumentId: documentId ? documentByServerId.get(documentId)?.localDocumentId : void 0,
|
|
2279
2361
|
documentId,
|
|
2362
|
+
chunkId: result.chunkId,
|
|
2280
2363
|
chunkType: result.chunkType,
|
|
2281
2364
|
content: result.content,
|
|
2282
2365
|
score: result.score,
|
package/dist/index.mjs
CHANGED
|
@@ -696,6 +696,9 @@ var BaseResource = class {
|
|
|
696
696
|
constructor(httpClient) {
|
|
697
697
|
this.httpClient = httpClient;
|
|
698
698
|
}
|
|
699
|
+
endpoint(path3) {
|
|
700
|
+
return `/v2${path3.startsWith("/") ? path3 : `/${path3}`}`;
|
|
701
|
+
}
|
|
699
702
|
};
|
|
700
703
|
|
|
701
704
|
// src/lib/upload.ts
|
|
@@ -746,7 +749,7 @@ async function pollJobStatus(httpClient, jobId, options) {
|
|
|
746
749
|
if (signal?.aborted) {
|
|
747
750
|
throw new Error("Polling aborted");
|
|
748
751
|
}
|
|
749
|
-
const jobResult = await httpClient.get(`/
|
|
752
|
+
const jobResult = await httpClient.get(`/v2/jobs/${jobId}`);
|
|
750
753
|
enrichJobResult(jobResult);
|
|
751
754
|
const elapsed = Date.now() - startTime;
|
|
752
755
|
const elapsedSeconds = Math.floor(elapsed / 1e3);
|
|
@@ -1007,6 +1010,9 @@ function createParseResult(parts) {
|
|
|
1007
1010
|
get tableChunks() {
|
|
1008
1011
|
return chunks.filter((c) => c.type === "table");
|
|
1009
1012
|
},
|
|
1013
|
+
get pageChunks() {
|
|
1014
|
+
return chunks.filter((c) => c.type === "page");
|
|
1015
|
+
},
|
|
1010
1016
|
get jobId() {
|
|
1011
1017
|
return manifest.jobId;
|
|
1012
1018
|
},
|
|
@@ -1084,6 +1090,17 @@ function buildTextChunk(chunkData) {
|
|
|
1084
1090
|
return {
|
|
1085
1091
|
chunkId: chunkData.chunkId ?? "",
|
|
1086
1092
|
type: "text",
|
|
1093
|
+
contentSource: chunkData.contentSource ?? "content",
|
|
1094
|
+
content: chunkData.content ?? "",
|
|
1095
|
+
path: chunkData.path ?? "",
|
|
1096
|
+
metadata: chunkData.metadata ?? {}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function buildPageChunk(chunkData) {
|
|
1100
|
+
return {
|
|
1101
|
+
chunkId: chunkData.chunkId ?? "",
|
|
1102
|
+
type: "page",
|
|
1103
|
+
contentSource: chunkData.contentSource ?? "summary",
|
|
1087
1104
|
content: chunkData.content ?? "",
|
|
1088
1105
|
path: chunkData.path ?? "",
|
|
1089
1106
|
metadata: chunkData.metadata ?? {}
|
|
@@ -1093,6 +1110,7 @@ function buildImageChunk(chunkData, filePath, imageBuffer) {
|
|
|
1093
1110
|
return {
|
|
1094
1111
|
chunkId: chunkData.chunkId ?? "",
|
|
1095
1112
|
type: "image",
|
|
1113
|
+
contentSource: chunkData.contentSource,
|
|
1096
1114
|
content: chunkData.content ?? "",
|
|
1097
1115
|
path: chunkData.path ?? "",
|
|
1098
1116
|
filePath,
|
|
@@ -1110,6 +1128,7 @@ function buildTableChunk(chunkData, filePath, html) {
|
|
|
1110
1128
|
return {
|
|
1111
1129
|
chunkId: chunkData.chunkId ?? "",
|
|
1112
1130
|
type: "table",
|
|
1131
|
+
contentSource: chunkData.contentSource,
|
|
1113
1132
|
content: chunkData.content ?? "",
|
|
1114
1133
|
path: chunkData.path ?? "",
|
|
1115
1134
|
filePath,
|
|
@@ -1124,6 +1143,9 @@ async function processChunk(zip, chunkData) {
|
|
|
1124
1143
|
if (chunkData.type === "text") {
|
|
1125
1144
|
return buildTextChunk(chunkData);
|
|
1126
1145
|
}
|
|
1146
|
+
if (chunkData.type === "page") {
|
|
1147
|
+
return buildPageChunk(chunkData);
|
|
1148
|
+
}
|
|
1127
1149
|
if (chunkData.type === "image") {
|
|
1128
1150
|
const filePath = getChunkFilePath(chunkData);
|
|
1129
1151
|
if (!filePath) {
|
|
@@ -1156,6 +1178,9 @@ async function processDirectoryChunk(directory, chunkData) {
|
|
|
1156
1178
|
if (chunkData.type === "text") {
|
|
1157
1179
|
return buildTextChunk(chunkData);
|
|
1158
1180
|
}
|
|
1181
|
+
if (chunkData.type === "page") {
|
|
1182
|
+
return buildPageChunk(chunkData);
|
|
1183
|
+
}
|
|
1159
1184
|
if (chunkData.type === "image") {
|
|
1160
1185
|
const filePath = getChunkFilePath(chunkData);
|
|
1161
1186
|
if (!filePath) {
|
|
@@ -1194,6 +1219,7 @@ function serializeChunks(chunks) {
|
|
|
1194
1219
|
const rawChunk = {
|
|
1195
1220
|
chunkId: chunk.chunkId,
|
|
1196
1221
|
type: chunk.type,
|
|
1222
|
+
contentSource: chunk.contentSource,
|
|
1197
1223
|
content: chunk.content,
|
|
1198
1224
|
path: chunk.path,
|
|
1199
1225
|
metadata: chunk.metadata
|
|
@@ -1262,7 +1288,7 @@ var Jobs = class extends BaseResource {
|
|
|
1262
1288
|
* Create a new parsing job
|
|
1263
1289
|
*/
|
|
1264
1290
|
async create(params) {
|
|
1265
|
-
const job = await this.httpClient.post("/
|
|
1291
|
+
const job = await this.httpClient.post(this.endpoint("/jobs"), params);
|
|
1266
1292
|
if (job.uploadUrl) {
|
|
1267
1293
|
this.pendingUploadJobs.set(job.jobId, job);
|
|
1268
1294
|
}
|
|
@@ -1272,7 +1298,7 @@ var Jobs = class extends BaseResource {
|
|
|
1272
1298
|
* Get job status
|
|
1273
1299
|
*/
|
|
1274
1300
|
async get(jobId) {
|
|
1275
|
-
const jobResult = await this.httpClient.get(`/
|
|
1301
|
+
const jobResult = await this.httpClient.get(this.endpoint(`/jobs/${jobId}`));
|
|
1276
1302
|
enrichJobResult(jobResult);
|
|
1277
1303
|
return jobResult;
|
|
1278
1304
|
}
|
|
@@ -1368,7 +1394,7 @@ var Retrieval = class extends BaseResource {
|
|
|
1368
1394
|
* Query published documents.
|
|
1369
1395
|
*/
|
|
1370
1396
|
async query(params) {
|
|
1371
|
-
return this.httpClient.post("/
|
|
1397
|
+
return this.httpClient.post(this.endpoint("/retrieval/query"), params);
|
|
1372
1398
|
}
|
|
1373
1399
|
};
|
|
1374
1400
|
|
|
@@ -1378,25 +1404,24 @@ var Documents = class extends BaseResource {
|
|
|
1378
1404
|
* List canonical documents in a namespace.
|
|
1379
1405
|
*/
|
|
1380
1406
|
async list(params) {
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
return this.httpClient.get("/v1/documents", requestConfig);
|
|
1407
|
+
const response = await this.httpClient.get(
|
|
1408
|
+
this.endpoint("/documents"),
|
|
1409
|
+
this.createDocumentListRequestConfig(params)
|
|
1410
|
+
);
|
|
1411
|
+
return this.normalizeDocumentListResponse(response);
|
|
1387
1412
|
}
|
|
1388
1413
|
/**
|
|
1389
1414
|
* Get one canonical document by ID.
|
|
1390
1415
|
*/
|
|
1391
1416
|
async get(documentId) {
|
|
1392
|
-
return this.httpClient.get(`/
|
|
1417
|
+
return this.httpClient.get(this.endpoint(`/documents/${documentId}`));
|
|
1393
1418
|
}
|
|
1394
1419
|
/**
|
|
1395
1420
|
* List current-revision chunks for one canonical document.
|
|
1396
1421
|
*/
|
|
1397
1422
|
async listChunks(documentId, params) {
|
|
1398
1423
|
return this.httpClient.get(
|
|
1399
|
-
`/
|
|
1424
|
+
this.endpoint(`/documents/${documentId}/chunks`),
|
|
1400
1425
|
this.createChunkListRequestConfig(params)
|
|
1401
1426
|
);
|
|
1402
1427
|
}
|
|
@@ -1405,7 +1430,7 @@ var Documents = class extends BaseResource {
|
|
|
1405
1430
|
*/
|
|
1406
1431
|
async getChunk(documentId, documentChunkId, params) {
|
|
1407
1432
|
return this.httpClient.get(
|
|
1408
|
-
`/
|
|
1433
|
+
this.endpoint(`/documents/${documentId}/chunks/${documentChunkId}`),
|
|
1409
1434
|
this.createChunkGetRequestConfig(params)
|
|
1410
1435
|
);
|
|
1411
1436
|
}
|
|
@@ -1413,7 +1438,39 @@ var Documents = class extends BaseResource {
|
|
|
1413
1438
|
* Archive one canonical document by ID.
|
|
1414
1439
|
*/
|
|
1415
1440
|
async archive(documentId) {
|
|
1416
|
-
return this.httpClient.post(`/
|
|
1441
|
+
return this.httpClient.post(this.endpoint(`/documents/${documentId}/archive`));
|
|
1442
|
+
}
|
|
1443
|
+
createDocumentListRequestConfig(params) {
|
|
1444
|
+
if (!params) {
|
|
1445
|
+
return void 0;
|
|
1446
|
+
}
|
|
1447
|
+
const queryParams = {};
|
|
1448
|
+
if (params.namespace !== void 0) {
|
|
1449
|
+
queryParams.namespace = params.namespace;
|
|
1450
|
+
}
|
|
1451
|
+
if (params.page !== void 0) {
|
|
1452
|
+
queryParams.page = params.page;
|
|
1453
|
+
}
|
|
1454
|
+
if (params.pageSize !== void 0) {
|
|
1455
|
+
queryParams.page_size = params.pageSize;
|
|
1456
|
+
}
|
|
1457
|
+
return Object.keys(queryParams).length > 0 ? { params: queryParams } : void 0;
|
|
1458
|
+
}
|
|
1459
|
+
normalizeDocumentListResponse(response) {
|
|
1460
|
+
const maybePaginatedResponse = response;
|
|
1461
|
+
if (maybePaginatedResponse.pagination) {
|
|
1462
|
+
return response;
|
|
1463
|
+
}
|
|
1464
|
+
const total = response.documents.length;
|
|
1465
|
+
return {
|
|
1466
|
+
...response,
|
|
1467
|
+
pagination: {
|
|
1468
|
+
page: 1,
|
|
1469
|
+
pageSize: total,
|
|
1470
|
+
total,
|
|
1471
|
+
totalPages: total > 0 ? 1 : 0
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1417
1474
|
}
|
|
1418
1475
|
createChunkListRequestConfig(params) {
|
|
1419
1476
|
if (!params) {
|
|
@@ -1429,18 +1486,18 @@ var Documents = class extends BaseResource {
|
|
|
1429
1486
|
if (params.chunkType !== void 0) {
|
|
1430
1487
|
queryParams.chunk_type = params.chunkType;
|
|
1431
1488
|
}
|
|
1432
|
-
if (params.includeAssetUrls
|
|
1433
|
-
queryParams.include_asset_urls =
|
|
1489
|
+
if (params.includeAssetUrls !== void 0) {
|
|
1490
|
+
queryParams.include_asset_urls = params.includeAssetUrls;
|
|
1434
1491
|
}
|
|
1435
1492
|
return Object.keys(queryParams).length > 0 ? { params: queryParams } : void 0;
|
|
1436
1493
|
}
|
|
1437
1494
|
createChunkGetRequestConfig(params) {
|
|
1438
|
-
if (params?.includeAssetUrls
|
|
1495
|
+
if (params?.includeAssetUrls === void 0) {
|
|
1439
1496
|
return void 0;
|
|
1440
1497
|
}
|
|
1441
1498
|
return {
|
|
1442
1499
|
params: {
|
|
1443
|
-
include_asset_urls:
|
|
1500
|
+
include_asset_urls: params.includeAssetUrls
|
|
1444
1501
|
}
|
|
1445
1502
|
};
|
|
1446
1503
|
}
|
|
@@ -1643,7 +1700,7 @@ function countChunkTypes(result) {
|
|
|
1643
1700
|
counts[chunk.type] += 1;
|
|
1644
1701
|
return counts;
|
|
1645
1702
|
},
|
|
1646
|
-
{ text: 0, image: 0, table: 0 }
|
|
1703
|
+
{ text: 0, image: 0, table: 0, page: 0 }
|
|
1647
1704
|
);
|
|
1648
1705
|
}
|
|
1649
1706
|
function toLocalKnowledgeDocument(stored) {
|
|
@@ -1970,19 +2027,40 @@ function createLocalDocumentIdForRemote(documentId) {
|
|
|
1970
2027
|
function indexChunks(result) {
|
|
1971
2028
|
return result.chunks.map((chunk, index) => {
|
|
1972
2029
|
const filePath = getChunkFilePath2(chunk);
|
|
2030
|
+
const readableContent = getReadableChunkContent(chunk);
|
|
1973
2031
|
return {
|
|
1974
2032
|
source: chunk,
|
|
1975
2033
|
position: index + 1,
|
|
1976
2034
|
chunkId: chunk.chunkId,
|
|
1977
2035
|
chunkType: chunk.type,
|
|
2036
|
+
contentSource: chunk.contentSource,
|
|
1978
2037
|
content: chunk.content,
|
|
2038
|
+
readableContent,
|
|
1979
2039
|
sectionPath: normalizeSectionPath(chunk.path, result.manifest.sourceFileName),
|
|
1980
2040
|
sourceChunkPath: chunk.path,
|
|
1981
2041
|
filePath,
|
|
2042
|
+
pageNumbers: getChunkPageNumbers(chunk.metadata),
|
|
1982
2043
|
metadata: chunk.metadata
|
|
1983
2044
|
};
|
|
1984
2045
|
});
|
|
1985
2046
|
}
|
|
2047
|
+
function getReadableChunkContent(chunk) {
|
|
2048
|
+
if (chunk.type !== "page") {
|
|
2049
|
+
return chunk.content;
|
|
2050
|
+
}
|
|
2051
|
+
const summary = chunk.metadata.summary;
|
|
2052
|
+
return typeof summary === "string" && summary.trim().length > 0 ? summary : chunk.content;
|
|
2053
|
+
}
|
|
2054
|
+
function getChunkPageNumbers(metadata) {
|
|
2055
|
+
const value = metadata.pageNums;
|
|
2056
|
+
if (!Array.isArray(value)) {
|
|
2057
|
+
return void 0;
|
|
2058
|
+
}
|
|
2059
|
+
const pageNumbers = value.filter(
|
|
2060
|
+
(pageNumber) => Number.isInteger(pageNumber) && pageNumber > 0
|
|
2061
|
+
);
|
|
2062
|
+
return pageNumbers.length > 0 ? [...new Set(pageNumbers)].sort((left, right) => left - right) : void 0;
|
|
2063
|
+
}
|
|
1986
2064
|
function getChunkFilePath2(chunk) {
|
|
1987
2065
|
if (chunk.type === "image" || chunk.type === "table") {
|
|
1988
2066
|
return chunk.filePath;
|
|
@@ -2056,7 +2134,7 @@ function createSectionFromChunk(pathValue, chunk) {
|
|
|
2056
2134
|
startChunk: chunk.position,
|
|
2057
2135
|
endChunk: chunk.position,
|
|
2058
2136
|
chunkCount: 1,
|
|
2059
|
-
typeCounts: { text: 0, image: 0, table: 0, [chunk.chunkType]: 1 },
|
|
2137
|
+
typeCounts: { text: 0, image: 0, table: 0, page: 0, [chunk.chunkType]: 1 },
|
|
2060
2138
|
children: []
|
|
2061
2139
|
};
|
|
2062
2140
|
}
|
|
@@ -2115,7 +2193,7 @@ function countIndexedTypes(chunks) {
|
|
|
2115
2193
|
counts[chunk.chunkType] += 1;
|
|
2116
2194
|
return counts;
|
|
2117
2195
|
},
|
|
2118
|
-
{ text: 0, image: 0, table: 0 }
|
|
2196
|
+
{ text: 0, image: 0, table: 0, page: 0 }
|
|
2119
2197
|
);
|
|
2120
2198
|
}
|
|
2121
2199
|
function isInSection(chunkSectionPath, sectionPath) {
|
|
@@ -2152,10 +2230,13 @@ function toReadChunk(chunk) {
|
|
|
2152
2230
|
position: chunk.position,
|
|
2153
2231
|
chunkId: chunk.chunkId,
|
|
2154
2232
|
chunkType: chunk.chunkType,
|
|
2233
|
+
contentSource: chunk.contentSource,
|
|
2155
2234
|
content: chunk.content,
|
|
2235
|
+
readableContent: chunk.readableContent,
|
|
2156
2236
|
sectionPath: chunk.sectionPath,
|
|
2157
2237
|
sourceChunkPath: chunk.sourceChunkPath,
|
|
2158
2238
|
filePath: chunk.filePath,
|
|
2239
|
+
pageNumbers: chunk.pageNumbers,
|
|
2159
2240
|
metadata: chunk.metadata
|
|
2160
2241
|
};
|
|
2161
2242
|
}
|
|
@@ -2207,6 +2288,7 @@ function toResultReference(result, documentByServerId) {
|
|
|
2207
2288
|
return {
|
|
2208
2289
|
localDocumentId: documentId ? documentByServerId.get(documentId)?.localDocumentId : void 0,
|
|
2209
2290
|
documentId,
|
|
2291
|
+
chunkId: result.chunkId,
|
|
2210
2292
|
sectionPath: result.source.sectionPath ?? void 0,
|
|
2211
2293
|
chunkType: result.chunkType,
|
|
2212
2294
|
score: result.score
|
|
@@ -2217,6 +2299,7 @@ function toRemoteSearchResult(result, documentByServerId) {
|
|
|
2217
2299
|
return {
|
|
2218
2300
|
localDocumentId: documentId ? documentByServerId.get(documentId)?.localDocumentId : void 0,
|
|
2219
2301
|
documentId,
|
|
2302
|
+
chunkId: result.chunkId,
|
|
2220
2303
|
chunkType: result.chunkType,
|
|
2221
2304
|
content: result.content,
|
|
2222
2305
|
score: result.score,
|