@ontos-ai/knowhere-sdk 0.2.1 → 0.3.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
@@ -104,7 +104,9 @@ const result = await client.parse({
104
104
  });
105
105
  ```
106
106
 
107
- `fileName` 会在 `file` 是本地文件路径时自动推断;当 `file` `Buffer`、`Uint8Array` 或不带路径信息的流时必须显式提供。
107
+ `fileName` is inferred automatically when `file` is a local file path. When
108
+ `file` is a `Buffer`, `Uint8Array`, or a stream without path metadata, provide
109
+ `fileName` explicitly.
108
110
 
109
111
  ### Advanced Options
110
112
 
@@ -163,6 +165,83 @@ const jobResult = await client.jobs.wait(job.jobId, {
163
165
  const result = await client.jobs.load(jobResult);
164
166
  ```
165
167
 
168
+ ### Retrieval and Document Lifecycle
169
+
170
+ Published documents are queryable through the retrieval API after a job
171
+ finishes. `client.jobs.create(...)` does not return a usable `documentId`;
172
+ persist `jobResult.documentId` after publication if you need to update or
173
+ archive the same document later.
174
+
175
+ ```typescript
176
+ const job = await client.jobs.create({
177
+ sourceType: 'url',
178
+ sourceUrl: 'https://example.com/manual.pdf',
179
+ namespace: 'support-center',
180
+ });
181
+
182
+ const jobResult = await client.jobs.wait(job.jobId);
183
+ const documentId = jobResult.documentId;
184
+
185
+ if (!documentId) {
186
+ throw new Error('Expected documentId after successful publication.');
187
+ }
188
+
189
+ console.log(documentId);
190
+
191
+ const response = await client.retrieval.query({
192
+ namespace: 'support-center',
193
+ query: 'How do I reset Bluetooth pairing?',
194
+ topK: 5,
195
+ });
196
+
197
+ for (const result of response.results) {
198
+ console.log(result.content);
199
+ console.log(result.score);
200
+ console.log(result.source.sourceFileName, result.source.sectionPath);
201
+ }
202
+ ```
203
+
204
+ Retrieval results use one canonical source object:
205
+
206
+ ```typescript
207
+ result.content;
208
+ result.chunkType;
209
+ result.score;
210
+ result.assetUrl;
211
+ result.source.documentId;
212
+ result.source.sourceFileName;
213
+ result.source.sectionPath;
214
+ ```
215
+
216
+ Use `documentId` to update or archive a document:
217
+
218
+ ```typescript
219
+ const updateJob = await client.jobs.create({
220
+ sourceType: 'url',
221
+ sourceUrl: 'https://example.com/manual-v2.pdf',
222
+ documentId,
223
+ });
224
+
225
+ const documents = await client.documents.list({ namespace: 'support-center' });
226
+ const document = await client.documents.get(documentId);
227
+ const archived = await client.documents.archive(documentId);
228
+
229
+ console.log(documents.documents.length);
230
+ console.log(document.status);
231
+ console.log(archived.status);
232
+ ```
233
+
234
+ Follow-up queries can exclude documents or sections for one request:
235
+
236
+ ```typescript
237
+ const followUp = await client.retrieval.query({
238
+ namespace: 'support-center',
239
+ query: 'battery charging',
240
+ excludeDocumentIds: ['doc_old'],
241
+ excludeSections: [{ documentId: 'doc_123', sectionPath: 'Appendix / Legal' }],
242
+ });
243
+ ```
244
+
166
245
  ### Error Handling
167
246
 
168
247
  ```typescript
@@ -213,7 +292,7 @@ Check out the [examples](./examples) directory for more usage examples:
213
292
 
214
293
  ```bash
215
294
  # Install dependencies
216
- npm install
295
+ npm ci
217
296
 
218
297
  # Run tests
219
298
  npm test
@@ -239,6 +318,12 @@ npm run build
239
318
  See [docs/release-workflow.md](./docs/release-workflow.md) for the
240
319
  Changesets-based stable and beta release process.
241
320
 
321
+ ## Community
322
+
323
+ - Contributing guide: [CONTRIBUTING.md](./CONTRIBUTING.md)
324
+ - Security policy: [SECURITY.md](./SECURITY.md)
325
+ - Code of conduct: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
326
+
242
327
  ## License
243
328
 
244
329
  [MIT](./LICENSE)
package/dist/index.d.mts CHANGED
@@ -41,6 +41,8 @@ interface Job {
41
41
  sourceType: string;
42
42
  /** Optional custom data identifier */
43
43
  dataId?: string;
44
+ /** Retrieval namespace for the canonical document */
45
+ namespace?: string;
44
46
  /** Job creation timestamp */
45
47
  createdAt: Date;
46
48
  /** Presigned URL for file upload (if sourceType is 'file') */
@@ -75,6 +77,10 @@ interface JobResult {
75
77
  sourceType: string;
76
78
  /** Optional custom data identifier */
77
79
  dataId?: string;
80
+ /** Retrieval namespace for the canonical document */
81
+ namespace?: string;
82
+ /** Stable document identifier for retrieval/document lifecycle APIs */
83
+ documentId?: string;
78
84
  /** Job creation timestamp */
79
85
  createdAt: Date;
80
86
  /** Processing progress information */
@@ -157,6 +163,10 @@ interface CreateJobParams {
157
163
  fileName?: string;
158
164
  /** Optional custom data identifier */
159
165
  dataId?: string;
166
+ /** Retrieval namespace for the canonical document */
167
+ namespace?: string;
168
+ /** Existing document identifier when updating a published document */
169
+ documentId?: string;
160
170
  /** Parsing configuration */
161
171
  parsingParams?: ParsingParams;
162
172
  /** Webhook configuration */
@@ -219,6 +229,10 @@ interface ParseParams {
219
229
  summaryTxt?: boolean;
220
230
  /** Custom data identifier */
221
231
  dataId?: string;
232
+ /** Retrieval namespace for the canonical document */
233
+ namespace?: string;
234
+ /** Existing document identifier when updating a published document */
235
+ documentId?: string;
222
236
  /** Additional fragment description */
223
237
  addFragDesc?: string;
224
238
  /** Knowledge base directory */
@@ -458,6 +472,10 @@ interface ParseResult {
458
472
  readonly tableChunks: TableChunk[];
459
473
  /** Job ID */
460
474
  readonly jobId: string;
475
+ /** Effective retrieval namespace when loaded from a job result */
476
+ namespace?: string;
477
+ /** Canonical document identifier when loaded from a job result */
478
+ documentId?: string;
461
479
  /** Statistics */
462
480
  readonly statistics: Statistics;
463
481
  /** Find a specific chunk by ID */
@@ -566,12 +584,165 @@ declare class Jobs extends BaseResource {
566
584
  private resolveLoadJobResult;
567
585
  }
568
586
 
587
+ /**
588
+ * Section exclusion for follow-up retrieval queries.
589
+ */
590
+ interface RetrievalSectionExclusion {
591
+ /** Document containing the section to exclude */
592
+ documentId: string;
593
+ /** Human-readable section path to exclude */
594
+ sectionPath: string;
595
+ }
596
+ /**
597
+ * Supported retrieval channel names.
598
+ */
599
+ type RetrievalChannel = 'path' | 'content' | 'term';
600
+ /**
601
+ * Path filtering mode for retrieval queries.
602
+ */
603
+ type RetrievalFilterMode = 'delete' | 'keep';
604
+ /**
605
+ * Retrieval query parameters.
606
+ */
607
+ interface RetrievalQueryParams {
608
+ /** Search query text */
609
+ query: string;
610
+ /** Retrieval namespace. Defaults to the server's default namespace when omitted. */
611
+ namespace?: string;
612
+ /** Maximum number of results to return */
613
+ topK?: number;
614
+ /** Chunk type filter: 1=all, 2=text, 3=image, 4=table, 5=text+image, 6=text+table */
615
+ dataType?: 1 | 2 | 3 | 4 | 5 | 6;
616
+ /** Path keywords for include/exclude filtering */
617
+ signalPaths?: string[];
618
+ /** Signal path filter mode */
619
+ filterMode?: RetrievalFilterMode;
620
+ /** Retrieval channels to run. Defaults to all channels when omitted. */
621
+ channels?: RetrievalChannel[];
622
+ /** Per-channel weight overrides for reciprocal-rank fusion */
623
+ channelWeights?: Partial<Record<RetrievalChannel, number>>;
624
+ /** Enable LLM reranking after channel fusion */
625
+ rerank?: boolean;
626
+ /** Minimum retrieval score threshold after fusion */
627
+ threshold?: number;
628
+ /** Override the internal per-channel recall count */
629
+ internalRecallK?: number;
630
+ /** Documents to exclude for this request only */
631
+ excludeDocumentIds?: string[];
632
+ /** Document sections to exclude for this request only */
633
+ excludeSections?: RetrievalSectionExclusion[];
634
+ }
635
+ /**
636
+ * Caller-facing source reference attached to a retrieval result.
637
+ */
638
+ interface RetrievalSource {
639
+ /** Stable document identifier */
640
+ documentId?: string;
641
+ /** Original source file name */
642
+ sourceFileName?: string;
643
+ /** Human-readable section path */
644
+ sectionPath?: string;
645
+ }
646
+ /**
647
+ * Canonical chunk result returned by retrieval query.
648
+ */
649
+ interface RetrievalResult {
650
+ /** Knowledge content to use directly in the caller's answer */
651
+ content: string;
652
+ /** Chunk type, for example text, image, or table */
653
+ chunkType: string;
654
+ /** Retrieval score returned by the API */
655
+ score: number;
656
+ /** Presigned asset URL for media chunks when available */
657
+ assetUrl?: string;
658
+ /** Source reference for this result */
659
+ source: RetrievalSource;
660
+ }
661
+ /**
662
+ * Response from POST /v1/retrieval/query.
663
+ */
664
+ interface RetrievalQueryResponse {
665
+ /** Namespace searched by the API */
666
+ namespace: string;
667
+ /** Echoed query text */
668
+ query: string;
669
+ /** Retrieval router path used by the API for this query */
670
+ routerUsed?: string;
671
+ /** Ranked retrieval results */
672
+ results: RetrievalResult[];
673
+ }
674
+
675
+ /**
676
+ * Resource for querying published retrieval documents.
677
+ */
678
+ declare class Retrieval extends BaseResource {
679
+ /**
680
+ * Query published documents.
681
+ */
682
+ query(params: RetrievalQueryParams): Promise<RetrievalQueryResponse>;
683
+ }
684
+
685
+ /**
686
+ * Canonical document state returned by document lifecycle endpoints.
687
+ */
688
+ interface Document {
689
+ /** Stable document identifier */
690
+ documentId: string;
691
+ /** Retrieval namespace */
692
+ namespace: string;
693
+ /** Current lifecycle status */
694
+ status: string;
695
+ /** Current published job result identifier */
696
+ currentJobResultId?: string;
697
+ /** Original source file name */
698
+ sourceFileName?: string;
699
+ /** Document creation timestamp */
700
+ createdAt?: Date;
701
+ /** Last update timestamp */
702
+ updatedAt?: Date;
703
+ /** Archive timestamp, when archived */
704
+ archivedAt?: Date;
705
+ }
706
+ /**
707
+ * Response from GET /v1/documents.
708
+ */
709
+ interface DocumentListResponse {
710
+ /** Namespace listed by the API */
711
+ namespace: string;
712
+ /** Documents visible in the namespace */
713
+ documents: Document[];
714
+ }
715
+
716
+ /**
717
+ * Resource for canonical document lifecycle operations.
718
+ */
719
+ declare class Documents extends BaseResource {
720
+ /**
721
+ * List canonical documents in a namespace.
722
+ */
723
+ list(params?: {
724
+ namespace?: string;
725
+ }): Promise<DocumentListResponse>;
726
+ /**
727
+ * Get one canonical document by ID.
728
+ */
729
+ get(documentId: string): Promise<Document>;
730
+ /**
731
+ * Archive one canonical document by ID.
732
+ */
733
+ archive(documentId: string): Promise<Document>;
734
+ }
735
+
569
736
  /**
570
737
  * Main Knowhere SDK client
571
738
  */
572
739
  declare class Knowhere {
573
740
  /** Jobs resource for low-level API */
574
741
  readonly jobs: Jobs;
742
+ /** Retrieval resource for querying published documents */
743
+ readonly retrieval: Retrieval;
744
+ /** Documents resource for canonical document lifecycle operations */
745
+ readonly documents: Documents;
575
746
  private httpClient;
576
747
  /**
577
748
  * Create a new Knowhere client
@@ -731,4 +902,4 @@ declare class JobFailedError extends KnowhereError {
731
902
  constructor(message: string, code: string, jobResult: JobResult);
732
903
  }
733
904
 
734
- export { APIError, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, type LoadOptions, type Manifest, NetworkError, NotFoundError, type ParseParams, type ParseResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default };
905
+ export { APIError, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type Document, type DocumentListResponse, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, type LoadOptions, 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 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
@@ -41,6 +41,8 @@ interface Job {
41
41
  sourceType: string;
42
42
  /** Optional custom data identifier */
43
43
  dataId?: string;
44
+ /** Retrieval namespace for the canonical document */
45
+ namespace?: string;
44
46
  /** Job creation timestamp */
45
47
  createdAt: Date;
46
48
  /** Presigned URL for file upload (if sourceType is 'file') */
@@ -75,6 +77,10 @@ interface JobResult {
75
77
  sourceType: string;
76
78
  /** Optional custom data identifier */
77
79
  dataId?: string;
80
+ /** Retrieval namespace for the canonical document */
81
+ namespace?: string;
82
+ /** Stable document identifier for retrieval/document lifecycle APIs */
83
+ documentId?: string;
78
84
  /** Job creation timestamp */
79
85
  createdAt: Date;
80
86
  /** Processing progress information */
@@ -157,6 +163,10 @@ interface CreateJobParams {
157
163
  fileName?: string;
158
164
  /** Optional custom data identifier */
159
165
  dataId?: string;
166
+ /** Retrieval namespace for the canonical document */
167
+ namespace?: string;
168
+ /** Existing document identifier when updating a published document */
169
+ documentId?: string;
160
170
  /** Parsing configuration */
161
171
  parsingParams?: ParsingParams;
162
172
  /** Webhook configuration */
@@ -219,6 +229,10 @@ interface ParseParams {
219
229
  summaryTxt?: boolean;
220
230
  /** Custom data identifier */
221
231
  dataId?: string;
232
+ /** Retrieval namespace for the canonical document */
233
+ namespace?: string;
234
+ /** Existing document identifier when updating a published document */
235
+ documentId?: string;
222
236
  /** Additional fragment description */
223
237
  addFragDesc?: string;
224
238
  /** Knowledge base directory */
@@ -458,6 +472,10 @@ interface ParseResult {
458
472
  readonly tableChunks: TableChunk[];
459
473
  /** Job ID */
460
474
  readonly jobId: string;
475
+ /** Effective retrieval namespace when loaded from a job result */
476
+ namespace?: string;
477
+ /** Canonical document identifier when loaded from a job result */
478
+ documentId?: string;
461
479
  /** Statistics */
462
480
  readonly statistics: Statistics;
463
481
  /** Find a specific chunk by ID */
@@ -566,12 +584,165 @@ declare class Jobs extends BaseResource {
566
584
  private resolveLoadJobResult;
567
585
  }
568
586
 
587
+ /**
588
+ * Section exclusion for follow-up retrieval queries.
589
+ */
590
+ interface RetrievalSectionExclusion {
591
+ /** Document containing the section to exclude */
592
+ documentId: string;
593
+ /** Human-readable section path to exclude */
594
+ sectionPath: string;
595
+ }
596
+ /**
597
+ * Supported retrieval channel names.
598
+ */
599
+ type RetrievalChannel = 'path' | 'content' | 'term';
600
+ /**
601
+ * Path filtering mode for retrieval queries.
602
+ */
603
+ type RetrievalFilterMode = 'delete' | 'keep';
604
+ /**
605
+ * Retrieval query parameters.
606
+ */
607
+ interface RetrievalQueryParams {
608
+ /** Search query text */
609
+ query: string;
610
+ /** Retrieval namespace. Defaults to the server's default namespace when omitted. */
611
+ namespace?: string;
612
+ /** Maximum number of results to return */
613
+ topK?: number;
614
+ /** Chunk type filter: 1=all, 2=text, 3=image, 4=table, 5=text+image, 6=text+table */
615
+ dataType?: 1 | 2 | 3 | 4 | 5 | 6;
616
+ /** Path keywords for include/exclude filtering */
617
+ signalPaths?: string[];
618
+ /** Signal path filter mode */
619
+ filterMode?: RetrievalFilterMode;
620
+ /** Retrieval channels to run. Defaults to all channels when omitted. */
621
+ channels?: RetrievalChannel[];
622
+ /** Per-channel weight overrides for reciprocal-rank fusion */
623
+ channelWeights?: Partial<Record<RetrievalChannel, number>>;
624
+ /** Enable LLM reranking after channel fusion */
625
+ rerank?: boolean;
626
+ /** Minimum retrieval score threshold after fusion */
627
+ threshold?: number;
628
+ /** Override the internal per-channel recall count */
629
+ internalRecallK?: number;
630
+ /** Documents to exclude for this request only */
631
+ excludeDocumentIds?: string[];
632
+ /** Document sections to exclude for this request only */
633
+ excludeSections?: RetrievalSectionExclusion[];
634
+ }
635
+ /**
636
+ * Caller-facing source reference attached to a retrieval result.
637
+ */
638
+ interface RetrievalSource {
639
+ /** Stable document identifier */
640
+ documentId?: string;
641
+ /** Original source file name */
642
+ sourceFileName?: string;
643
+ /** Human-readable section path */
644
+ sectionPath?: string;
645
+ }
646
+ /**
647
+ * Canonical chunk result returned by retrieval query.
648
+ */
649
+ interface RetrievalResult {
650
+ /** Knowledge content to use directly in the caller's answer */
651
+ content: string;
652
+ /** Chunk type, for example text, image, or table */
653
+ chunkType: string;
654
+ /** Retrieval score returned by the API */
655
+ score: number;
656
+ /** Presigned asset URL for media chunks when available */
657
+ assetUrl?: string;
658
+ /** Source reference for this result */
659
+ source: RetrievalSource;
660
+ }
661
+ /**
662
+ * Response from POST /v1/retrieval/query.
663
+ */
664
+ interface RetrievalQueryResponse {
665
+ /** Namespace searched by the API */
666
+ namespace: string;
667
+ /** Echoed query text */
668
+ query: string;
669
+ /** Retrieval router path used by the API for this query */
670
+ routerUsed?: string;
671
+ /** Ranked retrieval results */
672
+ results: RetrievalResult[];
673
+ }
674
+
675
+ /**
676
+ * Resource for querying published retrieval documents.
677
+ */
678
+ declare class Retrieval extends BaseResource {
679
+ /**
680
+ * Query published documents.
681
+ */
682
+ query(params: RetrievalQueryParams): Promise<RetrievalQueryResponse>;
683
+ }
684
+
685
+ /**
686
+ * Canonical document state returned by document lifecycle endpoints.
687
+ */
688
+ interface Document {
689
+ /** Stable document identifier */
690
+ documentId: string;
691
+ /** Retrieval namespace */
692
+ namespace: string;
693
+ /** Current lifecycle status */
694
+ status: string;
695
+ /** Current published job result identifier */
696
+ currentJobResultId?: string;
697
+ /** Original source file name */
698
+ sourceFileName?: string;
699
+ /** Document creation timestamp */
700
+ createdAt?: Date;
701
+ /** Last update timestamp */
702
+ updatedAt?: Date;
703
+ /** Archive timestamp, when archived */
704
+ archivedAt?: Date;
705
+ }
706
+ /**
707
+ * Response from GET /v1/documents.
708
+ */
709
+ interface DocumentListResponse {
710
+ /** Namespace listed by the API */
711
+ namespace: string;
712
+ /** Documents visible in the namespace */
713
+ documents: Document[];
714
+ }
715
+
716
+ /**
717
+ * Resource for canonical document lifecycle operations.
718
+ */
719
+ declare class Documents extends BaseResource {
720
+ /**
721
+ * List canonical documents in a namespace.
722
+ */
723
+ list(params?: {
724
+ namespace?: string;
725
+ }): Promise<DocumentListResponse>;
726
+ /**
727
+ * Get one canonical document by ID.
728
+ */
729
+ get(documentId: string): Promise<Document>;
730
+ /**
731
+ * Archive one canonical document by ID.
732
+ */
733
+ archive(documentId: string): Promise<Document>;
734
+ }
735
+
569
736
  /**
570
737
  * Main Knowhere SDK client
571
738
  */
572
739
  declare class Knowhere {
573
740
  /** Jobs resource for low-level API */
574
741
  readonly jobs: Jobs;
742
+ /** Retrieval resource for querying published documents */
743
+ readonly retrieval: Retrieval;
744
+ /** Documents resource for canonical document lifecycle operations */
745
+ readonly documents: Documents;
575
746
  private httpClient;
576
747
  /**
577
748
  * Create a new Knowhere client
@@ -731,4 +902,4 @@ declare class JobFailedError extends KnowhereError {
731
902
  constructor(message: string, code: string, jobResult: JobResult);
732
903
  }
733
904
 
734
- export { APIError, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, type LoadOptions, type Manifest, NetworkError, NotFoundError, type ParseParams, type ParseResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default };
905
+ export { APIError, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, type DocType, type Document, type DocumentListResponse, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, KnowhereError, type KnowhereOptions, type LoadOptions, 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 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
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  BadRequestError: () => BadRequestError,
36
36
  ChecksumError: () => ChecksumError,
37
37
  ConflictError: () => ConflictError,
38
+ Documents: () => Documents,
38
39
  GatewayTimeoutError: () => GatewayTimeoutError,
39
40
  InternalServerError: () => InternalServerError,
40
41
  InvalidStateError: () => InvalidStateError,
@@ -48,6 +49,7 @@ __export(index_exports, {
48
49
  PermissionDeniedError: () => PermissionDeniedError,
49
50
  PollingTimeoutError: () => PollingTimeoutError,
50
51
  RateLimitError: () => RateLimitError,
52
+ Retrieval: () => Retrieval,
51
53
  ServiceUnavailableError: () => ServiceUnavailableError,
52
54
  TimeoutError: () => TimeoutError,
53
55
  VERSION: () => VERSION,
@@ -344,6 +346,15 @@ function enrichJobResult(jobResult) {
344
346
  }
345
347
  return jobResult;
346
348
  }
349
+ function enrichParseResult(parseResult2, scope) {
350
+ if (scope.namespace !== void 0) {
351
+ parseResult2.namespace = scope.namespace;
352
+ }
353
+ if (scope.documentId !== void 0) {
354
+ parseResult2.documentId = scope.documentId;
355
+ }
356
+ return parseResult2;
357
+ }
347
358
  function sanitizePath(path2) {
348
359
  let sanitized = path2.replace(/^\/+/, "");
349
360
  sanitized = sanitized.replace(/\.\.(\/|\\)/g, "");
@@ -1075,7 +1086,11 @@ var Jobs = class extends BaseResource {
1075
1086
  * Create a new parsing job
1076
1087
  */
1077
1088
  async create(params) {
1078
- const job = await this.httpClient.post("/v1/jobs", params);
1089
+ const job = await this.httpClient.post(
1090
+ "/v1/jobs",
1091
+ params
1092
+ );
1093
+ delete job.documentId;
1079
1094
  if (job.uploadUrl) {
1080
1095
  this.pendingUploadJobs.set(job.jobId, job);
1081
1096
  }
@@ -1123,7 +1138,8 @@ var Jobs = class extends BaseResource {
1123
1138
  if (!jobResult.resultUrl) {
1124
1139
  throw new NotFoundError("Result URL not available");
1125
1140
  }
1126
- return parseResult(this.httpClient, jobResult.resultUrl, options);
1141
+ const result = await parseResult(this.httpClient, jobResult.resultUrl, options);
1142
+ return enrichParseResult(result, jobResult);
1127
1143
  }
1128
1144
  isHttpUrl(value) {
1129
1145
  return /^https?:\/\//i.test(value);
@@ -1174,6 +1190,43 @@ var Jobs = class extends BaseResource {
1174
1190
  }
1175
1191
  };
1176
1192
 
1193
+ // src/resources/retrieval.ts
1194
+ var Retrieval = class extends BaseResource {
1195
+ /**
1196
+ * Query published documents.
1197
+ */
1198
+ async query(params) {
1199
+ return this.httpClient.post("/v1/retrieval/query", params);
1200
+ }
1201
+ };
1202
+
1203
+ // src/resources/documents.ts
1204
+ var Documents = class extends BaseResource {
1205
+ /**
1206
+ * List canonical documents in a namespace.
1207
+ */
1208
+ async list(params) {
1209
+ const requestConfig = params?.namespace ? {
1210
+ params: {
1211
+ namespace: params.namespace
1212
+ }
1213
+ } : void 0;
1214
+ return this.httpClient.get("/v1/documents", requestConfig);
1215
+ }
1216
+ /**
1217
+ * Get one canonical document by ID.
1218
+ */
1219
+ async get(documentId) {
1220
+ return this.httpClient.get(`/v1/documents/${documentId}`);
1221
+ }
1222
+ /**
1223
+ * Archive one canonical document by ID.
1224
+ */
1225
+ async archive(documentId) {
1226
+ return this.httpClient.post(`/v1/documents/${documentId}/archive`);
1227
+ }
1228
+ };
1229
+
1177
1230
  // src/client.ts
1178
1231
  function inferFileName(file, explicitFileName) {
1179
1232
  if (explicitFileName) {
@@ -1193,6 +1246,10 @@ function isReadStream2(file) {
1193
1246
  var Knowhere = class {
1194
1247
  /** Jobs resource for low-level API */
1195
1248
  jobs;
1249
+ /** Retrieval resource for querying published documents */
1250
+ retrieval;
1251
+ /** Documents resource for canonical document lifecycle operations */
1252
+ documents;
1196
1253
  httpClient;
1197
1254
  /**
1198
1255
  * Create a new Knowhere client
@@ -1216,6 +1273,8 @@ var Knowhere = class {
1216
1273
  httpsAgent: options.httpsAgent
1217
1274
  });
1218
1275
  this.jobs = new Jobs(this.httpClient);
1276
+ this.retrieval = new Retrieval(this.httpClient);
1277
+ this.documents = new Documents(this.httpClient);
1219
1278
  }
1220
1279
  /**
1221
1280
  * High-level API: Parse a document and return structured results
@@ -1273,6 +1332,8 @@ var Knowhere = class {
1273
1332
  sourceUrl: params.url,
1274
1333
  fileName: resolvedFileName,
1275
1334
  dataId: params.dataId,
1335
+ namespace: params.namespace,
1336
+ documentId: params.documentId,
1276
1337
  parsingParams: Object.keys(parsingParams).length > 0 ? parsingParams : void 0,
1277
1338
  webhook
1278
1339
  });
@@ -1292,7 +1353,7 @@ var Knowhere = class {
1292
1353
  const result = await this.jobs.load(jobResult, {
1293
1354
  verifyChecksum: params.verifyChecksum
1294
1355
  });
1295
- return result;
1356
+ return enrichParseResult(result, jobResult);
1296
1357
  }
1297
1358
  };
1298
1359
  // Annotate the CommonJS export names for ESM import in node:
@@ -1302,6 +1363,7 @@ var Knowhere = class {
1302
1363
  BadRequestError,
1303
1364
  ChecksumError,
1304
1365
  ConflictError,
1366
+ Documents,
1305
1367
  GatewayTimeoutError,
1306
1368
  InternalServerError,
1307
1369
  InvalidStateError,
@@ -1315,6 +1377,7 @@ var Knowhere = class {
1315
1377
  PermissionDeniedError,
1316
1378
  PollingTimeoutError,
1317
1379
  RateLimitError,
1380
+ Retrieval,
1318
1381
  ServiceUnavailableError,
1319
1382
  TimeoutError,
1320
1383
  VERSION,
package/dist/index.mjs CHANGED
@@ -286,6 +286,15 @@ function enrichJobResult(jobResult) {
286
286
  }
287
287
  return jobResult;
288
288
  }
289
+ function enrichParseResult(parseResult2, scope) {
290
+ if (scope.namespace !== void 0) {
291
+ parseResult2.namespace = scope.namespace;
292
+ }
293
+ if (scope.documentId !== void 0) {
294
+ parseResult2.documentId = scope.documentId;
295
+ }
296
+ return parseResult2;
297
+ }
289
298
  function sanitizePath(path2) {
290
299
  let sanitized = path2.replace(/^\/+/, "");
291
300
  sanitized = sanitized.replace(/\.\.(\/|\\)/g, "");
@@ -1017,7 +1026,11 @@ var Jobs = class extends BaseResource {
1017
1026
  * Create a new parsing job
1018
1027
  */
1019
1028
  async create(params) {
1020
- const job = await this.httpClient.post("/v1/jobs", params);
1029
+ const job = await this.httpClient.post(
1030
+ "/v1/jobs",
1031
+ params
1032
+ );
1033
+ delete job.documentId;
1021
1034
  if (job.uploadUrl) {
1022
1035
  this.pendingUploadJobs.set(job.jobId, job);
1023
1036
  }
@@ -1065,7 +1078,8 @@ var Jobs = class extends BaseResource {
1065
1078
  if (!jobResult.resultUrl) {
1066
1079
  throw new NotFoundError("Result URL not available");
1067
1080
  }
1068
- return parseResult(this.httpClient, jobResult.resultUrl, options);
1081
+ const result = await parseResult(this.httpClient, jobResult.resultUrl, options);
1082
+ return enrichParseResult(result, jobResult);
1069
1083
  }
1070
1084
  isHttpUrl(value) {
1071
1085
  return /^https?:\/\//i.test(value);
@@ -1116,6 +1130,43 @@ var Jobs = class extends BaseResource {
1116
1130
  }
1117
1131
  };
1118
1132
 
1133
+ // src/resources/retrieval.ts
1134
+ var Retrieval = class extends BaseResource {
1135
+ /**
1136
+ * Query published documents.
1137
+ */
1138
+ async query(params) {
1139
+ return this.httpClient.post("/v1/retrieval/query", params);
1140
+ }
1141
+ };
1142
+
1143
+ // src/resources/documents.ts
1144
+ var Documents = class extends BaseResource {
1145
+ /**
1146
+ * List canonical documents in a namespace.
1147
+ */
1148
+ async list(params) {
1149
+ const requestConfig = params?.namespace ? {
1150
+ params: {
1151
+ namespace: params.namespace
1152
+ }
1153
+ } : void 0;
1154
+ return this.httpClient.get("/v1/documents", requestConfig);
1155
+ }
1156
+ /**
1157
+ * Get one canonical document by ID.
1158
+ */
1159
+ async get(documentId) {
1160
+ return this.httpClient.get(`/v1/documents/${documentId}`);
1161
+ }
1162
+ /**
1163
+ * Archive one canonical document by ID.
1164
+ */
1165
+ async archive(documentId) {
1166
+ return this.httpClient.post(`/v1/documents/${documentId}/archive`);
1167
+ }
1168
+ };
1169
+
1119
1170
  // src/client.ts
1120
1171
  function inferFileName(file, explicitFileName) {
1121
1172
  if (explicitFileName) {
@@ -1135,6 +1186,10 @@ function isReadStream2(file) {
1135
1186
  var Knowhere = class {
1136
1187
  /** Jobs resource for low-level API */
1137
1188
  jobs;
1189
+ /** Retrieval resource for querying published documents */
1190
+ retrieval;
1191
+ /** Documents resource for canonical document lifecycle operations */
1192
+ documents;
1138
1193
  httpClient;
1139
1194
  /**
1140
1195
  * Create a new Knowhere client
@@ -1158,6 +1213,8 @@ var Knowhere = class {
1158
1213
  httpsAgent: options.httpsAgent
1159
1214
  });
1160
1215
  this.jobs = new Jobs(this.httpClient);
1216
+ this.retrieval = new Retrieval(this.httpClient);
1217
+ this.documents = new Documents(this.httpClient);
1161
1218
  }
1162
1219
  /**
1163
1220
  * High-level API: Parse a document and return structured results
@@ -1215,6 +1272,8 @@ var Knowhere = class {
1215
1272
  sourceUrl: params.url,
1216
1273
  fileName: resolvedFileName,
1217
1274
  dataId: params.dataId,
1275
+ namespace: params.namespace,
1276
+ documentId: params.documentId,
1218
1277
  parsingParams: Object.keys(parsingParams).length > 0 ? parsingParams : void 0,
1219
1278
  webhook
1220
1279
  });
@@ -1234,7 +1293,7 @@ var Knowhere = class {
1234
1293
  const result = await this.jobs.load(jobResult, {
1235
1294
  verifyChecksum: params.verifyChecksum
1236
1295
  });
1237
- return result;
1296
+ return enrichParseResult(result, jobResult);
1238
1297
  }
1239
1298
  };
1240
1299
  export {
@@ -1243,6 +1302,7 @@ export {
1243
1302
  BadRequestError,
1244
1303
  ChecksumError,
1245
1304
  ConflictError,
1305
+ Documents,
1246
1306
  GatewayTimeoutError,
1247
1307
  InternalServerError,
1248
1308
  InvalidStateError,
@@ -1256,6 +1316,7 @@ export {
1256
1316
  PermissionDeniedError,
1257
1317
  PollingTimeoutError,
1258
1318
  RateLimitError,
1319
+ Retrieval,
1259
1320
  ServiceUnavailableError,
1260
1321
  TimeoutError,
1261
1322
  VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontos-ai/knowhere-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Official Node.js SDK for Knowhere document parsing API",
5
5
  "keywords": [
6
6
  "knowhere",
@@ -60,17 +60,18 @@
60
60
  "prepublishOnly": "npm run lint && npm run typecheck && npm run test:ci && npm run build"
61
61
  },
62
62
  "dependencies": {
63
- "axios": "^1.6.0",
63
+ "axios": "^1.15.2",
64
64
  "jszip": "^3.10.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@changesets/changelog-github": "^0.6.0",
68
68
  "@changesets/cli": "^2.30.0",
69
+ "@eslint/js": "^10.0.1",
69
70
  "@types/node": "^25.2.3",
70
71
  "@typescript-eslint/eslint-plugin": "^8.55.0",
71
72
  "@typescript-eslint/parser": "^8.55.0",
72
73
  "@vitest/coverage-v8": "^4.0.18",
73
- "eslint": "^9.39.2",
74
+ "eslint": "^10.2.1",
74
75
  "prettier": "^3.0.0",
75
76
  "tsup": "^8.0.0",
76
77
  "typescript": "^5.3.0",