@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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +6 -6
- package/README.md +1 -1
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/chat_message_history.cjs +104 -137
- package/dist/chat_message_history.cjs.map +1 -0
- package/dist/chat_message_history.d.cts +57 -0
- package/dist/chat_message_history.d.cts.map +1 -0
- package/dist/chat_message_history.d.ts +53 -43
- package/dist/chat_message_history.d.ts.map +1 -0
- package/dist/chat_message_history.js +103 -133
- package/dist/chat_message_history.js.map +1 -0
- package/dist/engine.cjs +188 -242
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +138 -0
- package/dist/engine.d.cts.map +1 -0
- package/dist/engine.d.ts +102 -80
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +186 -234
- package/dist/engine.js.map +1 -0
- package/dist/index.cjs +21 -20
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +7 -4
- package/dist/indexes.cjs +96 -168
- package/dist/indexes.cjs.map +1 -0
- package/dist/indexes.d.cts +68 -0
- package/dist/indexes.d.cts.map +1 -0
- package/dist/indexes.d.ts +50 -47
- package/dist/indexes.d.ts.map +1 -0
- package/dist/indexes.js +90 -161
- package/dist/indexes.js.map +1 -0
- package/dist/loader.cjs +159 -242
- package/dist/loader.cjs.map +1 -0
- package/dist/loader.d.cts +101 -0
- package/dist/loader.d.cts.map +1 -0
- package/dist/loader.d.ts +40 -26
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +157 -237
- package/dist/loader.js.map +1 -0
- package/dist/utils/utils.cjs +36 -65
- package/dist/utils/utils.cjs.map +1 -0
- package/dist/utils/utils.js +36 -62
- package/dist/utils/utils.js.map +1 -0
- package/dist/vectorstore.cjs +438 -593
- package/dist/vectorstore.cjs.map +1 -0
- package/dist/vectorstore.d.cts +300 -0
- package/dist/vectorstore.d.cts.map +1 -0
- package/dist/vectorstore.d.ts +147 -130
- package/dist/vectorstore.d.ts.map +1 -0
- package/dist/vectorstore.js +436 -588
- package/dist/vectorstore.js.map +1 -0
- package/package.json +38 -47
- package/dist/utils/utils.d.ts +0 -22
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/dist/indexes.js
CHANGED
|
@@ -1,163 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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,K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