vectra 0.9.0 → 0.10.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 (74) hide show
  1. package/README.md +10 -10
  2. package/package.json +7 -6
  3. package/src/ItemSelector.ts +7 -1
  4. package/src/LocalDocumentIndex.ts +7 -1
  5. package/src/LocalDocumentResult.ts +70 -22
  6. package/src/LocalIndex.ts +70 -3
  7. package/src/internals/Colorize.ts +3 -3
  8. package/src/internals/wink-bm25-text-search.d.ts +4 -0
  9. package/src/types.ts +1 -0
  10. package/src/vectra-cli.ts +13 -2
  11. package/lib/FileFetcher.d.ts +0 -5
  12. package/lib/FileFetcher.d.ts.map +0 -1
  13. package/lib/FileFetcher.js +0 -69
  14. package/lib/FileFetcher.js.map +0 -1
  15. package/lib/GPT3Tokenizer.d.ts +0 -9
  16. package/lib/GPT3Tokenizer.d.ts.map +0 -1
  17. package/lib/GPT3Tokenizer.js +0 -17
  18. package/lib/GPT3Tokenizer.js.map +0 -1
  19. package/lib/ItemSelector.d.ts +0 -41
  20. package/lib/ItemSelector.d.ts.map +0 -1
  21. package/lib/ItemSelector.js +0 -162
  22. package/lib/ItemSelector.js.map +0 -1
  23. package/lib/LocalDocument.d.ts +0 -54
  24. package/lib/LocalDocument.d.ts.map +0 -1
  25. package/lib/LocalDocument.js +0 -146
  26. package/lib/LocalDocument.js.map +0 -1
  27. package/lib/LocalDocumentIndex.d.ts +0 -128
  28. package/lib/LocalDocumentIndex.d.ts.map +0 -1
  29. package/lib/LocalDocumentIndex.js +0 -446
  30. package/lib/LocalDocumentIndex.js.map +0 -1
  31. package/lib/LocalDocumentResult.d.ts +0 -45
  32. package/lib/LocalDocumentResult.d.ts.map +0 -1
  33. package/lib/LocalDocumentResult.js +0 -282
  34. package/lib/LocalDocumentResult.js.map +0 -1
  35. package/lib/LocalIndex.d.ts +0 -136
  36. package/lib/LocalIndex.d.ts.map +0 -1
  37. package/lib/LocalIndex.js +0 -413
  38. package/lib/LocalIndex.js.map +0 -1
  39. package/lib/OpenAIEmbeddings.d.ts +0 -126
  40. package/lib/OpenAIEmbeddings.d.ts.map +0 -1
  41. package/lib/OpenAIEmbeddings.js +0 -174
  42. package/lib/OpenAIEmbeddings.js.map +0 -1
  43. package/lib/TextSplitter.d.ts +0 -20
  44. package/lib/TextSplitter.d.ts.map +0 -1
  45. package/lib/TextSplitter.js +0 -537
  46. package/lib/TextSplitter.js.map +0 -1
  47. package/lib/WebFetcher.d.ts +0 -15
  48. package/lib/WebFetcher.d.ts.map +0 -1
  49. package/lib/WebFetcher.js +0 -224
  50. package/lib/WebFetcher.js.map +0 -1
  51. package/lib/index.d.ts +0 -12
  52. package/lib/index.d.ts.map +0 -1
  53. package/lib/index.js +0 -28
  54. package/lib/index.js.map +0 -1
  55. package/lib/internals/Colorize.d.ts +0 -14
  56. package/lib/internals/Colorize.d.ts.map +0 -1
  57. package/lib/internals/Colorize.js +0 -64
  58. package/lib/internals/Colorize.js.map +0 -1
  59. package/lib/internals/index.d.ts +0 -3
  60. package/lib/internals/index.d.ts.map +0 -1
  61. package/lib/internals/index.js +0 -19
  62. package/lib/internals/index.js.map +0 -1
  63. package/lib/internals/types.d.ts +0 -43
  64. package/lib/internals/types.d.ts.map +0 -1
  65. package/lib/internals/types.js +0 -3
  66. package/lib/internals/types.js.map +0 -1
  67. package/lib/types.d.ts +0 -145
  68. package/lib/types.d.ts.map +0 -1
  69. package/lib/types.js +0 -3
  70. package/lib/types.js.map +0 -1
  71. package/lib/vectra-cli.d.ts +0 -2
  72. package/lib/vectra-cli.d.ts.map +0 -1
  73. package/lib/vectra-cli.js +0 -303
  74. package/lib/vectra-cli.js.map +0 -1
@@ -1,41 +0,0 @@
1
- import { MetadataFilter, MetadataTypes } from './types';
2
- export declare class ItemSelector {
3
- /**
4
- * Returns the similarity between two vectors using the cosine similarity.
5
- * @param vector1 Vector 1
6
- * @param vector2 Vector 2
7
- * @returns Similarity between the two vectors
8
- */
9
- static cosineSimilarity(vector1: number[], vector2: number[]): number;
10
- /**
11
- * Normalizes a vector.
12
- * @remarks
13
- * The norm of a vector is the square root of the sum of the squares of the elements.
14
- * The LocalIndex pre-normalizes all vectors to improve performance.
15
- * @param vector Vector to normalize
16
- * @returns Normalized vector
17
- */
18
- static normalize(vector: number[]): number;
19
- /**
20
- * Returns the similarity between two vectors using cosine similarity.
21
- * @remarks
22
- * The LocalIndex pre-normalizes all vectors to improve performance.
23
- * This method uses the pre-calculated norms to improve performance.
24
- * @param vector1 Vector 1
25
- * @param norm1 Norm of vector 1
26
- * @param vector2 Vector 2
27
- * @param norm2 Norm of vector 2
28
- * @returns Similarity between the two vectors
29
- */
30
- static normalizedCosineSimilarity(vector1: number[], norm1: number, vector2: number[], norm2: number): number;
31
- /**
32
- * Applies a filter to the metadata of an item.
33
- * @param metadata Metadata of the item
34
- * @param filter Filter to apply
35
- * @returns True if the item matches the filter, false otherwise
36
- */
37
- static select(metadata: Record<string, MetadataTypes>, filter: MetadataFilter): boolean;
38
- private static dotProduct;
39
- private static metadataFilter;
40
- }
41
- //# sourceMappingURL=ItemSelector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ItemSelector.d.ts","sourceRoot":"","sources":["../src/ItemSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExD,qBAAa,YAAY;IACrB;;;;;OAKG;WACW,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;IAKnE;;;;;;;OAOG;WACW,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE;IAYxC;;;;;;;;;;OAUG;WACW,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM;IAK3G;;;;;OAKG;WACW,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO;IAoC9F,OAAO,CAAC,MAAM,CAAC,UAAU;IAYzB,OAAO,CAAC,MAAM,CAAC,cAAc;CAyDhC"}
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ItemSelector = void 0;
4
- class ItemSelector {
5
- /**
6
- * Returns the similarity between two vectors using the cosine similarity.
7
- * @param vector1 Vector 1
8
- * @param vector2 Vector 2
9
- * @returns Similarity between the two vectors
10
- */
11
- static cosineSimilarity(vector1, vector2) {
12
- // Return the quotient of the dot product and the product of the norms
13
- return this.dotProduct(vector1, vector2) / (this.normalize(vector1) * this.normalize(vector2));
14
- }
15
- /**
16
- * Normalizes a vector.
17
- * @remarks
18
- * The norm of a vector is the square root of the sum of the squares of the elements.
19
- * The LocalIndex pre-normalizes all vectors to improve performance.
20
- * @param vector Vector to normalize
21
- * @returns Normalized vector
22
- */
23
- static normalize(vector) {
24
- // Initialize a variable to store the sum of the squares
25
- let sum = 0;
26
- // Loop through the elements of the array
27
- for (let i = 0; i < vector.length; i++) {
28
- // Square the element and add it to the sum
29
- sum += vector[i] * vector[i];
30
- }
31
- // Return the square root of the sum
32
- return Math.sqrt(sum);
33
- }
34
- /**
35
- * Returns the similarity between two vectors using cosine similarity.
36
- * @remarks
37
- * The LocalIndex pre-normalizes all vectors to improve performance.
38
- * This method uses the pre-calculated norms to improve performance.
39
- * @param vector1 Vector 1
40
- * @param norm1 Norm of vector 1
41
- * @param vector2 Vector 2
42
- * @param norm2 Norm of vector 2
43
- * @returns Similarity between the two vectors
44
- */
45
- static normalizedCosineSimilarity(vector1, norm1, vector2, norm2) {
46
- // Return the quotient of the dot product and the product of the norms
47
- return this.dotProduct(vector1, vector2) / (norm1 * norm2);
48
- }
49
- /**
50
- * Applies a filter to the metadata of an item.
51
- * @param metadata Metadata of the item
52
- * @param filter Filter to apply
53
- * @returns True if the item matches the filter, false otherwise
54
- */
55
- static select(metadata, filter) {
56
- if (filter === undefined || filter === null) {
57
- return true;
58
- }
59
- for (const key in filter) {
60
- switch (key) {
61
- case '$and':
62
- if (!filter[key].every((f) => this.select(metadata, f))) {
63
- return false;
64
- }
65
- break;
66
- case '$or':
67
- if (!filter[key].some((f) => this.select(metadata, f))) {
68
- return false;
69
- }
70
- break;
71
- default:
72
- const value = filter[key];
73
- if (value === undefined || value === null) {
74
- return false;
75
- }
76
- else if (typeof value == 'object') {
77
- if (!this.metadataFilter(metadata[key], value)) {
78
- return false;
79
- }
80
- }
81
- else {
82
- if (metadata[key] !== value) {
83
- return false;
84
- }
85
- }
86
- break;
87
- }
88
- }
89
- return true;
90
- }
91
- static dotProduct(arr1, arr2) {
92
- // Initialize a variable to store the sum of the products
93
- let sum = 0;
94
- // Loop through the elements of the arrays
95
- for (let i = 0; i < arr1.length; i++) {
96
- // Multiply the corresponding elements and add them to the sum
97
- sum += arr1[i] * arr2[i];
98
- }
99
- // Return the sum
100
- return sum;
101
- }
102
- static metadataFilter(value, filter) {
103
- if (value === undefined || value === null) {
104
- return false;
105
- }
106
- for (const key in filter) {
107
- switch (key) {
108
- case '$eq':
109
- if (value !== filter[key]) {
110
- return false;
111
- }
112
- break;
113
- case '$ne':
114
- if (value === filter[key]) {
115
- return false;
116
- }
117
- break;
118
- case '$gt':
119
- if (typeof value != 'number' || value <= filter[key]) {
120
- return false;
121
- }
122
- break;
123
- case '$gte':
124
- if (typeof value != 'number' || value < filter[key]) {
125
- return false;
126
- }
127
- break;
128
- case '$lt':
129
- if (typeof value != 'number' || value >= filter[key]) {
130
- return false;
131
- }
132
- break;
133
- case '$lte':
134
- if (typeof value != 'number' || value > filter[key]) {
135
- return false;
136
- }
137
- break;
138
- case '$in':
139
- if (typeof value == 'boolean') {
140
- return false;
141
- }
142
- else if (typeof value == 'string' && !filter[key].includes(value)) {
143
- return false;
144
- }
145
- else if (!filter[key].some(val => typeof val == 'string' && val.includes(value))) {
146
- return false;
147
- }
148
- break;
149
- case '$nin':
150
- if (typeof value == 'boolean' || filter[key].includes(value)) {
151
- return false;
152
- }
153
- break;
154
- default:
155
- return value === filter[key];
156
- }
157
- }
158
- return true;
159
- }
160
- }
161
- exports.ItemSelector = ItemSelector;
162
- //# sourceMappingURL=ItemSelector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ItemSelector.js","sourceRoot":"","sources":["../src/ItemSelector.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAY;IACrB;;;;;OAKG;IACI,MAAM,CAAC,gBAAgB,CAAC,OAAiB,EAAE,OAAiB;QAC/D,sEAAsE;QACtE,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACnG,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAC,MAAgB;QACpC,wDAAwD;QACxD,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,yCAAyC;QACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACpC,2CAA2C;YAC3C,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;SAChC;QACD,oCAAoC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAC,0BAA0B,CAAC,OAAiB,EAAE,KAAa,EAAE,OAAiB,EAAE,KAAa;QACvG,sEAAsE;QACtE,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,QAAuC,EAAE,M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B;oBACD,MAAM;gBACV,KAAK,KAAK;oBACN,IAAI,OAAO,KAAK,IAAI,SAAS,EAAE;wBAC3B,OAAO,KAAK,CAAC;qBAChB;yBAAM,IAAG,OAAO,KAAK,IAAI,QAAQ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAC;wBAChE,OAAO,KAAK,CAAA;qBACf;yBAAM,IAAG,CAAC,MAAM,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,IAAI,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAe,CAAC,CAAC,EAAC;wBACzF,OAAO,KAAK,CAAA;qBACf;oBACD,MAAM;gBACV,KAAK,MAAM;oBACP,IAAI,OAAO,KAAK,IAAI,SAAS,IAAI,MAAM,CAAC,GAAG,CAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;wBAC3D,OAAO,KAAK,CAAC;qBAChB;oBACD,MAAM;gBACV;oBACI,OAAO,KAAK,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC;aACpC;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA/JD,oCA+JC"}
@@ -1,54 +0,0 @@
1
- import { MetadataTypes } from './types';
2
- import { LocalDocumentIndex } from './LocalDocumentIndex';
3
- /**
4
- * Represents an indexed document stored on disk.
5
- */
6
- export declare class LocalDocument {
7
- private readonly _index;
8
- private readonly _id;
9
- private readonly _uri;
10
- private _metadata;
11
- private _text;
12
- /**
13
- * Creates a new `LocalDocument` instance.
14
- * @param index Parent index that contains the document.
15
- * @param id ID of the document.
16
- * @param uri URI of the document.
17
- */
18
- constructor(index: LocalDocumentIndex, id: string, uri: string);
19
- /**
20
- * Returns the folder path where the document is stored.
21
- */
22
- get folderPath(): string;
23
- /**
24
- * Returns the ID of the document.
25
- */
26
- get id(): string;
27
- /**
28
- * Returns the URI of the document.
29
- */
30
- get uri(): string;
31
- /**
32
- * Returns the length of the document in tokens.
33
- * @remarks
34
- * This value will be estimated for documents longer then 40k bytes.
35
- * @returns Length of the document in tokens.
36
- */
37
- getLength(): Promise<number>;
38
- /**
39
- * Determines if the document has additional metadata storred on disk.
40
- * @returns True if the document has metadata; otherwise, false.
41
- */
42
- hasMetadata(): Promise<boolean>;
43
- /**
44
- * Loads the metadata for the document from disk.
45
- * @returns Metadata for the document.
46
- */
47
- loadMetadata(): Promise<Record<string, MetadataTypes>>;
48
- /**
49
- * Loads the text for the document from disk.
50
- * @returns Text for the document.
51
- */
52
- loadText(): Promise<string>;
53
- }
54
- //# sourceMappingURL=LocalDocument.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalDocument.d.ts","sourceRoot":"","sources":["../src/LocalDocument.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAyC;IAC1D,OAAO,CAAC,KAAK,CAAmB;IAEhC;;;;;OAKG;gBACgB,KAAK,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAMrE;;OAEG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED;;OAEG;IACH,IAAW,EAAE,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED;;;;;OAKG;IACU,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IASzC;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAS5C;;;OAGG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAC,aAAa,CAAC,CAAC;IAmBlE;;;OAGG;IACU,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;CAW3C"}
@@ -1,146 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.LocalDocument = void 0;
36
- const fs = __importStar(require("fs/promises"));
37
- const path = __importStar(require("path"));
38
- /**
39
- * Represents an indexed document stored on disk.
40
- */
41
- class LocalDocument {
42
- /**
43
- * Creates a new `LocalDocument` instance.
44
- * @param index Parent index that contains the document.
45
- * @param id ID of the document.
46
- * @param uri URI of the document.
47
- */
48
- constructor(index, id, uri) {
49
- this._index = index;
50
- this._id = id;
51
- this._uri = uri;
52
- }
53
- /**
54
- * Returns the folder path where the document is stored.
55
- */
56
- get folderPath() {
57
- return this._index.folderPath;
58
- }
59
- /**
60
- * Returns the ID of the document.
61
- */
62
- get id() {
63
- return this._id;
64
- }
65
- /**
66
- * Returns the URI of the document.
67
- */
68
- get uri() {
69
- return this._uri;
70
- }
71
- /**
72
- * Returns the length of the document in tokens.
73
- * @remarks
74
- * This value will be estimated for documents longer then 40k bytes.
75
- * @returns Length of the document in tokens.
76
- */
77
- getLength() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- const text = yield this.loadText();
80
- if (text.length <= 40000) {
81
- return this._index.tokenizer.encode(text).length;
82
- }
83
- else {
84
- return Math.ceil(text.length / 4);
85
- }
86
- });
87
- }
88
- /**
89
- * Determines if the document has additional metadata storred on disk.
90
- * @returns True if the document has metadata; otherwise, false.
91
- */
92
- hasMetadata() {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- try {
95
- yield fs.access(path.join(this.folderPath, `${this.id}.json`));
96
- return true;
97
- }
98
- catch (err) {
99
- return false;
100
- }
101
- });
102
- }
103
- /**
104
- * Loads the metadata for the document from disk.
105
- * @returns Metadata for the document.
106
- */
107
- loadMetadata() {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- if (this._metadata == undefined) {
110
- let json;
111
- try {
112
- json = (yield fs.readFile(path.join(this.folderPath, `${this.id}.json`))).toString();
113
- }
114
- catch (err) {
115
- throw new Error(`Error reading metadata for document "${this.uri}": ${err.toString()}`);
116
- }
117
- try {
118
- this._metadata = JSON.parse(json);
119
- }
120
- catch (err) {
121
- throw new Error(`Error parsing metadata for document "${this.uri}": ${err.toString()}`);
122
- }
123
- }
124
- return this._metadata;
125
- });
126
- }
127
- /**
128
- * Loads the text for the document from disk.
129
- * @returns Text for the document.
130
- */
131
- loadText() {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- if (this._text == undefined) {
134
- try {
135
- this._text = (yield fs.readFile(path.join(this.folderPath, `${this.id}.txt`))).toString();
136
- }
137
- catch (err) {
138
- throw new Error(`Error reading text file for document "${this.uri}": ${err.toString()}`);
139
- }
140
- }
141
- return this._text;
142
- });
143
- }
144
- }
145
- exports.LocalDocument = LocalDocument;
146
- //# sourceMappingURL=LocalDocument.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalDocument.js","sourceRoot":"","sources":["../src/LocalDocument.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,2CAA6B;AAI7B;;GAEG;AACH,MAAa,aAAa;IAOtB;;;;;OAKG;IACH,YAAmB,KAAyB,EAAE,EAAU,EAAE,GAAW;QACjE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,IAAW,EAAE;QACT,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACU,SAAS;;YAClB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE;gBACtB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;aACpD;iBAAM;gBACH,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC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U,EAAE,GAAG,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;iBAC7F;gBAAC,OAAO,GAAY,EAAE;oBACnB,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,CAAC,GAAG,MAAO,GAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;iBACrG;aACJ;YAED,OAAO,IAAI,CAAC,KAAK,CAAC;QACtB,CAAC;KAAA;CACJ;AA1GD,sCA0GC"}
@@ -1,128 +0,0 @@
1
- import { CreateIndexConfig, LocalIndex } from "./LocalIndex";
2
- import { TextSplitterConfig } from "./TextSplitter";
3
- import { MetadataFilter, EmbeddingsModel, Tokenizer, MetadataTypes, DocumentChunkMetadata, DocumentCatalogStats } from "./types";
4
- import { LocalDocumentResult } from './LocalDocumentResult';
5
- import { LocalDocument } from './LocalDocument';
6
- /**
7
- * Options for querying documents in the index.
8
- */
9
- export interface DocumentQueryOptions {
10
- /**
11
- * Optional. Maximum number of documents to return.
12
- * @remarks
13
- * Default is 10.
14
- */
15
- maxDocuments?: number;
16
- /**
17
- * Maximum number of chunks to return per document.
18
- * @remarks
19
- * Default is 50.
20
- */
21
- maxChunks?: number;
22
- /**
23
- * Optional. Filter to apply to the document metadata.
24
- */
25
- filter?: MetadataFilter;
26
- }
27
- /**
28
- * Configuration settings for a local document index.
29
- */
30
- export interface LocalDocumentIndexConfig {
31
- /**
32
- * Folder path where the index is stored.
33
- */
34
- folderPath: string;
35
- /**
36
- * Optional. Embeddings model to use for generating document embeddings.
37
- */
38
- embeddings?: EmbeddingsModel;
39
- /**
40
- * Optional. Tokenizer to use for splitting text into tokens.
41
- */
42
- tokenizer?: Tokenizer;
43
- /**
44
- * Optional. Configuration settings for splitting text into chunks.
45
- */
46
- chunkingConfig?: Partial<TextSplitterConfig>;
47
- }
48
- /**
49
- * Represents a local index of documents stored on disk.
50
- */
51
- export declare class LocalDocumentIndex extends LocalIndex<DocumentChunkMetadata> {
52
- private readonly _embeddings?;
53
- private readonly _tokenizer;
54
- private readonly _chunkingConfig?;
55
- private _catalog?;
56
- private _newCatalog?;
57
- /**
58
- * Creates a new `LocalDocumentIndex` instance.
59
- * @param config Configuration settings for the document index.
60
- */
61
- constructor(config: LocalDocumentIndexConfig);
62
- /**
63
- * Returns the embeddings model used by the index (if configured.)
64
- */
65
- get embeddings(): EmbeddingsModel | undefined;
66
- /**
67
- * Returns the tokenizer used by the index.
68
- */
69
- get tokenizer(): Tokenizer;
70
- /**
71
- * Returns true if the document catalog exists.
72
- */
73
- isCatalogCreated(): Promise<boolean>;
74
- /**
75
- * Returns the document ID for the given URI.
76
- * @param uri URI of the document to lookup.
77
- * @returns Document ID or undefined if not found.
78
- */
79
- getDocumentId(uri: string): Promise<string | undefined>;
80
- /**
81
- * Returns the document URI for the given ID.
82
- * @param documentId ID of the document to lookup.
83
- * @returns Document URI or undefined if not found.
84
- */
85
- getDocumentUri(documentId: string): Promise<string | undefined>;
86
- /**
87
- * Loads the document catalog from disk and returns its stats.
88
- * @returns Catalog stats.
89
- */
90
- getCatalogStats(): Promise<DocumentCatalogStats>;
91
- /**
92
- * Deletes a document from the index.
93
- * @param uri URI of the document to delete.
94
- */
95
- deleteDocument(uri: string): Promise<void>;
96
- /**
97
- * Adds a document to the catalog.
98
- * @remarks
99
- * A new update is started if one is not already in progress. If an document with the same uri
100
- * already exists, it will be replaced.
101
- * @param uri - Document URI
102
- * @param text - Document text
103
- * @param docType - Optional. Document type
104
- * @param metadata - Optional. Document metadata to index
105
- * @returns Inserted document
106
- */
107
- upsertDocument(uri: string, text: string, docType?: string, metadata?: Record<string, MetadataTypes>): Promise<LocalDocument>;
108
- /**
109
- * Returns all documents in the index.
110
- * @remarks
111
- * Each document will contain all of the documents indexed chunks.
112
- * @returns Array of documents.
113
- */
114
- listDocuments(): Promise<LocalDocumentResult[]>;
115
- /**
116
- * Queries the index for documents similar to the given query.
117
- * @param query Text to query for.
118
- * @param options Optional. Query options.
119
- * @returns Array of document results.
120
- */
121
- queryDocuments(query: string, options?: DocumentQueryOptions): Promise<LocalDocumentResult[]>;
122
- beginUpdate(): Promise<void>;
123
- cancelUpdate(): void;
124
- createIndex(config?: CreateIndexConfig): Promise<void>;
125
- endUpdate(): Promise<void>;
126
- protected loadIndexData(): Promise<void>;
127
- }
128
- //# sourceMappingURL=LocalDocumentIndex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalDocumentIndex.d.ts","sourceRoot":"","sources":["../src/LocalDocumentIndex.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAgB,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAmC,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAClK,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAE7B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU,CAAC,qBAAqB,CAAC;IACrE,OAAO,CAAC,QAAQ,CAAC,WAAW,CA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