@or-sdk/lookup 1.1.0-beta.1830.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.
Files changed (87) hide show
  1. package/README.md +983 -0
  2. package/dist/cjs/Lookup.js +413 -0
  3. package/dist/cjs/Lookup.js.map +1 -0
  4. package/dist/cjs/__tests__/QnA.collections.spec.js +177 -0
  5. package/dist/cjs/__tests__/QnA.collections.spec.js.map +1 -0
  6. package/dist/cjs/__tests__/fixtures/collection.json +34 -0
  7. package/dist/cjs/constants.js +5 -0
  8. package/dist/cjs/constants.js.map +1 -0
  9. package/dist/cjs/error-parser/OrNetworkError.js +45 -0
  10. package/dist/cjs/error-parser/OrNetworkError.js.map +1 -0
  11. package/dist/cjs/error-parser/index.js +34 -0
  12. package/dist/cjs/error-parser/index.js.map +1 -0
  13. package/dist/cjs/error-parser/parse-axios-error.js +38 -0
  14. package/dist/cjs/error-parser/parse-axios-error.js.map +1 -0
  15. package/dist/cjs/error-parser/processors.js +22 -0
  16. package/dist/cjs/error-parser/processors.js.map +1 -0
  17. package/dist/cjs/error-parser/types.js +3 -0
  18. package/dist/cjs/error-parser/types.js.map +1 -0
  19. package/dist/cjs/guards.js +9 -0
  20. package/dist/cjs/guards.js.map +1 -0
  21. package/dist/cjs/index.js +23 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/types.js +11 -0
  24. package/dist/cjs/types.js.map +1 -0
  25. package/dist/esm/Lookup.js +221 -0
  26. package/dist/esm/Lookup.js.map +1 -0
  27. package/dist/esm/__tests__/QnA.collections.spec.js +89 -0
  28. package/dist/esm/__tests__/QnA.collections.spec.js.map +1 -0
  29. package/dist/esm/__tests__/fixtures/collection.json +34 -0
  30. package/dist/esm/constants.js +2 -0
  31. package/dist/esm/constants.js.map +1 -0
  32. package/dist/esm/error-parser/OrNetworkError.js +14 -0
  33. package/dist/esm/error-parser/OrNetworkError.js.map +1 -0
  34. package/dist/esm/error-parser/index.js +12 -0
  35. package/dist/esm/error-parser/index.js.map +1 -0
  36. package/dist/esm/error-parser/parse-axios-error.js +34 -0
  37. package/dist/esm/error-parser/parse-axios-error.js.map +1 -0
  38. package/dist/esm/error-parser/processors.js +16 -0
  39. package/dist/esm/error-parser/processors.js.map +1 -0
  40. package/dist/esm/error-parser/types.js +2 -0
  41. package/dist/esm/error-parser/types.js.map +1 -0
  42. package/dist/esm/guards.js +5 -0
  43. package/dist/esm/guards.js.map +1 -0
  44. package/dist/esm/index.js +5 -0
  45. package/dist/esm/index.js.map +1 -0
  46. package/dist/esm/types.js +8 -0
  47. package/dist/esm/types.js.map +1 -0
  48. package/dist/types/Lookup.d.ts +27 -0
  49. package/dist/types/Lookup.d.ts.map +1 -0
  50. package/dist/types/__tests__/QnA.collections.spec.d.ts +2 -0
  51. package/dist/types/__tests__/QnA.collections.spec.d.ts.map +1 -0
  52. package/dist/types/constants.d.ts +2 -0
  53. package/dist/types/constants.d.ts.map +1 -0
  54. package/dist/types/error-parser/OrNetworkError.d.ts +14 -0
  55. package/dist/types/error-parser/OrNetworkError.d.ts.map +1 -0
  56. package/dist/types/error-parser/index.d.ts +5 -0
  57. package/dist/types/error-parser/index.d.ts.map +1 -0
  58. package/dist/types/error-parser/parse-axios-error.d.ts +3 -0
  59. package/dist/types/error-parser/parse-axios-error.d.ts.map +1 -0
  60. package/dist/types/error-parser/processors.d.ts +7 -0
  61. package/dist/types/error-parser/processors.d.ts.map +1 -0
  62. package/dist/types/error-parser/types.d.ts +6 -0
  63. package/dist/types/error-parser/types.d.ts.map +1 -0
  64. package/dist/types/guards.d.ts +3 -0
  65. package/dist/types/guards.d.ts.map +1 -0
  66. package/dist/types/index.d.ts +5 -0
  67. package/dist/types/index.d.ts.map +1 -0
  68. package/dist/types/types.d.ts +146 -0
  69. package/dist/types/types.d.ts.map +1 -0
  70. package/package.json +37 -0
  71. package/src/Lookup.ts +353 -0
  72. package/src/__tests__/QnA.collections.spec.ts +108 -0
  73. package/src/__tests__/fixtures/collection.json +34 -0
  74. package/src/constants.ts +1 -0
  75. package/src/error-parser/OrNetworkError.ts +23 -0
  76. package/src/error-parser/index.ts +16 -0
  77. package/src/error-parser/parse-axios-error.ts +40 -0
  78. package/src/error-parser/processors.ts +21 -0
  79. package/src/error-parser/types.ts +6 -0
  80. package/src/guards.ts +5 -0
  81. package/src/index.ts +4 -0
  82. package/src/types.ts +629 -0
  83. package/tsconfig.dev.json +8 -0
  84. package/tsconfig.esm.json +12 -0
  85. package/tsconfig.json +7 -0
  86. package/tsconfig.types.json +10 -0
  87. package/vitest.config.js +24 -0
package/src/types.ts ADDED
@@ -0,0 +1,629 @@
1
+ import { OrderOptions, PaginationOptions, Token } from '@or-sdk/base';
2
+
3
+ export type { OrNetworkError } from './error-parser';
4
+
5
+ export type SearchMode = 'vector' | 'bm25';
6
+
7
+ export type LookupConfig = {
8
+ /**
9
+ * token
10
+ */
11
+ token: Token;
12
+
13
+ /**
14
+ * Url of OneReach service discovery api
15
+ */
16
+ discoveryUrl?: string;
17
+
18
+ /**
19
+ * Account ID for cross-account requests (super admin only)
20
+ */
21
+ accountId?: string;
22
+
23
+ /**
24
+ * Url of OneReach lookup api
25
+ */
26
+ serviceUrl?: string;
27
+ };
28
+
29
+ /**
30
+ * Document creation parameters
31
+ */
32
+ export type LoadDocument = {
33
+ /**
34
+ * Document name
35
+ */
36
+ name: string;
37
+
38
+ /**
39
+ * Document URL
40
+ */
41
+ url?: string;
42
+
43
+ /**
44
+ * Document description
45
+ */
46
+ description?: string;
47
+
48
+ /**
49
+ * Default custom properties for document passages.
50
+ * Note that these properties should be listed in collection properties
51
+ */
52
+ defaultProperties: Record<string, unknown>;
53
+ };
54
+
55
+ export type Property = {
56
+ /**
57
+ * Property name. e.g. `nameOfTheAuthor`
58
+ */
59
+ name: string;
60
+
61
+ /**
62
+ * Property type. See https://weaviate.io/developers/weaviate/config-refs/schema#datatypes for the available types
63
+ */
64
+ dataType: string;
65
+
66
+ /**
67
+ * Property description
68
+ */
69
+ description?: string;
70
+ };
71
+
72
+ /**
73
+ * CreateCollection parameters
74
+ */
75
+ export type CreateCollection = UpdateCollection & {
76
+ /**
77
+ * Collection name
78
+ * Can start only with a letter.
79
+ * Minimum length: 5, Maximum length: 100
80
+ */
81
+ name: string;
82
+
83
+ /**
84
+ * Custom properties (Optional)
85
+ * Type: Array<Property>
86
+ */
87
+ properties?: Property[];
88
+ };
89
+
90
+ /**
91
+ * Search parameters
92
+ */
93
+ export type Search = {
94
+ /**
95
+ * Search query
96
+ */
97
+ query: string;
98
+
99
+ /**
100
+ * Limit the number of results.
101
+ */
102
+ limit?: number;
103
+
104
+ /**
105
+ * Weaviate where filter. See https://weaviate.io/developers/weaviate/api/graphql/filters
106
+ */
107
+ where?: Record<string, unknown>;
108
+
109
+ /**
110
+ * Array of the custom properties to select.
111
+ */
112
+ select?: string[];
113
+
114
+ /**
115
+ * Filter out passages that are further than maxDistance from the question or context by cosine metric.
116
+ * Default: 0
117
+ * Range: 0 - 1
118
+ */
119
+ maxDistance?: number;
120
+ };
121
+
122
+ export type MessageRole = 'user' | 'assistant';
123
+ export type AskMode = 'conversation' | 'ask';
124
+
125
+ /**
126
+ * Message data for completion request
127
+ */
128
+ export type CompletionRequestMessage = {
129
+ /**
130
+ * Role of the message sender (either "user" or "assistant")
131
+ */
132
+ role: MessageRole;
133
+
134
+ /**
135
+ * Content of the message
136
+ */
137
+ content: string;
138
+ };
139
+
140
+ /**
141
+ * Ask question parameters
142
+ */
143
+ export type Ask = {
144
+ /**
145
+ * Question to ask
146
+ */
147
+ question: string;
148
+
149
+ /**
150
+ * Previous chat messages
151
+ * Default: []
152
+ */
153
+ messages?: CompletionRequestMessage[];
154
+
155
+ /**
156
+ * Limit the number of results.
157
+ * Default: 5
158
+ * Range: 1 - 100
159
+ */
160
+ limit?: number;
161
+
162
+ /**
163
+ * Weaviate where filter. See https://weaviate.io/developers/weaviate/api/graphql/filters
164
+ * Optional
165
+ */
166
+ where?: Record<string, unknown>;
167
+
168
+ /**
169
+ * Array of the custom properties to select.
170
+ * Optional
171
+ */
172
+ select?: string[];
173
+
174
+ /**
175
+ * Question mode.
176
+ * Default: 'conversation'
177
+ * Values: 'conversation', 'ask'
178
+ */
179
+ mode?: AskMode;
180
+
181
+ /**
182
+ * A summarization instruction used to generate correct answer.
183
+ * Maximum Length: 1000 characters
184
+ * Optional
185
+ */
186
+ answerInstruction?: string | null;
187
+
188
+ /**
189
+ * A summarization instruction used to generate correct search query.
190
+ * Maximum Length: 1000 characters
191
+ * Optional
192
+ */
193
+ questionInstruction?: string | null;
194
+
195
+ /**
196
+ * What sampling temperature to use.
197
+ * Default: 1
198
+ * Range: 0 - 2
199
+ */
200
+ temperature?: number;
201
+
202
+ /**
203
+ * Maximum output length from the LLM
204
+ * Default: 1024
205
+ * Range: 128 - 2048
206
+ */
207
+ maxTokens?: number;
208
+
209
+ /**
210
+ * Positive values penalize new tokens based on their existing frequency in the text so far.
211
+ * Default: 0
212
+ * Range: -2 - 2
213
+ */
214
+ frequencyPenalty?: number;
215
+
216
+ /**
217
+ * Penalize new tokens based on whether they appear in the text so far.
218
+ * Default: 0
219
+ * Range: -2 - 2
220
+ */
221
+ presencePenalty?: number;
222
+
223
+ /**
224
+ * Filter out passages that are further than maxDistance from the question or context by cosine metric.
225
+ * Default: 0
226
+ * Range: 0 - 1
227
+ */
228
+ maxDistance?: number;
229
+ };
230
+
231
+ /**
232
+ * DocumentStatus represents the loading status of a document.
233
+ */
234
+ export enum DocumentStatus {
235
+ NEW = 'NEW',
236
+ LOADING = 'LOADING',
237
+ READY = 'READY',
238
+ ERROR = 'ERROR',
239
+ }
240
+
241
+ /**
242
+ * Document represents a document object.
243
+ */
244
+ export type Document = {
245
+ /**
246
+ * Document ID
247
+ */
248
+ id: string;
249
+
250
+ /**
251
+ * Collection ID
252
+ */
253
+ collection: string;
254
+
255
+ /**
256
+ * Document name
257
+ */
258
+ name: string;
259
+
260
+ /**
261
+ * Document description
262
+ */
263
+ description: string;
264
+
265
+ /**
266
+ * Document loading status or error message
267
+ */
268
+ status: DocumentStatus | string;
269
+
270
+ /**
271
+ * Creation Date
272
+ */
273
+ createdAt: string;
274
+
275
+ /**
276
+ * Updating Date
277
+ */
278
+ updatedAt: string;
279
+
280
+ /**
281
+ * Number of passages in the document.
282
+ */
283
+ countPassages?: number;
284
+
285
+ /**
286
+ * The URL of the source this document is downloaded from if provided.
287
+ */
288
+ sourceUrl?: string;
289
+ };
290
+
291
+ /**
292
+ * Collection represents a collection object.
293
+ */
294
+ export type Collection = {
295
+ /**
296
+ * Collection ID
297
+ */
298
+ id: string;
299
+
300
+ /**
301
+ * Account ID
302
+ */
303
+ accountId: string;
304
+
305
+ /**
306
+ * Collection name
307
+ * Can start only with a letter.
308
+ * Minimum length: 5, Maximum length: 100
309
+ */
310
+ name: string;
311
+
312
+ /**
313
+ * Collection description (Optional)
314
+ * Minimum length: 3, Maximum length: 500
315
+ */
316
+ description?: string;
317
+
318
+ /**
319
+ * A collection thumbnail image URL (Optional)
320
+ * Minimum length: 3, Maximum length: 2048
321
+ */
322
+ imageUrl?: string;
323
+
324
+ /**
325
+ * A summarization instruction used to generate a correct answer (Optional)
326
+ * Maximum length: 1000
327
+ */
328
+ answerInstruction?: string | null;
329
+
330
+ /**
331
+ * A summarization instruction used to generate a correct search query (Optional)
332
+ * Maximum length: 1000
333
+ */
334
+ questionInstruction?: string | null;
335
+
336
+ /**
337
+ * A summarization instruction used to generate a correct first message (Optional)
338
+ * Maximum length: 1000
339
+ */
340
+ greetingInstruction?: string | null;
341
+
342
+ /**
343
+ * Custom properties (Optional)
344
+ * Type: Array<Property>
345
+ */
346
+ properties?: Property[];
347
+
348
+ /**
349
+ * Creation Date
350
+ */
351
+ createdAt: string | Date;
352
+
353
+ /**
354
+ * Updating Date
355
+ */
356
+ updatedAt: string | Date;
357
+
358
+ /**
359
+ * What sampling temperature to use.
360
+ * Minimum value: 0, Maximum value: 2
361
+ */
362
+ temperature?: number;
363
+
364
+ /**
365
+ * Max output length from the LLM
366
+ * Minimum value: 128, Maximum value: 2048
367
+ */
368
+ maxTokens?: number;
369
+
370
+ /**
371
+ * Positive values penalize new tokens based on their existing frequency in the text so far.
372
+ * Minimum value: -2, Maximum value: 2
373
+ */
374
+ frequencyPenalty?: number;
375
+
376
+ /**
377
+ * Penalize new tokens based on whether they appear in the text so far.
378
+ * Minimum value: -2, Maximum value: 2
379
+ */
380
+ presencePenalty?: number;
381
+
382
+ /**
383
+ * Filter out passages that are further then maxDistance from the question or context by cosine metric.
384
+ * Minimum value: 0, Maximum value: 1
385
+ */
386
+ maxDistance?: number;
387
+
388
+ /**
389
+ * Large language model name.
390
+ */
391
+ modelName?: string;
392
+
393
+ /**
394
+ * Number of passages in the collection.
395
+ */
396
+ countPassages?: number;
397
+ };
398
+
399
+ /**
400
+ * SearchResult represents a document found as a result of a search query.
401
+ */
402
+ export type SearchResult = {
403
+ /**
404
+ * Found passage ID
405
+ */
406
+ id: string;
407
+
408
+ /**
409
+ * Cosine distance between search query and result.
410
+ */
411
+ distance: string;
412
+
413
+ /**
414
+ * Found passage content.
415
+ */
416
+ content: string;
417
+
418
+ /**
419
+ * SourceUrl
420
+ */
421
+ sourceUrl: string;
422
+
423
+ /**
424
+ * Found passage metadata.
425
+ */
426
+ loaderMetadata: Record<string, unknown>;
427
+
428
+ /**
429
+ * Found passage metadata.
430
+ */
431
+ document: {
432
+ id: string;
433
+ name: string;
434
+ };
435
+ };
436
+
437
+ /**
438
+ * AskResults represents the response from an ask question query.
439
+ */
440
+ export type AskResults = {
441
+ /**
442
+ * Generated answer from the chat completion.
443
+ */
444
+ result: CompletionRequestMessage;
445
+
446
+ /**
447
+ * Search result for the input question.
448
+ */
449
+ searchResult: SearchResult;
450
+ };
451
+
452
+
453
+ /**
454
+ * UpdateDocument parameters
455
+ */
456
+ export type UpdateDocument = {
457
+ /**
458
+ * Document description
459
+ */
460
+ description?: string;
461
+
462
+ /**
463
+ * Document status or loading error message
464
+ */
465
+ status?: DocumentStatus | string;
466
+ };
467
+
468
+ /**
469
+ * UpdateCollection parameters
470
+ */
471
+ export type UpdateCollection = {
472
+ /**
473
+ * Collection description (Optional)
474
+ * Minimum length: 3, Maximum length: 500
475
+ */
476
+ description?: string;
477
+
478
+ /**
479
+ * A collection thumbnail image URL (Optional)
480
+ * Minimum length: 3, Maximum length: 2048
481
+ */
482
+ imageUrl?: string;
483
+
484
+ /**
485
+ * A summarization instruction used to generate a correct answer (Optional)
486
+ * Maximum length: 1000
487
+ */
488
+ answerInstruction?: string;
489
+
490
+ /**
491
+ * A summarization instruction used to generate a correct search query (Optional)
492
+ * Maximum length: 1000
493
+ */
494
+ questionInstruction?: string;
495
+
496
+ /**
497
+ * A summarization instruction used to generate a correct first message (Optional)
498
+ * Maximum length: 1000
499
+ */
500
+ greetingInstruction?: string;
501
+
502
+ /**
503
+ * What sampling temperature to use (Optional)
504
+ * Default value: 1, Range: [0, 2]
505
+ */
506
+ temperature?: number;
507
+
508
+ /**
509
+ * Max output length from the LLM (Optional)
510
+ * Range: [128, 2048]
511
+ */
512
+ maxTokens?: number;
513
+
514
+ /**
515
+ * Positive values penalize new tokens based on their existing frequency in the text so far (Optional)
516
+ * Range: [-2, 2]
517
+ */
518
+ frequencyPenalty?: number;
519
+
520
+ /**
521
+ * Penalize new tokens based on whether they appear in the text so far (Optional)
522
+ * Range: [-2, 2]
523
+ */
524
+ presencePenalty?: number;
525
+
526
+ /**
527
+ * Filter out passages that are further then maxDistance from the question or context by
528
+ * cosine metric (Optional)
529
+ * Range: [0, 1]
530
+ */
531
+ maxDistance?: number;
532
+
533
+ /**
534
+ * Large language model name (Optional)
535
+ * Maximum length: 64
536
+ */
537
+ modelName?: string;
538
+ };
539
+
540
+ /**
541
+ * Find parameters
542
+ */
543
+ export type Find = Partial<PaginationOptions> & Partial<OrderOptions> & {
544
+ /**
545
+ * Search query
546
+ */
547
+ query?: string;
548
+
549
+ /**
550
+ * Search mode: bm25 for full-text search and vector for vector similarity search.
551
+ */
552
+ mode?: SearchMode;
553
+ };
554
+
555
+ /**
556
+ * Find passages parameters
557
+ */
558
+ export type FindPassages = Find & {
559
+ /**
560
+ * Weaviate where filter. See https://weaviate.io/developers/weaviate/api/graphql/filters
561
+ */
562
+ where?: Record<string, unknown>;
563
+ };
564
+
565
+ /**
566
+ * Passage creation parameters. The properties other than listed are considered custom properties.
567
+ */
568
+ export type CreatePassage<T extends Record<string, unknown> = Record<string, unknown>> = {
569
+ /**
570
+ * Content of the passage
571
+ */
572
+ content: string;
573
+
574
+ /**
575
+ * Document ID
576
+ */
577
+ documentId: string;
578
+
579
+ /**
580
+ * Custom loader metadata. Non filterable property
581
+ */
582
+ loaderMetadata?: Record<string, unknown>;
583
+ } & T;
584
+
585
+ /**
586
+ * Passage represents a passage object.
587
+ */
588
+ export type Passage<T extends Record<string, unknown> = Record<string, unknown>> = {
589
+ /**
590
+ * Passage ID
591
+ */
592
+ id: string;
593
+
594
+ /**
595
+ * Passage Content
596
+ */
597
+ content: string;
598
+
599
+ /**
600
+ * Creation Date
601
+ */
602
+ createdAt: string;
603
+
604
+ /**
605
+ * Updating Date
606
+ */
607
+ updatedAt: string;
608
+ } & T;
609
+
610
+
611
+ /**
612
+ * Update passage parameters
613
+ */
614
+ export type UpdatePassage<T extends Record<string, unknown> = Record<string, unknown>> = {
615
+ /**
616
+ * Updated content of the passage
617
+ */
618
+ content: string;
619
+ } & T;
620
+
621
+ /**
622
+ * Represents a deleted passage.
623
+ */
624
+ export type DeletedPassage = {
625
+ /**
626
+ * The ID of the deleted passage.
627
+ */
628
+ id: string;
629
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "./dist/types",
5
+ "rootDir": "./src",
6
+ "declaration": true
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "declarationDir": "./dist/types",
6
+ "module": "ES6",
7
+ "target": "es6",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true
11
+ }
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "emitDeclarationOnly": true
9
+ }
10
+ }
@@ -0,0 +1,24 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ reporters: ['junit', 'basic'],
6
+ outputFile: 'test-results/junit.xml',
7
+ coverage: {
8
+ all: true,
9
+ reporter: ['text', 'json', 'html', 'cobertura', 'text-summary'],
10
+ clean: true,
11
+ include: [
12
+ 'src/**',
13
+ ],
14
+ exclude: [
15
+ 'src/types.ts',
16
+ '**/*.spec.ts',
17
+ ],
18
+ },
19
+ globals: true,
20
+ environment: 'node',
21
+ clearMocks: true,
22
+ watch: false,
23
+ },
24
+ });