@langchain/google-cloud-sql-pg 0.0.2 → 1.0.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 (58) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +6 -6
  3. package/README.md +1 -1
  4. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/chat_message_history.cjs +104 -137
  6. package/dist/chat_message_history.cjs.map +1 -0
  7. package/dist/chat_message_history.d.cts +57 -0
  8. package/dist/chat_message_history.d.cts.map +1 -0
  9. package/dist/chat_message_history.d.ts +53 -43
  10. package/dist/chat_message_history.d.ts.map +1 -0
  11. package/dist/chat_message_history.js +103 -133
  12. package/dist/chat_message_history.js.map +1 -0
  13. package/dist/engine.cjs +188 -242
  14. package/dist/engine.cjs.map +1 -0
  15. package/dist/engine.d.cts +138 -0
  16. package/dist/engine.d.cts.map +1 -0
  17. package/dist/engine.d.ts +102 -80
  18. package/dist/engine.d.ts.map +1 -0
  19. package/dist/engine.js +186 -234
  20. package/dist/engine.js.map +1 -0
  21. package/dist/index.cjs +21 -20
  22. package/dist/index.d.cts +6 -0
  23. package/dist/index.d.ts +6 -4
  24. package/dist/index.js +7 -4
  25. package/dist/indexes.cjs +96 -168
  26. package/dist/indexes.cjs.map +1 -0
  27. package/dist/indexes.d.cts +68 -0
  28. package/dist/indexes.d.cts.map +1 -0
  29. package/dist/indexes.d.ts +50 -47
  30. package/dist/indexes.d.ts.map +1 -0
  31. package/dist/indexes.js +90 -161
  32. package/dist/indexes.js.map +1 -0
  33. package/dist/loader.cjs +159 -242
  34. package/dist/loader.cjs.map +1 -0
  35. package/dist/loader.d.cts +101 -0
  36. package/dist/loader.d.cts.map +1 -0
  37. package/dist/loader.d.ts +40 -26
  38. package/dist/loader.d.ts.map +1 -0
  39. package/dist/loader.js +157 -237
  40. package/dist/loader.js.map +1 -0
  41. package/dist/utils/utils.cjs +36 -65
  42. package/dist/utils/utils.cjs.map +1 -0
  43. package/dist/utils/utils.js +36 -62
  44. package/dist/utils/utils.js.map +1 -0
  45. package/dist/vectorstore.cjs +438 -593
  46. package/dist/vectorstore.cjs.map +1 -0
  47. package/dist/vectorstore.d.cts +300 -0
  48. package/dist/vectorstore.d.cts.map +1 -0
  49. package/dist/vectorstore.d.ts +147 -130
  50. package/dist/vectorstore.d.ts.map +1 -0
  51. package/dist/vectorstore.js +436 -588
  52. package/dist/vectorstore.js.map +1 -0
  53. package/package.json +38 -47
  54. package/dist/utils/utils.d.ts +0 -22
  55. package/index.cjs +0 -1
  56. package/index.d.cts +0 -1
  57. package/index.d.ts +0 -1
  58. package/index.js +0 -1
package/dist/indexes.js CHANGED
@@ -1,163 +1,92 @@
1
- class StrategyMixin {
2
- constructor(operator, searchFunction, indexFunction) {
3
- Object.defineProperty(this, "operator", {
4
- enumerable: true,
5
- configurable: true,
6
- writable: true,
7
- value: void 0
8
- });
9
- Object.defineProperty(this, "searchFunction", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: void 0
14
- });
15
- Object.defineProperty(this, "indexFunction", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- this.operator = operator;
22
- this.searchFunction = searchFunction;
23
- this.indexFunction = indexFunction;
24
- }
25
- }
1
+ //#region src/indexes.ts
2
+ var StrategyMixin = class {
3
+ operator;
4
+ searchFunction;
5
+ indexFunction;
6
+ constructor(operator, searchFunction, indexFunction) {
7
+ this.operator = operator;
8
+ this.searchFunction = searchFunction;
9
+ this.indexFunction = indexFunction;
10
+ }
11
+ };
26
12
  /**
27
- * Enumerator of the Distance strategies.
28
- */
29
- export class DistanceStrategy extends StrategyMixin {
30
- }
31
- Object.defineProperty(DistanceStrategy, "EUCLIDEAN", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: new StrategyMixin("<->", "l2_distance", "vector_l2_ops")
36
- });
37
- Object.defineProperty(DistanceStrategy, "COSINE_DISTANCE", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: new StrategyMixin("<=>", "cosine_distance", "vector_cosine_ops")
42
- });
43
- Object.defineProperty(DistanceStrategy, "INNER_PRODUCT", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: new StrategyMixin("<#>", "inner_product", "vector_ip_ops")
48
- });
49
- export const DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.COSINE_DISTANCE;
50
- export const DEFAULT_INDEX_NAME_SUFFIX = "langchainvectorindex";
51
- export class BaseIndex {
52
- constructor(name, indexType = "base", distanceStrategy = DistanceStrategy.COSINE_DISTANCE, partialIndexes = []) {
53
- Object.defineProperty(this, "name", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: void 0
58
- });
59
- Object.defineProperty(this, "indexType", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- Object.defineProperty(this, "distanceStrategy", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
70
- });
71
- Object.defineProperty(this, "partialIndexes", {
72
- enumerable: true,
73
- configurable: true,
74
- writable: true,
75
- value: void 0
76
- });
77
- this.name = name;
78
- this.indexType = indexType;
79
- this.distanceStrategy = distanceStrategy;
80
- this.partialIndexes = partialIndexes;
81
- }
82
- }
83
- export class ExactNearestNeighbor extends BaseIndex {
84
- constructor(baseArgs) {
85
- super(baseArgs?.name, "exactnearestneighbor", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
86
- }
87
- indexOptions() {
88
- throw new Error("indexOptions method must be implemented by subclass");
89
- }
90
- }
91
- export class HNSWIndex extends BaseIndex {
92
- constructor(baseArgs, m, efConstruction) {
93
- super(baseArgs?.name, "hnsw", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
94
- Object.defineProperty(this, "m", {
95
- enumerable: true,
96
- configurable: true,
97
- writable: true,
98
- value: void 0
99
- });
100
- Object.defineProperty(this, "efConstruction", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- this.m = m ?? 16;
107
- this.efConstruction = efConstruction ?? 64;
108
- }
109
- indexOptions() {
110
- return `(m = ${this.m}, ef_construction = ${this.efConstruction})`;
111
- }
112
- }
113
- export class IVFFlatIndex extends BaseIndex {
114
- constructor(baseArgs, lists) {
115
- super(baseArgs?.name, "ivfflat", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
116
- Object.defineProperty(this, "lists", {
117
- enumerable: true,
118
- configurable: true,
119
- writable: true,
120
- value: void 0
121
- });
122
- this.lists = lists ?? 100;
123
- }
124
- indexOptions() {
125
- return `(lists = ${this.lists})`;
126
- }
127
- }
13
+ * Enumerator of the Distance strategies.
14
+ */
15
+ var DistanceStrategy = class extends StrategyMixin {
16
+ static EUCLIDEAN = new StrategyMixin("<->", "l2_distance", "vector_l2_ops");
17
+ static COSINE_DISTANCE = new StrategyMixin("<=>", "cosine_distance", "vector_cosine_ops");
18
+ static INNER_PRODUCT = new StrategyMixin("<#>", "inner_product", "vector_ip_ops");
19
+ };
20
+ const DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.COSINE_DISTANCE;
21
+ const DEFAULT_INDEX_NAME_SUFFIX = "langchainvectorindex";
22
+ var BaseIndex = class {
23
+ name;
24
+ indexType;
25
+ distanceStrategy;
26
+ partialIndexes;
27
+ constructor(name, indexType = "base", distanceStrategy = DistanceStrategy.COSINE_DISTANCE, partialIndexes = []) {
28
+ this.name = name;
29
+ this.indexType = indexType;
30
+ this.distanceStrategy = distanceStrategy;
31
+ this.partialIndexes = partialIndexes;
32
+ }
33
+ };
34
+ var ExactNearestNeighbor = class extends BaseIndex {
35
+ constructor(baseArgs) {
36
+ super(baseArgs?.name, "exactnearestneighbor", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
37
+ }
38
+ indexOptions() {
39
+ throw new Error("indexOptions method must be implemented by subclass");
40
+ }
41
+ };
42
+ var HNSWIndex = class extends BaseIndex {
43
+ m;
44
+ efConstruction;
45
+ constructor(baseArgs, m, efConstruction) {
46
+ super(baseArgs?.name, "hnsw", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
47
+ this.m = m ?? 16;
48
+ this.efConstruction = efConstruction ?? 64;
49
+ }
50
+ indexOptions() {
51
+ return `(m = ${this.m}, ef_construction = ${this.efConstruction})`;
52
+ }
53
+ };
54
+ var IVFFlatIndex = class extends BaseIndex {
55
+ lists;
56
+ constructor(baseArgs, lists) {
57
+ super(baseArgs?.name, "ivfflat", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
58
+ this.lists = lists ?? 100;
59
+ }
60
+ indexOptions() {
61
+ return `(lists = ${this.lists})`;
62
+ }
63
+ };
128
64
  /**
129
- * Convert index attributes to string.
130
- * Must be implemented by subclasses.
131
- */
132
- export class QueryOptions {
133
- }
134
- export class HNSWQueryOptions extends QueryOptions {
135
- constructor(efSearch) {
136
- super();
137
- Object.defineProperty(this, "efSearch", {
138
- enumerable: true,
139
- configurable: true,
140
- writable: true,
141
- value: void 0
142
- });
143
- this.efSearch = efSearch ?? 40;
144
- }
145
- to_string() {
146
- return `hnsw.ef_search = ${this.efSearch}`;
147
- }
148
- }
149
- export class IVFFlatQueryOptions extends QueryOptions {
150
- constructor(probes) {
151
- super();
152
- Object.defineProperty(this, "probes", {
153
- enumerable: true,
154
- configurable: true,
155
- writable: true,
156
- value: void 0
157
- });
158
- this.probes = probes ?? 1;
159
- }
160
- to_string() {
161
- return `ivflfat.probes = ${this.probes}`;
162
- }
163
- }
65
+ * Convert index attributes to string.
66
+ * Must be implemented by subclasses.
67
+ */
68
+ var QueryOptions = class {};
69
+ var HNSWQueryOptions = class extends QueryOptions {
70
+ efSearch;
71
+ constructor(efSearch) {
72
+ super();
73
+ this.efSearch = efSearch ?? 40;
74
+ }
75
+ to_string() {
76
+ return `hnsw.ef_search = ${this.efSearch}`;
77
+ }
78
+ };
79
+ var IVFFlatQueryOptions = class extends QueryOptions {
80
+ probes;
81
+ constructor(probes) {
82
+ super();
83
+ this.probes = probes ?? 1;
84
+ }
85
+ to_string() {
86
+ return `ivflfat.probes = ${this.probes}`;
87
+ }
88
+ };
89
+
90
+ //#endregion
91
+ export { BaseIndex, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, QueryOptions };
92
+ //# sourceMappingURL=indexes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexes.js","names":["operator: string","searchFunction: string","indexFunction: string","DEFAULT_INDEX_NAME_SUFFIX: string","name?: string","indexType: string","distanceStrategy: DistanceStrategy","partialIndexes: string[]","baseArgs?: BaseIndexArgs","m?: number","efConstruction?: number","baseArgs: BaseIndexArgs","lists?: number","efSearch?: number","probes?: number"],"sources":["../src/indexes.ts"],"sourcesContent":["class StrategyMixin {\n operator: string;\n\n searchFunction: string;\n\n indexFunction: string;\n\n constructor(operator: string, searchFunction: string, indexFunction: string) {\n this.operator = operator;\n this.searchFunction = searchFunction;\n this.indexFunction = indexFunction;\n }\n}\n\n/**\n * Enumerator of the Distance strategies.\n */\nexport class DistanceStrategy extends StrategyMixin {\n public static EUCLIDEAN = new StrategyMixin(\n \"<->\",\n \"l2_distance\",\n \"vector_l2_ops\"\n );\n\n public static COSINE_DISTANCE = new StrategyMixin(\n \"<=>\",\n \"cosine_distance\",\n \"vector_cosine_ops\"\n );\n\n public static INNER_PRODUCT = new StrategyMixin(\n \"<#>\",\n \"inner_product\",\n \"vector_ip_ops\"\n );\n}\n\nexport const DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.COSINE_DISTANCE;\nexport const DEFAULT_INDEX_NAME_SUFFIX: string = \"langchainvectorindex\";\n\nexport interface BaseIndexArgs {\n name?: string;\n distanceStrategy?: DistanceStrategy;\n partialIndexes?: string[];\n}\n\nexport abstract class BaseIndex {\n name?: string;\n\n indexType: string;\n\n distanceStrategy: DistanceStrategy;\n\n partialIndexes?: string[];\n\n constructor(\n name?: string,\n indexType: string = \"base\",\n distanceStrategy: DistanceStrategy = DistanceStrategy.COSINE_DISTANCE,\n partialIndexes: string[] = []\n ) {\n this.name = name;\n this.indexType = indexType;\n this.distanceStrategy = distanceStrategy;\n this.partialIndexes = partialIndexes;\n }\n\n /**\n * Set index query options for vector store initialization.\n */\n abstract indexOptions(): string;\n}\n\nexport class ExactNearestNeighbor extends BaseIndex {\n constructor(baseArgs?: BaseIndexArgs) {\n super(\n baseArgs?.name,\n \"exactnearestneighbor\",\n baseArgs?.distanceStrategy,\n baseArgs?.partialIndexes\n );\n }\n\n indexOptions(): string {\n throw new Error(\"indexOptions method must be implemented by subclass\");\n }\n}\n\nexport class HNSWIndex extends BaseIndex {\n m: number;\n\n efConstruction: number;\n\n constructor(baseArgs?: BaseIndexArgs, m?: number, efConstruction?: number) {\n super(\n baseArgs?.name,\n \"hnsw\",\n baseArgs?.distanceStrategy,\n baseArgs?.partialIndexes\n );\n this.m = m ?? 16;\n this.efConstruction = efConstruction ?? 64;\n }\n\n indexOptions(): string {\n return `(m = ${this.m}, ef_construction = ${this.efConstruction})`;\n }\n}\n\nexport class IVFFlatIndex extends BaseIndex {\n lists: number;\n\n constructor(baseArgs: BaseIndexArgs, lists?: number) {\n super(\n baseArgs?.name,\n \"ivfflat\",\n baseArgs?.distanceStrategy,\n baseArgs?.partialIndexes\n );\n this.lists = lists ?? 100;\n }\n\n indexOptions(): string {\n return `(lists = ${this.lists})`;\n }\n}\n\n/**\n * Convert index attributes to string.\n * Must be implemented by subclasses.\n */\nexport abstract class QueryOptions {\n abstract to_string(): string;\n}\n\nexport class HNSWQueryOptions extends QueryOptions {\n efSearch: number;\n\n constructor(efSearch?: number) {\n super();\n this.efSearch = efSearch ?? 40;\n }\n\n to_string(): string {\n return `hnsw.ef_search = ${this.efSearch}`;\n }\n}\n\nexport class IVFFlatQueryOptions extends QueryOptions {\n readonly probes: number;\n\n constructor(probes?: number) {\n super();\n this.probes = probes ?? 1;\n }\n\n to_string(): string {\n return `ivflfat.probes = ${this.probes}`;\n }\n}\n"],"mappings":";AAAA,IAAM,gBAAN,MAAoB;CAClB;CAEA;CAEA;CAEA,YAAYA,UAAkBC,gBAAwBC,eAAuB;EAC3E,KAAK,WAAW;EAChB,KAAK,iBAAiB;EACtB,KAAK,gBAAgB;CACtB;AACF;;;;AAKD,IAAa,mBAAb,cAAsC,cAAc;CAClD,OAAc,YAAY,IAAI,cAC5B,OACA,eACA;CAGF,OAAc,kBAAkB,IAAI,cAClC,OACA,mBACA;CAGF,OAAc,gBAAgB,IAAI,cAChC,OACA,iBACA;AAEH;AAED,MAAa,4BAA4B,iBAAiB;AAC1D,MAAaC,4BAAoC;AAQjD,IAAsB,YAAtB,MAAgC;CAC9B;CAEA;CAEA;CAEA;CAEA,YACEC,MACAC,YAAoB,QACpBC,mBAAqC,iBAAiB,iBACtDC,iBAA2B,CAAE,GAC7B;EACA,KAAK,OAAO;EACZ,KAAK,YAAY;EACjB,KAAK,mBAAmB;EACxB,KAAK,iBAAiB;CACvB;AAMF;AAED,IAAa,uBAAb,cAA0C,UAAU;CAClD,YAAYC,UAA0B;EACpC,MACE,UAAU,MACV,wBACA,UAAU,kBACV,UAAU,eACX;CACF;CAED,eAAuB;AACrB,QAAM,IAAI,MAAM;CACjB;AACF;AAED,IAAa,YAAb,cAA+B,UAAU;CACvC;CAEA;CAEA,YAAYA,UAA0BC,GAAYC,gBAAyB;EACzE,MACE,UAAU,MACV,QACA,UAAU,kBACV,UAAU,eACX;EACD,KAAK,IAAI,KAAK;EACd,KAAK,iBAAiB,kBAAkB;CACzC;CAED,eAAuB;AACrB,SAAO,CAAC,KAAK,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,eAAe,CAAC,CAAC;CACnE;AACF;AAED,IAAa,eAAb,cAAkC,UAAU;CAC1C;CAEA,YAAYC,UAAyBC,OAAgB;EACnD,MACE,UAAU,MACV,WACA,UAAU,kBACV,UAAU,eACX;EACD,KAAK,QAAQ,SAAS;CACvB;CAED,eAAuB;AACrB,SAAO,CAAC,SAAS,EAAE,KAAK,MAAM,CAAC,CAAC;CACjC;AACF;;;;;AAMD,IAAsB,eAAtB,MAAmC,CAElC;AAED,IAAa,mBAAb,cAAsC,aAAa;CACjD;CAEA,YAAYC,UAAmB;EAC7B,OAAO;EACP,KAAK,WAAW,YAAY;CAC7B;CAED,YAAoB;AAClB,SAAO,CAAC,iBAAiB,EAAE,KAAK,UAAU;CAC3C;AACF;AAED,IAAa,sBAAb,cAAyC,aAAa;CACpD,AAAS;CAET,YAAYC,QAAiB;EAC3B,OAAO;EACP,KAAK,SAAS,UAAU;CACzB;CAED,YAAoB;AAClB,SAAO,CAAC,iBAAiB,EAAE,KAAK,QAAQ;CACzC;AACF"}