vectra 0.1.2 → 0.2.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.
Files changed (77) hide show
  1. package/README.md +5 -0
  2. package/bin/vectra.js +3 -0
  3. package/lib/GPT3Tokenizer.d.ts +9 -0
  4. package/lib/GPT3Tokenizer.d.ts.map +1 -0
  5. package/lib/GPT3Tokenizer.js +17 -0
  6. package/lib/GPT3Tokenizer.js.map +1 -0
  7. package/lib/ItemSelector.d.ts +1 -1
  8. package/lib/ItemSelector.d.ts.map +1 -1
  9. package/lib/ItemSelector.js.map +1 -1
  10. package/lib/LocalDocument.d.ts +16 -0
  11. package/lib/LocalDocument.d.ts.map +1 -0
  12. package/lib/LocalDocument.js +99 -0
  13. package/lib/LocalDocument.js.map +1 -0
  14. package/lib/LocalDocumentIndex.d.ts +48 -0
  15. package/lib/LocalDocumentIndex.d.ts.map +1 -0
  16. package/lib/LocalDocumentIndex.js +367 -0
  17. package/lib/LocalDocumentIndex.js.map +1 -0
  18. package/lib/LocalDocumentResult.d.ts +12 -0
  19. package/lib/LocalDocumentResult.d.ts.map +1 -0
  20. package/lib/LocalDocumentResult.js +186 -0
  21. package/lib/LocalDocumentResult.js.map +1 -0
  22. package/lib/LocalIndex.d.ts +9 -63
  23. package/lib/LocalIndex.d.ts.map +1 -1
  24. package/lib/LocalIndex.js +14 -1
  25. package/lib/LocalIndex.js.map +1 -1
  26. package/lib/OpenAIEmbeddings.d.ts +98 -0
  27. package/lib/OpenAIEmbeddings.d.ts.map +1 -0
  28. package/lib/OpenAIEmbeddings.js +139 -0
  29. package/lib/OpenAIEmbeddings.js.map +1 -0
  30. package/lib/TextSplitter.d.ts +17 -0
  31. package/lib/TextSplitter.d.ts.map +1 -0
  32. package/lib/TextSplitter.js +460 -0
  33. package/lib/TextSplitter.js.map +1 -0
  34. package/lib/WebFetcher.d.ts +16 -0
  35. package/lib/WebFetcher.d.ts.map +1 -0
  36. package/lib/WebFetcher.js +144 -0
  37. package/lib/WebFetcher.js.map +1 -0
  38. package/lib/index.d.ts +8 -0
  39. package/lib/index.d.ts.map +1 -1
  40. package/lib/index.js +13 -1
  41. package/lib/index.js.map +1 -1
  42. package/lib/internals/Colorize.d.ts +14 -0
  43. package/lib/internals/Colorize.d.ts.map +1 -0
  44. package/lib/internals/Colorize.js +64 -0
  45. package/lib/internals/Colorize.js.map +1 -0
  46. package/lib/internals/index.d.ts +3 -0
  47. package/lib/internals/index.d.ts.map +1 -0
  48. package/lib/internals/index.js +19 -0
  49. package/lib/internals/index.js.map +1 -0
  50. package/lib/internals/types.d.ts +42 -0
  51. package/lib/internals/types.d.ts.map +1 -0
  52. package/lib/internals/types.js +3 -0
  53. package/lib/internals/types.js.map +1 -0
  54. package/lib/types.d.ts +133 -0
  55. package/lib/types.d.ts.map +1 -0
  56. package/lib/types.js +3 -0
  57. package/lib/types.js.map +1 -0
  58. package/lib/vectra-cli.d.ts +2 -0
  59. package/lib/vectra-cli.d.ts.map +1 -0
  60. package/lib/vectra-cli.js +277 -0
  61. package/lib/vectra-cli.js.map +1 -0
  62. package/package.json +21 -3
  63. package/src/GPT3Tokenizer.ts +15 -0
  64. package/src/ItemSelector.ts +9 -9
  65. package/src/LocalDocument.ts +70 -0
  66. package/src/LocalDocumentIndex.ts +355 -0
  67. package/src/LocalDocumentResult.ts +206 -0
  68. package/src/LocalIndex.ts +12 -78
  69. package/src/OpenAIEmbeddings.ts +205 -0
  70. package/src/TextSplitter.ts +480 -0
  71. package/src/WebFetcher.ts +128 -0
  72. package/src/index.ts +8 -0
  73. package/src/internals/Colorize.ts +64 -0
  74. package/src/internals/index.ts +2 -0
  75. package/src/internals/types.ts +46 -0
  76. package/src/types.ts +160 -0
  77. package/src/vectra-cli.ts +238 -0
package/lib/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ export * from './GPT3Tokenizer';
1
2
  export * from './ItemSelector';
2
3
  export * from './LocalIndex';
4
+ export * from './LocalDocument';
5
+ export * from './LocalDocumentIndex';
6
+ export * from './LocalDocumentResult';
7
+ export * from './OpenAIEmbeddings';
8
+ export * from './TextSplitter';
9
+ export * from './types';
10
+ export * from './WebFetcher';
3
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,6 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./GPT3Tokenizer"), exports);
13
18
  __exportStar(require("./ItemSelector"), exports);
14
19
  __exportStar(require("./LocalIndex"), exports);
20
+ __exportStar(require("./LocalDocument"), exports);
21
+ __exportStar(require("./LocalDocumentIndex"), exports);
22
+ __exportStar(require("./LocalDocumentResult"), exports);
23
+ __exportStar(require("./OpenAIEmbeddings"), exports);
24
+ __exportStar(require("./TextSplitter"), exports);
25
+ __exportStar(require("./types"), exports);
26
+ __exportStar(require("./WebFetcher"), exports);
15
27
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B;AAC/B,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,iDAA+B;AAC/B,+CAA6B;AAC7B,kDAAgC;AAChC,uDAAqC;AACrC,wDAAsC;AACtC,qDAAmC;AACnC,iDAA+B;AAC/B,0CAAwB;AACxB,+CAA6B"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @private
3
+ */
4
+ export declare class Colorize {
5
+ static replaceLine(text: string): string;
6
+ static error(error: Error | string): string;
7
+ static output(output: object | string, quote?: string, units?: string): string;
8
+ static progress(message: string): string;
9
+ static success(message: string): string;
10
+ static title(title: string): string;
11
+ static value(field: string, value: any, units?: string): string;
12
+ static warning(warning: string): string;
13
+ }
14
+ //# sourceMappingURL=Colorize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Colorize.d.ts","sourceRoot":"","sources":["../../src/internals/Colorize.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,QAAQ;WACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;WAIjC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAC,MAAM,GAAG,MAAM;WAQlC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,GAAE,MAAW,EAAE,KAAK,GAAE,MAAW,GAAG,MAAM;WAyB/E,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;WAIjC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;WAIhC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;WAI5B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAE,MAAW,GAAG,MAAM;WAI5D,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAIjD"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Colorize = void 0;
4
+ const colorizer = require('json-colorizer');
5
+ /**
6
+ * @private
7
+ */
8
+ class Colorize {
9
+ static replaceLine(text) {
10
+ return '\x1b[A\x1b[2K' + text;
11
+ }
12
+ static error(error) {
13
+ if (typeof error === 'string') {
14
+ return `\x1b[31;1m${error}\x1b[0m`;
15
+ }
16
+ else {
17
+ return `\x1b[31;1m${error.message}\x1b[0m`;
18
+ }
19
+ }
20
+ static output(output, quote = '', units = '') {
21
+ if (typeof output === 'string') {
22
+ return `\x1b[32m${quote}${output}${quote}\x1b[0m`;
23
+ }
24
+ else if (typeof output === 'object' && output !== null) {
25
+ return colorizer(output, {
26
+ pretty: true,
27
+ colors: {
28
+ BRACE: 'white',
29
+ BRACKET: 'white',
30
+ COLON: 'white',
31
+ COMMA: 'white',
32
+ STRING_KEY: 'white',
33
+ STRING_LITERAL: 'green',
34
+ NUMBER_LITERAL: 'blue',
35
+ BOOLEAN_LITERAL: 'blue',
36
+ NULL_LITERAL: 'blue'
37
+ }
38
+ });
39
+ }
40
+ else if (typeof output == 'number') {
41
+ return `\x1b[34m${output}${units}\x1b[0m`;
42
+ }
43
+ else {
44
+ return `\x1b[34m${output}\x1b[0m`;
45
+ }
46
+ }
47
+ static progress(message) {
48
+ return message;
49
+ }
50
+ static success(message) {
51
+ return `\x1b[32;1m${message}\x1b[0m`;
52
+ }
53
+ static title(title) {
54
+ return `\x1b[35;1m${title}\x1b[0m`;
55
+ }
56
+ static value(field, value, units = '') {
57
+ return `${field}: ${Colorize.output(value, '"', units)}`;
58
+ }
59
+ static warning(warning) {
60
+ return `\x1b[33m${warning}\x1b[0m`;
61
+ }
62
+ }
63
+ exports.Colorize = Colorize;
64
+ //# sourceMappingURL=Colorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Colorize.js","sourceRoot":"","sources":["../../src/internals/Colorize.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAa,QAAQ;IACV,MAAM,CAAC,WAAW,CAAC,IAAY;QAClC,OAAO,eAAe,GAAG,IAAI,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,KAAmB;QACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,aAAa,KAAK,SAAS,CAAC;SACtC;aAAM;YACH,OAAO,aAAa,KAAK,CAAC,OAAO,SAAS,CAAC;SAC9C;IACL,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,MAAuB,EAAE,QAAgB,EAAE,EAAE,QAAgB,EAAE;QAChF,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC5B,OAAO,WAAW,KAAK,GAAG,MAAM,GAAG,KAAK,SAAS,CAAC;SACrD;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE;YACtD,OAAO,SAAS,CAAC,MAAM,EAAE;gBACrB,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE;oBACJ,KAAK,EAAE,OAAO;oBACd,OAAO,EAAE,OAAO;oBAChB,KAAK,EAAE,OAAO;oBACd,KAAK,EAAE,OAAO;oBACd,UAAU,EAAE,OAAO;oBACnB,cAAc,EAAE,OAAO;oBACvB,cAAc,EAAE,MAAM;oBACtB,eAAe,EAAE,MAAM;oBACvB,YAAY,EAAE,MAAM;iBACvB;aACJ,CAAC,CAAC;SACN;aAAM,IAAI,OAAO,MAAM,IAAI,QAAQ,EAAE;YAClC,OAAO,WAAW,MAAM,GAAG,KAAK,SAAS,CAAC;SAC7C;aAAM;YACH,OAAO,WAAW,MAAM,SAAS,CAAC;SACrC;IACL,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,OAAe;QAClC,OAAO,OAAO,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,OAAe;QACjC,OAAO,aAAa,OAAO,SAAS,CAAC;IACzC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,KAAa;QAC7B,OAAO,aAAa,KAAK,SAAS,CAAC;IACvC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,KAAa,EAAE,KAAU,EAAE,QAAgB,EAAE;QAC7D,OAAO,GAAG,KAAK,KAAK,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;IAC7D,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,OAAe;QACjC,OAAO,WAAW,OAAO,SAAS,CAAC;IAEvC,CAAC;CACJ;AA1DD,4BA0DC"}
@@ -0,0 +1,3 @@
1
+ export * from "./Colorize";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Colorize"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,0CAAwB"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @private
3
+ */
4
+ export interface CreateEmbeddingRequest {
5
+ input: CreateEmbeddingRequestInput;
6
+ user?: string;
7
+ }
8
+ /**
9
+ * @private
10
+ */
11
+ export interface OpenAICreateEmbeddingRequest extends CreateEmbeddingRequest {
12
+ model: string;
13
+ }
14
+ /**
15
+ * @private
16
+ */
17
+ export interface CreateEmbeddingResponse {
18
+ object: string;
19
+ model: string;
20
+ data: Array<CreateEmbeddingResponseDataInner>;
21
+ usage: CreateEmbeddingResponseUsage;
22
+ }
23
+ /**
24
+ * @private
25
+ */
26
+ export interface CreateEmbeddingResponseDataInner {
27
+ index: number;
28
+ object: string;
29
+ embedding: Array<number>;
30
+ }
31
+ /**
32
+ * @private
33
+ */
34
+ export interface CreateEmbeddingResponseUsage {
35
+ prompt_tokens: number;
36
+ total_tokens: number;
37
+ }
38
+ /**
39
+ * @private
40
+ */
41
+ export type CreateEmbeddingRequestInput = Array<any> | Array<number> | Array<string> | string;
42
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC,KAAK,EAAE,2BAA2B,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,sBAAsB;IACxE,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC9C,KAAK,EAAE,4BAA4B,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":""}
package/lib/types.d.ts ADDED
@@ -0,0 +1,133 @@
1
+ /**
2
+ * An AI model that can be used to create embeddings.
3
+ */
4
+ export interface EmbeddingsModel {
5
+ /**
6
+ * Creates embeddings for the given inputs.
7
+ * @param inputs Text inputs to create embeddings for.
8
+ * @returns A `EmbeddingsResponse` with a status and the generated embeddings or a message when an error occurs.
9
+ */
10
+ createEmbeddings(inputs: string | string[]): Promise<EmbeddingsResponse>;
11
+ }
12
+ /**
13
+ * Status of the embeddings response.
14
+ * @remarks
15
+ * `success` - The embeddings were successfully created.
16
+ * `error` - An error occurred while creating the embeddings.
17
+ * `rate_limited` - The request was rate limited.
18
+ */
19
+ export type EmbeddingsResponseStatus = 'success' | 'error' | 'rate_limited';
20
+ /**
21
+ * Response returned by a `EmbeddingsClient`.
22
+ */
23
+ export interface EmbeddingsResponse {
24
+ /**
25
+ * Status of the embeddings response.
26
+ */
27
+ status: EmbeddingsResponseStatus;
28
+ /**
29
+ * Optional. Embeddings for the given inputs.
30
+ */
31
+ output?: number[][];
32
+ /**
33
+ * Optional. Message when status is not equal to `success`.
34
+ */
35
+ message?: string;
36
+ }
37
+ export interface TextChunk {
38
+ text: string;
39
+ tokens: number[];
40
+ startPos: number;
41
+ endPos: number;
42
+ startOverlap: number[];
43
+ endOverlap: number[];
44
+ }
45
+ export interface TextFetcher {
46
+ fetch(uri: string): Promise<string>;
47
+ }
48
+ export interface IndexStats {
49
+ version: number;
50
+ metadata_config: {
51
+ indexed?: string[];
52
+ };
53
+ items: number;
54
+ }
55
+ export interface IndexItem<TMetadata = Record<string, MetadataTypes>> {
56
+ id: string;
57
+ metadata: TMetadata;
58
+ vector: number[];
59
+ norm: number;
60
+ metadataFile?: string;
61
+ }
62
+ export interface MetadataFilter {
63
+ /**
64
+ * Equal to (number, string, boolean)
65
+ */
66
+ '$eq'?: number | string | boolean;
67
+ /**
68
+ * Not equal to (number, string, boolean)
69
+ */
70
+ '$ne'?: number | string | boolean;
71
+ /**
72
+ * Greater than (number)
73
+ */
74
+ '$gt'?: number;
75
+ /**
76
+ * Greater than or equal to (number)
77
+ */
78
+ '$gte'?: number;
79
+ /**
80
+ * Less than (number)
81
+ */
82
+ '$lt'?: number;
83
+ /**
84
+ * Less than or equal to (number)
85
+ */
86
+ '$lte'?: number;
87
+ /**
88
+ * In array (string or number)
89
+ */
90
+ '$in'?: (number | string)[];
91
+ /**
92
+ * Not in array (string or number)
93
+ */
94
+ '$nin'?: (number | string)[];
95
+ /**
96
+ * AND (MetadataFilter[])
97
+ */
98
+ '$and'?: MetadataFilter[];
99
+ /**
100
+ * OR (MetadataFilter[])
101
+ */
102
+ '$or'?: MetadataFilter[];
103
+ [key: string]: unknown;
104
+ }
105
+ export type MetadataTypes = number | string | boolean;
106
+ export interface QueryResult<TMetadata = Record<string, MetadataTypes>> {
107
+ item: IndexItem<TMetadata>;
108
+ score: number;
109
+ }
110
+ export interface Tokenizer {
111
+ decode(tokens: number[]): string;
112
+ encode(text: string): number[];
113
+ }
114
+ export interface DocumentChunkMetadata {
115
+ documentId: string;
116
+ startPos: number;
117
+ endPos: number;
118
+ [key: string]: MetadataTypes;
119
+ }
120
+ export interface DocumentCatalogStats {
121
+ version: number;
122
+ documents: number;
123
+ chunks: number;
124
+ metadata_config: {
125
+ indexed?: string[];
126
+ };
127
+ }
128
+ export interface DocumentTextSection {
129
+ text: string;
130
+ tokenCount: number;
131
+ score: number;
132
+ }
133
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare function run(): Promise<void>;
2
+ //# sourceMappingURL=vectra-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vectra-cli.d.ts","sourceRoot":"","sources":["../src/vectra-cli.ts"],"names":[],"mappings":"AAQA,wBAAsB,GAAG,kBAyNxB"}
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.run = void 0;
39
+ const fs = __importStar(require("fs/promises"));
40
+ const yargs_1 = __importDefault(require("yargs/yargs"));
41
+ const helpers_1 = require("yargs/helpers");
42
+ const LocalDocumentIndex_1 = require("./LocalDocumentIndex");
43
+ const WebFetcher_1 = require("./WebFetcher");
44
+ const OpenAIEmbeddings_1 = require("./OpenAIEmbeddings");
45
+ const internals_1 = require("./internals");
46
+ function run() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ // prettier-ignore
49
+ const args = yield (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
50
+ .scriptName('vectra')
51
+ .command('create <index>', `create a new local index`, {}, (args) => __awaiter(this, void 0, void 0, function* () {
52
+ const folderPath = args.index;
53
+ const index = new LocalDocumentIndex_1.LocalDocumentIndex({ folderPath });
54
+ console.log(internals_1.Colorize.output(`creating index at ${folderPath}`));
55
+ yield index.createIndex({ version: 1, deleteIfExists: true });
56
+ }))
57
+ .command('delete <index>', `delete an existing local index`, {}, (args) => __awaiter(this, void 0, void 0, function* () {
58
+ const folderPath = args.index;
59
+ console.log(internals_1.Colorize.output(`deleting index at ${folderPath}`));
60
+ const index = new LocalDocumentIndex_1.LocalDocumentIndex({ folderPath });
61
+ yield index.deleteIndex();
62
+ }))
63
+ .command('add-web <index>', `adds one or more web pages to an index`, (yargs) => {
64
+ return yargs
65
+ .option('keys', {
66
+ alias: 'k',
67
+ describe: 'path of a JSON file containing the model keys to use for generating embeddings',
68
+ type: 'string'
69
+ })
70
+ .option('uri', {
71
+ alias: 'u',
72
+ array: true,
73
+ describe: 'http/https link to a web page to add',
74
+ type: 'string'
75
+ })
76
+ .option('list', {
77
+ alias: 'l',
78
+ describe: 'path to a file containing a list of web pages to add',
79
+ type: 'string'
80
+ })
81
+ .option('chunk-size', {
82
+ alias: 'cs',
83
+ describe: 'size of the generated chunks in tokens (defaults to 512)',
84
+ type: 'number',
85
+ default: 512
86
+ })
87
+ .check((argv) => {
88
+ if (Array.isArray(argv.uri) && argv.uri.length > 0) {
89
+ return true;
90
+ }
91
+ else if (typeof argv.list == 'string' && argv.list.trim().length > 0) {
92
+ return true;
93
+ }
94
+ else {
95
+ throw new Error(`you must specify either one or more "--uri <link>" for the pages to add or a "--list <file path>" for a file containing the list of pages to add.`);
96
+ }
97
+ })
98
+ .demandOption(['keys']);
99
+ }, (args) => __awaiter(this, void 0, void 0, function* () {
100
+ console.log(internals_1.Colorize.title('Adding Web Pages to Index'));
101
+ // Create embeddings
102
+ const keys = JSON.parse(yield fs.readFile(args.keys, 'utf-8'));
103
+ const embeddings = new OpenAIEmbeddings_1.OpenAIEmbeddings(Object.assign({ model: 'text-embedding-ada-002' }, keys));
104
+ // Initialize index
105
+ const folderPath = args.index;
106
+ const index = new LocalDocumentIndex_1.LocalDocumentIndex({
107
+ folderPath,
108
+ embeddings,
109
+ chunkingConfig: {
110
+ chunkSize: args.chunkSize
111
+ }
112
+ });
113
+ // Get list of url's
114
+ const uris = yield getItemList(args.uri, args.list, 'web page');
115
+ // Fetch web pages
116
+ const fetcher = new WebFetcher_1.WebFetcher();
117
+ for (const uri of uris) {
118
+ try {
119
+ console.log(internals_1.Colorize.progress(`fetching ${uri}`));
120
+ const content = yield fetcher.fetch(uri);
121
+ console.log(internals_1.Colorize.replaceLine(internals_1.Colorize.progress(`indexing ${uri}`)));
122
+ yield index.upsertDocument(uri, content);
123
+ console.log(internals_1.Colorize.replaceLine(internals_1.Colorize.success(`added ${uri}`)));
124
+ }
125
+ catch (err) {
126
+ console.log(internals_1.Colorize.replaceLine(internals_1.Colorize.error(`Error adding: ${uri}\n${err.message}`)));
127
+ }
128
+ }
129
+ }))
130
+ .command('remove <index>', `removes one or more documents from an index`, (yargs) => {
131
+ return yargs
132
+ .option('uri', {
133
+ alias: 'u',
134
+ array: true,
135
+ describe: 'uri of a document to remove',
136
+ type: 'string'
137
+ })
138
+ .option('list', {
139
+ alias: 'l',
140
+ describe: 'path to a file containing a list of documents to remove',
141
+ type: 'string'
142
+ })
143
+ .check((argv) => {
144
+ if (Array.isArray(argv.uri) && argv.uri.length > 0) {
145
+ return true;
146
+ }
147
+ else if (typeof argv.list == 'string' && argv.list.trim().length > 0) {
148
+ return true;
149
+ }
150
+ else {
151
+ throw new Error(`you must specify either one or more "--uri <link>" for the pages to add or a "--list <file path>" for a file containing the list of pages to add.`);
152
+ }
153
+ });
154
+ }, (args) => __awaiter(this, void 0, void 0, function* () {
155
+ // Initialize index
156
+ const folderPath = args.index;
157
+ const index = new LocalDocumentIndex_1.LocalDocumentIndex({ folderPath });
158
+ // Get list of uri's
159
+ const uris = yield getItemList(args.uri, args.list, 'document');
160
+ // Remove documents
161
+ for (const uri of uris) {
162
+ console.log(`removing ${uri}`);
163
+ yield index.deleteDocument(uri);
164
+ }
165
+ }))
166
+ .command('stats <index>', `prints the stats for a local index`, {}, (args) => __awaiter(this, void 0, void 0, function* () {
167
+ const folderPath = args.index;
168
+ const index = new LocalDocumentIndex_1.LocalDocumentIndex({ folderPath });
169
+ const stats = yield index.getCatalogStats();
170
+ console.log(internals_1.Colorize.title('Index Stats'));
171
+ console.log(internals_1.Colorize.output(stats));
172
+ }))
173
+ .command('query <index> <query>', `queries a local index`, (yargs) => {
174
+ return yargs
175
+ .option('keys', {
176
+ alias: 'k',
177
+ describe: 'path of a JSON file containing the model keys to use for generating embeddings'
178
+ })
179
+ .option('document-count', {
180
+ alias: 'dc',
181
+ describe: 'max number of documents to return (defaults to 10)',
182
+ type: 'count',
183
+ default: 10
184
+ })
185
+ .option('chunk-count', {
186
+ alias: 'cc',
187
+ describe: 'max number of chunks to return (defaults to 50)',
188
+ type: 'count',
189
+ default: 50
190
+ })
191
+ .option('section-count', {
192
+ alias: 'sc',
193
+ describe: 'max number of document sections to render (defaults to 1)',
194
+ type: 'count',
195
+ default: 1
196
+ })
197
+ .option('tokens', {
198
+ alias: 't',
199
+ describe: 'max number of tokens to render for each document section (defaults to 2000)',
200
+ type: 'count',
201
+ default: 2000
202
+ })
203
+ .option('format', {
204
+ alias: 'f',
205
+ describe: `format of the rendered results. Defaults to 'sections'`,
206
+ choices: ['sections', 'stats', 'chunks'],
207
+ default: 'sections'
208
+ })
209
+ .demandOption(['keys']);
210
+ }, (args) => __awaiter(this, void 0, void 0, function* () {
211
+ console.log(internals_1.Colorize.title('Querying Index'));
212
+ // Create embeddings
213
+ const keys = JSON.parse(yield fs.readFile(args.keys, 'utf-8'));
214
+ const embeddings = new OpenAIEmbeddings_1.OpenAIEmbeddings(Object.assign({ model: 'text-embedding-ada-002' }, keys));
215
+ // Initialize index
216
+ const folderPath = args.index;
217
+ const index = new LocalDocumentIndex_1.LocalDocumentIndex({
218
+ folderPath,
219
+ embeddings
220
+ });
221
+ // Query index
222
+ const query = args.query;
223
+ const results = yield index.queryDocuments(query, {
224
+ maxDocuments: args.documentCount,
225
+ maxChunks: args.chunkCount,
226
+ });
227
+ // Render results
228
+ for (const result of results) {
229
+ console.log(internals_1.Colorize.output(result.uri));
230
+ console.log(internals_1.Colorize.value('score', result.score));
231
+ console.log(internals_1.Colorize.value('chunks', result.chunks.length));
232
+ if (args.format == 'sections') {
233
+ const sections = yield result.renderSections(args.tokens, args.sectionCount);
234
+ for (let i = 0; i < sections.length; i++) {
235
+ const section = sections[i];
236
+ console.log(internals_1.Colorize.title(args.sectionCount > 1 ? 'Section' : `Section ${1}`));
237
+ console.log(internals_1.Colorize.value('score', section.score));
238
+ console.log(internals_1.Colorize.value('tokens', section.tokenCount));
239
+ console.log(internals_1.Colorize.output(section.text));
240
+ }
241
+ }
242
+ else if (args.format == 'chunks') {
243
+ const text = yield result.loadText();
244
+ for (let i = 0; i < result.chunks.length; i++) {
245
+ const chunk = result.chunks[i];
246
+ const startPos = chunk.item.metadata.startPos;
247
+ const endPos = chunk.item.metadata.endPos;
248
+ console.log(internals_1.Colorize.title(`Chunk ${i + 1}`));
249
+ console.log(internals_1.Colorize.value('score', chunk.score));
250
+ console.log(internals_1.Colorize.value('startPos', startPos));
251
+ console.log(internals_1.Colorize.value('endPos', endPos));
252
+ console.log(internals_1.Colorize.output(text.substring(startPos, endPos + 1)));
253
+ }
254
+ }
255
+ }
256
+ }))
257
+ .help()
258
+ .demandCommand()
259
+ .parseAsync();
260
+ });
261
+ }
262
+ exports.run = run;
263
+ function getItemList(items, listFile, uriType) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ if (Array.isArray(items) && items.length > 0) {
266
+ return items;
267
+ }
268
+ else if (typeof listFile == 'string' && listFile.trim().length > 0) {
269
+ const list = yield fs.readFile(listFile, 'utf-8');
270
+ return list.split('\n').map((item) => item.trim()).filter((item) => item.length > 0);
271
+ }
272
+ else {
273
+ throw new Error(`you must specify either one or more "--uri <${uriType}>" for the items or a "--list <file path>" for a file containing the items.`);
274
+ }
275
+ });
276
+ }
277
+ //# sourceMappingURL=vectra-cli.js.map