@knowledge-stack/ksapi 1.13.0 → 1.14.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.
@@ -16,18 +16,24 @@
16
16
  import * as runtime from '../runtime';
17
17
  import type {
18
18
  ChunkResponse,
19
+ ChunkSearchRequest,
19
20
  CreateChunkRequest,
20
21
  HTTPValidationError,
22
+ ScoredChunkResponse,
21
23
  UpdateChunkContentRequest,
22
24
  UpdateChunkMetadataRequest,
23
25
  } from '../models/index';
24
26
  import {
25
27
  ChunkResponseFromJSON,
26
28
  ChunkResponseToJSON,
29
+ ChunkSearchRequestFromJSON,
30
+ ChunkSearchRequestToJSON,
27
31
  CreateChunkRequestFromJSON,
28
32
  CreateChunkRequestToJSON,
29
33
  HTTPValidationErrorFromJSON,
30
34
  HTTPValidationErrorToJSON,
35
+ ScoredChunkResponseFromJSON,
36
+ ScoredChunkResponseToJSON,
31
37
  UpdateChunkContentRequestFromJSON,
32
38
  UpdateChunkContentRequestToJSON,
33
39
  UpdateChunkMetadataRequestFromJSON,
@@ -49,6 +55,11 @@ export interface GetChunkRequest {
49
55
  ksUat?: string;
50
56
  }
51
57
 
58
+ export interface SearchChunksRequest {
59
+ chunkSearchRequest: ChunkSearchRequest;
60
+ ksUat?: string;
61
+ }
62
+
52
63
  export interface UpdateChunkContentOperationRequest {
53
64
  chunkId: string;
54
65
  updateChunkContentRequest: UpdateChunkContentRequest;
@@ -119,6 +130,23 @@ export interface ChunksApiInterface {
119
130
  */
120
131
  getChunk(requestParameters: GetChunkRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ChunkResponse>;
121
132
 
133
+ /**
134
+ * Semantic search over chunks using vector similarity. Combines pgvector cosine similarity with path-based authorization and optional metadata filters. Uses a two-session design to avoid holding a DB connection during the external embedding API call.
135
+ * @summary Search Chunks Handler
136
+ * @param {ChunkSearchRequest} chunkSearchRequest
137
+ * @param {string} [ksUat]
138
+ * @param {*} [options] Override http request option.
139
+ * @throws {RequiredError}
140
+ * @memberof ChunksApiInterface
141
+ */
142
+ searchChunksRaw(requestParameters: SearchChunksRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ScoredChunkResponse>>>;
143
+
144
+ /**
145
+ * Semantic search over chunks using vector similarity. Combines pgvector cosine similarity with path-based authorization and optional metadata filters. Uses a two-session design to avoid holding a DB connection during the external embedding API call.
146
+ * Search Chunks Handler
147
+ */
148
+ searchChunks(requestParameters: SearchChunksRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ScoredChunkResponse>>;
149
+
122
150
  /**
123
151
  * Update chunk content by creating a new content row. The old content row is preserved (not deleted). If the new content matches an existing content hash, it will be deduplicated.
124
152
  * @summary Update Chunk Content Handler
@@ -280,6 +308,47 @@ export class ChunksApi extends runtime.BaseAPI implements ChunksApiInterface {
280
308
  return await response.value();
281
309
  }
282
310
 
311
+ /**
312
+ * Semantic search over chunks using vector similarity. Combines pgvector cosine similarity with path-based authorization and optional metadata filters. Uses a two-session design to avoid holding a DB connection during the external embedding API call.
313
+ * Search Chunks Handler
314
+ */
315
+ async searchChunksRaw(requestParameters: SearchChunksRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ScoredChunkResponse>>> {
316
+ if (requestParameters['chunkSearchRequest'] == null) {
317
+ throw new runtime.RequiredError(
318
+ 'chunkSearchRequest',
319
+ 'Required parameter "chunkSearchRequest" was null or undefined when calling searchChunks().'
320
+ );
321
+ }
322
+
323
+ const queryParameters: any = {};
324
+
325
+ const headerParameters: runtime.HTTPHeaders = {};
326
+
327
+ headerParameters['Content-Type'] = 'application/json';
328
+
329
+
330
+ let urlPath = `/v1/chunks/search`;
331
+
332
+ const response = await this.request({
333
+ path: urlPath,
334
+ method: 'POST',
335
+ headers: headerParameters,
336
+ query: queryParameters,
337
+ body: ChunkSearchRequestToJSON(requestParameters['chunkSearchRequest']),
338
+ }, initOverrides);
339
+
340
+ return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(ScoredChunkResponseFromJSON));
341
+ }
342
+
343
+ /**
344
+ * Semantic search over chunks using vector similarity. Combines pgvector cosine similarity with path-based authorization and optional metadata filters. Uses a two-session design to avoid holding a DB connection during the external embedding API call.
345
+ * Search Chunks Handler
346
+ */
347
+ async searchChunks(requestParameters: SearchChunksRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ScoredChunkResponse>> {
348
+ const response = await this.searchChunksRaw(requestParameters, initOverrides);
349
+ return await response.value();
350
+ }
351
+
283
352
  /**
284
353
  * Update chunk content by creating a new content row. The old content row is preserved (not deleted). If the new content matches an existing content hash, it will be deduplicated.
285
354
  * Update Chunk Content Handler
@@ -0,0 +1,160 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Knowledge Stack API
5
+ * Knowledge Stack backend API for authentication and knowledge management
6
+ *
7
+ * The version of the OpenAPI document: 0.1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime';
16
+ import type { EmbeddingModel } from './EmbeddingModel';
17
+ import {
18
+ EmbeddingModelFromJSON,
19
+ EmbeddingModelFromJSONTyped,
20
+ EmbeddingModelToJSON,
21
+ EmbeddingModelToJSONTyped,
22
+ } from './EmbeddingModel';
23
+ import type { ChunkType } from './ChunkType';
24
+ import {
25
+ ChunkTypeFromJSON,
26
+ ChunkTypeFromJSONTyped,
27
+ ChunkTypeToJSON,
28
+ ChunkTypeToJSONTyped,
29
+ } from './ChunkType';
30
+
31
+ /**
32
+ * Request body for semantic chunk search.
33
+ * @export
34
+ * @interface ChunkSearchRequest
35
+ */
36
+ export interface ChunkSearchRequest {
37
+ /**
38
+ * Search query text
39
+ * @type {string}
40
+ * @memberof ChunkSearchRequest
41
+ */
42
+ query: string;
43
+ /**
44
+ * Embedding model to use
45
+ * @type {EmbeddingModel}
46
+ * @memberof ChunkSearchRequest
47
+ */
48
+ model?: EmbeddingModel;
49
+ /**
50
+ * Path part IDs to search within (non-CHUNK types). Defaults to tenant's /KS_ROOT/shared.
51
+ * @type {Array<string>}
52
+ * @memberof ChunkSearchRequest
53
+ */
54
+ parentPathIds?: Array<string>;
55
+ /**
56
+ * Filter by chunk type (TEXT, TABLE, IMAGE, UNKNOWN)
57
+ * @type {ChunkType}
58
+ * @memberof ChunkSearchRequest
59
+ */
60
+ chunkType?: ChunkType;
61
+ /**
62
+ * Only chunks updated after this timestamp
63
+ * @type {Date}
64
+ * @memberof ChunkSearchRequest
65
+ */
66
+ updatedAt?: Date;
67
+ /**
68
+ * Number of results (1-50)
69
+ * @type {number}
70
+ * @memberof ChunkSearchRequest
71
+ */
72
+ topK?: number;
73
+ /**
74
+ * Minimum similarity score
75
+ * @type {number}
76
+ * @memberof ChunkSearchRequest
77
+ */
78
+ scoreThreshold?: number;
79
+ }
80
+
81
+
82
+
83
+ /**
84
+ * Check if a given object implements the ChunkSearchRequest interface.
85
+ */
86
+ export function instanceOfChunkSearchRequest(value: object): value is ChunkSearchRequest {
87
+ if (!('query' in value) || value['query'] === undefined) return false;
88
+ return true;
89
+ }
90
+
91
+ export function ChunkSearchRequestFromJSON(json: any): ChunkSearchRequest {
92
+ return ChunkSearchRequestFromJSONTyped(json, false);
93
+ }
94
+
95
+ export function ChunkSearchRequestFromJSONTyped(json: any, ignoreDiscriminator: boolean): ChunkSearchRequest {
96
+ if (json == null) {
97
+ return json;
98
+ }
99
+ return {
100
+
101
+ 'query': json['query'],
102
+ 'model': json['model'] == null ? undefined : EmbeddingModelFromJSON(json['model']),
103
+ 'parentPathIds': json['parent_path_ids'] == null ? undefined : json['parent_path_ids'],
104
+ 'chunkType': json['chunk_type'] == null ? undefined : ChunkTypeFromJSON(json['chunk_type']),
105
+ 'updatedAt': json['updated_at'] == null ? undefined : (new Date(json['updated_at'])),
106
+ 'topK': json['top_k'] == null ? undefined : json['top_k'],
107
+ 'scoreThreshold': json['score_threshold'] == null ? undefined : json['score_threshold'],
108
+ };
109
+ }
110
+
111
+ export function ChunkSearchRequestToJSON(json: any): ChunkSearchRequest {
112
+ return ChunkSearchRequestToJSONTyped(json, false);
113
+ }
114
+
115
+ export function ChunkSearchRequestToJSONTyped(value?: ChunkSearchRequest | null, ignoreDiscriminator: boolean = false): any {
116
+ if (value == null) {
117
+ return value;
118
+ }
119
+
120
+ return {
121
+
122
+ 'query': value['query'],
123
+ 'model': EmbeddingModelToJSON(value['model']),
124
+ 'parent_path_ids': value['parentPathIds'],
125
+ 'chunk_type': ChunkTypeToJSON(value['chunkType']),
126
+ 'updated_at': value['updatedAt'] == null ? value['updatedAt'] : value['updatedAt'].toISOString(),
127
+ 'top_k': value['topK'],
128
+ 'score_threshold': value['scoreThreshold'],
129
+ };
130
+ }
131
+
132
+ export const ChunkSearchRequestPropertyValidationAttributesMap: {
133
+ [property: string]: {
134
+ maxLength?: number,
135
+ minLength?: number,
136
+ pattern?: string,
137
+ maximum?: number,
138
+ exclusiveMaximum?: boolean,
139
+ minimum?: number,
140
+ exclusiveMinimum?: boolean,
141
+ multipleOf?: number,
142
+ maxItems?: number,
143
+ minItems?: number,
144
+ uniqueItems?: boolean
145
+ }
146
+ } = {
147
+ query: {
148
+ minLength: 1,
149
+ },
150
+ topK: {
151
+ maximum: 50,
152
+ exclusiveMaximum: false,
153
+ minimum: 1,
154
+ exclusiveMinimum: false,
155
+ },
156
+ }
157
+
158
+ export const ChunkSearchRequestAdditionalPropertiesValidationAttributes: { maxProperties?: number, minProperties?: number } = {
159
+ }
160
+
@@ -0,0 +1,52 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Knowledge Stack API
5
+ * Knowledge Stack backend API for authentication and knowledge management
6
+ *
7
+ * The version of the OpenAPI document: 0.1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ /**
17
+ * Supported embedding models.
18
+ * @export
19
+ */
20
+ export const EmbeddingModel = {
21
+ TextEmbedding3Small: 'text-embedding-3-small'
22
+ } as const;
23
+ export type EmbeddingModel = typeof EmbeddingModel[keyof typeof EmbeddingModel];
24
+
25
+
26
+ export function instanceOfEmbeddingModel(value: any): boolean {
27
+ for (const key in EmbeddingModel) {
28
+ if (Object.prototype.hasOwnProperty.call(EmbeddingModel, key)) {
29
+ if (EmbeddingModel[key as keyof typeof EmbeddingModel] === value) {
30
+ return true;
31
+ }
32
+ }
33
+ }
34
+ return false;
35
+ }
36
+
37
+ export function EmbeddingModelFromJSON(json: any): EmbeddingModel {
38
+ return EmbeddingModelFromJSONTyped(json, false);
39
+ }
40
+
41
+ export function EmbeddingModelFromJSONTyped(json: any, ignoreDiscriminator: boolean): EmbeddingModel {
42
+ return json as EmbeddingModel;
43
+ }
44
+
45
+ export function EmbeddingModelToJSON(value?: EmbeddingModel | null): any {
46
+ return value as any;
47
+ }
48
+
49
+ export function EmbeddingModelToJSONTyped(value: any, ignoreDiscriminator: boolean): EmbeddingModel {
50
+ return value as EmbeddingModel;
51
+ }
52
+
@@ -0,0 +1,215 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Knowledge Stack API
5
+ * Knowledge Stack backend API for authentication and knowledge management
6
+ *
7
+ * The version of the OpenAPI document: 0.1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime';
16
+ import type { ChunkMetadataOutput } from './ChunkMetadataOutput';
17
+ import {
18
+ ChunkMetadataOutputFromJSON,
19
+ ChunkMetadataOutputFromJSONTyped,
20
+ ChunkMetadataOutputToJSON,
21
+ ChunkMetadataOutputToJSONTyped,
22
+ } from './ChunkMetadataOutput';
23
+ import type { ChunkType } from './ChunkType';
24
+ import {
25
+ ChunkTypeFromJSON,
26
+ ChunkTypeFromJSONTyped,
27
+ ChunkTypeToJSON,
28
+ ChunkTypeToJSONTyped,
29
+ } from './ChunkType';
30
+
31
+ /**
32
+ * Chunk response with similarity score.
33
+ * @export
34
+ * @interface ScoredChunkResponse
35
+ */
36
+ export interface ScoredChunkResponse {
37
+ /**
38
+ * Chunk ID
39
+ * @type {string}
40
+ * @memberof ScoredChunkResponse
41
+ */
42
+ id: string;
43
+ /**
44
+ * PathPart ID
45
+ * @type {string}
46
+ * @memberof ScoredChunkResponse
47
+ */
48
+ pathPartId: string;
49
+ /**
50
+ * ChunkContent ID
51
+ * @type {string}
52
+ * @memberof ScoredChunkResponse
53
+ */
54
+ contentId: string;
55
+ /**
56
+ * Chunk text content
57
+ * @type {string}
58
+ * @memberof ScoredChunkResponse
59
+ */
60
+ content: string;
61
+ /**
62
+ * Type of chunk content
63
+ * @type {ChunkType}
64
+ * @memberof ScoredChunkResponse
65
+ */
66
+ chunkType: ChunkType;
67
+ /**
68
+ * Chunk metadata
69
+ * @type {ChunkMetadataOutput}
70
+ * @memberof ScoredChunkResponse
71
+ */
72
+ chunkMetadata: ChunkMetadataOutput;
73
+ /**
74
+ * Parent PathPart ID
75
+ * @type {string}
76
+ * @memberof ScoredChunkResponse
77
+ */
78
+ parentId: string;
79
+ /**
80
+ * Previous sibling PathPart ID
81
+ * @type {string}
82
+ * @memberof ScoredChunkResponse
83
+ */
84
+ prevSiblingPathId?: string;
85
+ /**
86
+ * Next sibling PathPart ID
87
+ * @type {string}
88
+ * @memberof ScoredChunkResponse
89
+ */
90
+ nextSiblingId?: string;
91
+ /**
92
+ * Full materialized path from root
93
+ * @type {string}
94
+ * @memberof ScoredChunkResponse
95
+ */
96
+ materializedPath: string;
97
+ /**
98
+ * Tenant ID
99
+ * @type {string}
100
+ * @memberof ScoredChunkResponse
101
+ */
102
+ tenantId: string;
103
+ /**
104
+ * Creation timestamp
105
+ * @type {Date}
106
+ * @memberof ScoredChunkResponse
107
+ */
108
+ createdAt: Date;
109
+ /**
110
+ * Last update timestamp
111
+ * @type {Date}
112
+ * @memberof ScoredChunkResponse
113
+ */
114
+ updatedAt: Date;
115
+ /**
116
+ * Cosine similarity score (1 - cosine_distance)
117
+ * @type {number}
118
+ * @memberof ScoredChunkResponse
119
+ */
120
+ score: number;
121
+ }
122
+
123
+
124
+
125
+ /**
126
+ * Check if a given object implements the ScoredChunkResponse interface.
127
+ */
128
+ export function instanceOfScoredChunkResponse(value: object): value is ScoredChunkResponse {
129
+ if (!('id' in value) || value['id'] === undefined) return false;
130
+ if (!('pathPartId' in value) || value['pathPartId'] === undefined) return false;
131
+ if (!('contentId' in value) || value['contentId'] === undefined) return false;
132
+ if (!('content' in value) || value['content'] === undefined) return false;
133
+ if (!('chunkType' in value) || value['chunkType'] === undefined) return false;
134
+ if (!('chunkMetadata' in value) || value['chunkMetadata'] === undefined) return false;
135
+ if (!('parentId' in value) || value['parentId'] === undefined) return false;
136
+ if (!('materializedPath' in value) || value['materializedPath'] === undefined) return false;
137
+ if (!('tenantId' in value) || value['tenantId'] === undefined) return false;
138
+ if (!('createdAt' in value) || value['createdAt'] === undefined) return false;
139
+ if (!('updatedAt' in value) || value['updatedAt'] === undefined) return false;
140
+ if (!('score' in value) || value['score'] === undefined) return false;
141
+ return true;
142
+ }
143
+
144
+ export function ScoredChunkResponseFromJSON(json: any): ScoredChunkResponse {
145
+ return ScoredChunkResponseFromJSONTyped(json, false);
146
+ }
147
+
148
+ export function ScoredChunkResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): ScoredChunkResponse {
149
+ if (json == null) {
150
+ return json;
151
+ }
152
+ return {
153
+
154
+ 'id': json['id'],
155
+ 'pathPartId': json['path_part_id'],
156
+ 'contentId': json['content_id'],
157
+ 'content': json['content'],
158
+ 'chunkType': ChunkTypeFromJSON(json['chunk_type']),
159
+ 'chunkMetadata': ChunkMetadataOutputFromJSON(json['chunk_metadata']),
160
+ 'parentId': json['parent_id'],
161
+ 'prevSiblingPathId': json['prev_sibling_path_id'] == null ? undefined : json['prev_sibling_path_id'],
162
+ 'nextSiblingId': json['next_sibling_id'] == null ? undefined : json['next_sibling_id'],
163
+ 'materializedPath': json['materialized_path'],
164
+ 'tenantId': json['tenant_id'],
165
+ 'createdAt': (new Date(json['created_at'])),
166
+ 'updatedAt': (new Date(json['updated_at'])),
167
+ 'score': json['score'],
168
+ };
169
+ }
170
+
171
+ export function ScoredChunkResponseToJSON(json: any): ScoredChunkResponse {
172
+ return ScoredChunkResponseToJSONTyped(json, false);
173
+ }
174
+
175
+ export function ScoredChunkResponseToJSONTyped(value?: ScoredChunkResponse | null, ignoreDiscriminator: boolean = false): any {
176
+ if (value == null) {
177
+ return value;
178
+ }
179
+
180
+ return {
181
+
182
+ 'id': value['id'],
183
+ 'path_part_id': value['pathPartId'],
184
+ 'content_id': value['contentId'],
185
+ 'content': value['content'],
186
+ 'chunk_type': ChunkTypeToJSON(value['chunkType']),
187
+ 'chunk_metadata': ChunkMetadataOutputToJSON(value['chunkMetadata']),
188
+ 'parent_id': value['parentId'],
189
+ 'prev_sibling_path_id': value['prevSiblingPathId'],
190
+ 'next_sibling_id': value['nextSiblingId'],
191
+ 'materialized_path': value['materializedPath'],
192
+ 'tenant_id': value['tenantId'],
193
+ 'created_at': value['createdAt'].toISOString(),
194
+ 'updated_at': value['updatedAt'].toISOString(),
195
+ 'score': value['score'],
196
+ };
197
+ }
198
+
199
+ export const ScoredChunkResponsePropertyValidationAttributesMap: {
200
+ [property: string]: {
201
+ maxLength?: number,
202
+ minLength?: number,
203
+ pattern?: string,
204
+ maximum?: number,
205
+ exclusiveMaximum?: boolean,
206
+ minimum?: number,
207
+ exclusiveMinimum?: boolean,
208
+ multipleOf?: number,
209
+ maxItems?: number,
210
+ minItems?: number,
211
+ uniqueItems?: boolean
212
+ }
213
+ } = {
214
+ }
215
+
@@ -4,6 +4,7 @@ export * from './ChunkLineageResponse';
4
4
  export * from './ChunkMetadataInput';
5
5
  export * from './ChunkMetadataOutput';
6
6
  export * from './ChunkResponse';
7
+ export * from './ChunkSearchRequest';
7
8
  export * from './ChunkType';
8
9
  export * from './CreateChunkLineageRequest';
9
10
  export * from './CreateChunkRequest';
@@ -23,6 +24,7 @@ export * from './DocumentType';
23
24
  export * from './DocumentVersionResponse';
24
25
  export * from './EmailSentResponse';
25
26
  export * from './EmailVerificationRequest';
27
+ export * from './EmbeddingModel';
26
28
  export * from './FolderDocumentResponse';
27
29
  export * from './FolderResponse';
28
30
  export * from './HTTPValidationError';
@@ -59,6 +61,7 @@ export * from './PermissionResponse';
59
61
  export * from './Polygon';
60
62
  export * from './PolygonReference';
61
63
  export * from './RootResponse';
64
+ export * from './ScoredChunkResponse';
62
65
  export * from './SectionResponse';
63
66
  export * from './SignInRequest';
64
67
  export * from './TagPathPartRequest';