@ontos-ai/knowhere-sdk 0.3.0 → 0.4.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 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
 
@@ -222,10 +224,22 @@ const updateJob = await client.jobs.create({
222
224
 
223
225
  const documents = await client.documents.list({ namespace: 'support-center' });
224
226
  const document = await client.documents.get(documentId);
227
+ const chunks = await client.documents.listChunks(documentId, {
228
+ page: 1,
229
+ pageSize: 50,
230
+ chunkType: 'text',
231
+ });
225
232
  const archived = await client.documents.archive(documentId);
226
233
 
227
234
  console.log(documents.documents.length);
228
235
  console.log(document.status);
236
+ console.log(chunks.pagination.total);
237
+ if (chunks.chunks[0]) {
238
+ const chunk = await client.documents.getChunk(documentId, chunks.chunks[0].id, {
239
+ includeAssetUrls: true,
240
+ });
241
+ console.log(chunk.chunk.content);
242
+ }
229
243
  console.log(archived.status);
230
244
  ```
231
245
 
@@ -290,7 +304,7 @@ Check out the [examples](./examples) directory for more usage examples:
290
304
 
291
305
  ```bash
292
306
  # Install dependencies
293
- npm install
307
+ npm ci
294
308
 
295
309
  # Run tests
296
310
  npm test
@@ -316,6 +330,12 @@ npm run build
316
330
  See [docs/release-workflow.md](./docs/release-workflow.md) for the
317
331
  Changesets-based stable and beta release process.
318
332
 
333
+ ## Community
334
+
335
+ - Contributing guide: [CONTRIBUTING.md](./CONTRIBUTING.md)
336
+ - Security policy: [SECURITY.md](./SECURITY.md)
337
+ - Code of conduct: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
338
+
319
339
  ## License
320
340
 
321
341
  [MIT](./LICENSE)
package/dist/index.d.mts CHANGED
@@ -712,6 +712,104 @@ interface DocumentListResponse {
712
712
  /** Documents visible in the namespace */
713
713
  documents: Document[];
714
714
  }
715
+ /**
716
+ * Document chunk types supported by document chunk endpoints.
717
+ */
718
+ type DocumentChunkType = 'text' | 'image' | 'table';
719
+ /**
720
+ * Pagination metadata returned by chunk list endpoints.
721
+ */
722
+ interface DocumentChunkPagination {
723
+ /** Current page number */
724
+ page: number;
725
+ /** Number of items requested per page */
726
+ pageSize: number;
727
+ /** Total matching chunks */
728
+ total: number;
729
+ /** Total number of pages */
730
+ totalPages: number;
731
+ }
732
+ /**
733
+ * Query parameters for GET /v1/documents/{document_id}/chunks.
734
+ */
735
+ interface DocumentChunkListParams {
736
+ /** Page number (default: 1) */
737
+ page?: number;
738
+ /** Items per page (default: 50, maximum: 200) */
739
+ pageSize?: number;
740
+ /** Optional chunk type filter */
741
+ chunkType?: DocumentChunkType;
742
+ /** Generate asset URLs for media chunks (default: false) */
743
+ includeAssetUrls?: boolean;
744
+ }
745
+ /**
746
+ * Query parameters for GET /v1/documents/{document_id}/chunks/{document_chunk_id}.
747
+ */
748
+ interface DocumentChunkGetParams {
749
+ /** Generate asset URLs for media chunks (default: false) */
750
+ includeAssetUrls?: boolean;
751
+ }
752
+ /**
753
+ * One current-revision document chunk.
754
+ */
755
+ interface DocumentChunk {
756
+ /** Stable document chunk row identifier */
757
+ id: string;
758
+ /** Parser-provided chunk identifier */
759
+ chunkId: string;
760
+ /** Chunk content type */
761
+ chunkType: DocumentChunkType;
762
+ /** Chunk text or generated summary content */
763
+ content?: string | null;
764
+ /** Parent section identifier */
765
+ sectionId?: string | null;
766
+ /** Parent section path */
767
+ sectionPath?: string | null;
768
+ /** Source path from the parser output */
769
+ sourceChunkPath?: string | null;
770
+ /** Generated artifact file path for media chunks */
771
+ filePath?: string | null;
772
+ /** Sort order within the document revision */
773
+ sortOrder: number;
774
+ /** Chunk metadata returned by the API */
775
+ metadata: Record<string, unknown>;
776
+ /** Generated asset URL when requested and available */
777
+ assetUrl?: string | null;
778
+ /** Chunk creation timestamp */
779
+ createdAt?: Date;
780
+ }
781
+ /**
782
+ * Response from GET /v1/documents/{document_id}/chunks.
783
+ */
784
+ interface DocumentChunkListResponse {
785
+ /** Stable document identifier */
786
+ documentId: string;
787
+ /** Retrieval namespace */
788
+ namespace: string;
789
+ /** Current published job result identifier */
790
+ jobResultId?: string | null;
791
+ /** Current published job identifier */
792
+ jobId?: string | null;
793
+ /** Current-revision chunks */
794
+ chunks: DocumentChunk[];
795
+ /** Pagination metadata */
796
+ pagination: DocumentChunkPagination;
797
+ }
798
+ /**
799
+ * Response from GET /v1/documents/{document_id}/chunks/{document_chunk_id}.
800
+ */
801
+ interface DocumentChunkResponse {
802
+ /** Stable document identifier */
803
+ documentId: string;
804
+ /** Retrieval namespace */
805
+ namespace: string;
806
+ /** Current published job result identifier */
807
+ jobResultId?: string | null;
808
+ /** Current published job identifier */
809
+ jobId?: string | null;
810
+ /** Requested current-revision chunk */
811
+ chunk: DocumentChunk;
812
+ }
715
813
 
716
814
  /**
717
815
  * Resource for canonical document lifecycle operations.
@@ -727,10 +825,20 @@ declare class Documents extends BaseResource {
727
825
  * Get one canonical document by ID.
728
826
  */
729
827
  get(documentId: string): Promise<Document>;
828
+ /**
829
+ * List current-revision chunks for one canonical document.
830
+ */
831
+ listChunks(documentId: string, params?: DocumentChunkListParams): Promise<DocumentChunkListResponse>;
832
+ /**
833
+ * Get one current-revision chunk for one canonical document.
834
+ */
835
+ getChunk(documentId: string, documentChunkId: string, params?: DocumentChunkGetParams): Promise<DocumentChunkResponse>;
730
836
  /**
731
837
  * Archive one canonical document by ID.
732
838
  */
733
839
  archive(documentId: string): Promise<Document>;
840
+ private createChunkListRequestConfig;
841
+ private createChunkGetRequestConfig;
734
842
  }
735
843
 
736
844
  /**
@@ -902,4 +1010,4 @@ declare class JobFailedError extends KnowhereError {
902
1010
  constructor(message: string, code: string, jobResult: JobResult);
903
1011
  }
904
1012
 
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 };
1013
+ export { APIError, 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, 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
@@ -712,6 +712,104 @@ interface DocumentListResponse {
712
712
  /** Documents visible in the namespace */
713
713
  documents: Document[];
714
714
  }
715
+ /**
716
+ * Document chunk types supported by document chunk endpoints.
717
+ */
718
+ type DocumentChunkType = 'text' | 'image' | 'table';
719
+ /**
720
+ * Pagination metadata returned by chunk list endpoints.
721
+ */
722
+ interface DocumentChunkPagination {
723
+ /** Current page number */
724
+ page: number;
725
+ /** Number of items requested per page */
726
+ pageSize: number;
727
+ /** Total matching chunks */
728
+ total: number;
729
+ /** Total number of pages */
730
+ totalPages: number;
731
+ }
732
+ /**
733
+ * Query parameters for GET /v1/documents/{document_id}/chunks.
734
+ */
735
+ interface DocumentChunkListParams {
736
+ /** Page number (default: 1) */
737
+ page?: number;
738
+ /** Items per page (default: 50, maximum: 200) */
739
+ pageSize?: number;
740
+ /** Optional chunk type filter */
741
+ chunkType?: DocumentChunkType;
742
+ /** Generate asset URLs for media chunks (default: false) */
743
+ includeAssetUrls?: boolean;
744
+ }
745
+ /**
746
+ * Query parameters for GET /v1/documents/{document_id}/chunks/{document_chunk_id}.
747
+ */
748
+ interface DocumentChunkGetParams {
749
+ /** Generate asset URLs for media chunks (default: false) */
750
+ includeAssetUrls?: boolean;
751
+ }
752
+ /**
753
+ * One current-revision document chunk.
754
+ */
755
+ interface DocumentChunk {
756
+ /** Stable document chunk row identifier */
757
+ id: string;
758
+ /** Parser-provided chunk identifier */
759
+ chunkId: string;
760
+ /** Chunk content type */
761
+ chunkType: DocumentChunkType;
762
+ /** Chunk text or generated summary content */
763
+ content?: string | null;
764
+ /** Parent section identifier */
765
+ sectionId?: string | null;
766
+ /** Parent section path */
767
+ sectionPath?: string | null;
768
+ /** Source path from the parser output */
769
+ sourceChunkPath?: string | null;
770
+ /** Generated artifact file path for media chunks */
771
+ filePath?: string | null;
772
+ /** Sort order within the document revision */
773
+ sortOrder: number;
774
+ /** Chunk metadata returned by the API */
775
+ metadata: Record<string, unknown>;
776
+ /** Generated asset URL when requested and available */
777
+ assetUrl?: string | null;
778
+ /** Chunk creation timestamp */
779
+ createdAt?: Date;
780
+ }
781
+ /**
782
+ * Response from GET /v1/documents/{document_id}/chunks.
783
+ */
784
+ interface DocumentChunkListResponse {
785
+ /** Stable document identifier */
786
+ documentId: string;
787
+ /** Retrieval namespace */
788
+ namespace: string;
789
+ /** Current published job result identifier */
790
+ jobResultId?: string | null;
791
+ /** Current published job identifier */
792
+ jobId?: string | null;
793
+ /** Current-revision chunks */
794
+ chunks: DocumentChunk[];
795
+ /** Pagination metadata */
796
+ pagination: DocumentChunkPagination;
797
+ }
798
+ /**
799
+ * Response from GET /v1/documents/{document_id}/chunks/{document_chunk_id}.
800
+ */
801
+ interface DocumentChunkResponse {
802
+ /** Stable document identifier */
803
+ documentId: string;
804
+ /** Retrieval namespace */
805
+ namespace: string;
806
+ /** Current published job result identifier */
807
+ jobResultId?: string | null;
808
+ /** Current published job identifier */
809
+ jobId?: string | null;
810
+ /** Requested current-revision chunk */
811
+ chunk: DocumentChunk;
812
+ }
715
813
 
716
814
  /**
717
815
  * Resource for canonical document lifecycle operations.
@@ -727,10 +825,20 @@ declare class Documents extends BaseResource {
727
825
  * Get one canonical document by ID.
728
826
  */
729
827
  get(documentId: string): Promise<Document>;
828
+ /**
829
+ * List current-revision chunks for one canonical document.
830
+ */
831
+ listChunks(documentId: string, params?: DocumentChunkListParams): Promise<DocumentChunkListResponse>;
832
+ /**
833
+ * Get one current-revision chunk for one canonical document.
834
+ */
835
+ getChunk(documentId: string, documentChunkId: string, params?: DocumentChunkGetParams): Promise<DocumentChunkResponse>;
730
836
  /**
731
837
  * Archive one canonical document by ID.
732
838
  */
733
839
  archive(documentId: string): Promise<Document>;
840
+ private createChunkListRequestConfig;
841
+ private createChunkGetRequestConfig;
734
842
  }
735
843
 
736
844
  /**
@@ -902,4 +1010,4 @@ declare class JobFailedError extends KnowhereError {
902
1010
  constructor(message: string, code: string, jobResult: JobResult);
903
1011
  }
904
1012
 
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 };
1013
+ export { APIError, 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, 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
@@ -1219,12 +1219,59 @@ var Documents = class extends BaseResource {
1219
1219
  async get(documentId) {
1220
1220
  return this.httpClient.get(`/v1/documents/${documentId}`);
1221
1221
  }
1222
+ /**
1223
+ * List current-revision chunks for one canonical document.
1224
+ */
1225
+ async listChunks(documentId, params) {
1226
+ return this.httpClient.get(
1227
+ `/v1/documents/${documentId}/chunks`,
1228
+ this.createChunkListRequestConfig(params)
1229
+ );
1230
+ }
1231
+ /**
1232
+ * Get one current-revision chunk for one canonical document.
1233
+ */
1234
+ async getChunk(documentId, documentChunkId, params) {
1235
+ return this.httpClient.get(
1236
+ `/v1/documents/${documentId}/chunks/${documentChunkId}`,
1237
+ this.createChunkGetRequestConfig(params)
1238
+ );
1239
+ }
1222
1240
  /**
1223
1241
  * Archive one canonical document by ID.
1224
1242
  */
1225
1243
  async archive(documentId) {
1226
1244
  return this.httpClient.post(`/v1/documents/${documentId}/archive`);
1227
1245
  }
1246
+ createChunkListRequestConfig(params) {
1247
+ if (!params) {
1248
+ return void 0;
1249
+ }
1250
+ const queryParams = {};
1251
+ if (params.page !== void 0) {
1252
+ queryParams.page = params.page;
1253
+ }
1254
+ if (params.pageSize !== void 0) {
1255
+ queryParams.page_size = params.pageSize;
1256
+ }
1257
+ if (params.chunkType !== void 0) {
1258
+ queryParams.chunk_type = params.chunkType;
1259
+ }
1260
+ if (params.includeAssetUrls === true) {
1261
+ queryParams.include_asset_urls = true;
1262
+ }
1263
+ return Object.keys(queryParams).length > 0 ? { params: queryParams } : void 0;
1264
+ }
1265
+ createChunkGetRequestConfig(params) {
1266
+ if (params?.includeAssetUrls !== true) {
1267
+ return void 0;
1268
+ }
1269
+ return {
1270
+ params: {
1271
+ include_asset_urls: true
1272
+ }
1273
+ };
1274
+ }
1228
1275
  };
1229
1276
 
1230
1277
  // src/client.ts
package/dist/index.mjs CHANGED
@@ -1159,12 +1159,59 @@ var Documents = class extends BaseResource {
1159
1159
  async get(documentId) {
1160
1160
  return this.httpClient.get(`/v1/documents/${documentId}`);
1161
1161
  }
1162
+ /**
1163
+ * List current-revision chunks for one canonical document.
1164
+ */
1165
+ async listChunks(documentId, params) {
1166
+ return this.httpClient.get(
1167
+ `/v1/documents/${documentId}/chunks`,
1168
+ this.createChunkListRequestConfig(params)
1169
+ );
1170
+ }
1171
+ /**
1172
+ * Get one current-revision chunk for one canonical document.
1173
+ */
1174
+ async getChunk(documentId, documentChunkId, params) {
1175
+ return this.httpClient.get(
1176
+ `/v1/documents/${documentId}/chunks/${documentChunkId}`,
1177
+ this.createChunkGetRequestConfig(params)
1178
+ );
1179
+ }
1162
1180
  /**
1163
1181
  * Archive one canonical document by ID.
1164
1182
  */
1165
1183
  async archive(documentId) {
1166
1184
  return this.httpClient.post(`/v1/documents/${documentId}/archive`);
1167
1185
  }
1186
+ createChunkListRequestConfig(params) {
1187
+ if (!params) {
1188
+ return void 0;
1189
+ }
1190
+ const queryParams = {};
1191
+ if (params.page !== void 0) {
1192
+ queryParams.page = params.page;
1193
+ }
1194
+ if (params.pageSize !== void 0) {
1195
+ queryParams.page_size = params.pageSize;
1196
+ }
1197
+ if (params.chunkType !== void 0) {
1198
+ queryParams.chunk_type = params.chunkType;
1199
+ }
1200
+ if (params.includeAssetUrls === true) {
1201
+ queryParams.include_asset_urls = true;
1202
+ }
1203
+ return Object.keys(queryParams).length > 0 ? { params: queryParams } : void 0;
1204
+ }
1205
+ createChunkGetRequestConfig(params) {
1206
+ if (params?.includeAssetUrls !== true) {
1207
+ return void 0;
1208
+ }
1209
+ return {
1210
+ params: {
1211
+ include_asset_urls: true
1212
+ }
1213
+ };
1214
+ }
1168
1215
  };
1169
1216
 
1170
1217
  // src/client.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontos-ai/knowhere-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
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",