langchain 0.0.158 → 0.0.160

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/dist/chat_models/bedrock.cjs +28 -13
  2. package/dist/chat_models/bedrock.d.ts +6 -1
  3. package/dist/chat_models/bedrock.js +28 -13
  4. package/dist/llms/bedrock.cjs +29 -13
  5. package/dist/llms/bedrock.d.ts +6 -1
  6. package/dist/llms/bedrock.js +29 -13
  7. package/dist/load/import_constants.cjs +1 -0
  8. package/dist/load/import_constants.js +1 -0
  9. package/dist/prompts/few_shot.d.ts +1 -1
  10. package/dist/prompts/prompt.cjs +0 -3
  11. package/dist/prompts/prompt.d.ts +1 -1
  12. package/dist/prompts/prompt.js +0 -3
  13. package/dist/prompts/template.cjs +0 -2
  14. package/dist/prompts/template.d.ts +3 -3
  15. package/dist/prompts/template.js +0 -2
  16. package/dist/tools/google_calendar/base.cjs +94 -0
  17. package/dist/tools/google_calendar/base.d.ts +24 -0
  18. package/dist/tools/google_calendar/base.js +90 -0
  19. package/dist/tools/google_calendar/commands/run-create-events.cjs +71 -0
  20. package/dist/tools/google_calendar/commands/run-create-events.d.ts +10 -0
  21. package/dist/tools/google_calendar/commands/run-create-events.js +68 -0
  22. package/dist/tools/google_calendar/commands/run-view-events.cjs +50 -0
  23. package/dist/tools/google_calendar/commands/run-view-events.d.ts +10 -0
  24. package/dist/tools/google_calendar/commands/run-view-events.js +47 -0
  25. package/dist/tools/google_calendar/create.cjs +33 -0
  26. package/dist/tools/google_calendar/create.d.ts +8 -0
  27. package/dist/tools/google_calendar/create.js +29 -0
  28. package/dist/tools/google_calendar/descriptions.cjs +26 -0
  29. package/dist/tools/google_calendar/descriptions.d.ts +2 -0
  30. package/dist/tools/google_calendar/descriptions.js +23 -0
  31. package/dist/tools/google_calendar/index.cjs +7 -0
  32. package/dist/tools/google_calendar/index.d.ts +3 -0
  33. package/dist/tools/google_calendar/index.js +2 -0
  34. package/dist/tools/google_calendar/prompts/create-event-prompt.cjs +59 -0
  35. package/dist/tools/google_calendar/prompts/create-event-prompt.d.ts +1 -0
  36. package/dist/tools/google_calendar/prompts/create-event-prompt.js +56 -0
  37. package/dist/tools/google_calendar/prompts/index.cjs +7 -0
  38. package/dist/tools/google_calendar/prompts/index.d.ts +2 -0
  39. package/dist/tools/google_calendar/prompts/index.js +2 -0
  40. package/dist/tools/google_calendar/prompts/view-events-prompt.cjs +37 -0
  41. package/dist/tools/google_calendar/prompts/view-events-prompt.d.ts +1 -0
  42. package/dist/tools/google_calendar/prompts/view-events-prompt.js +34 -0
  43. package/dist/tools/google_calendar/utils/get-timezone-offset-in-hours.cjs +9 -0
  44. package/dist/tools/google_calendar/utils/get-timezone-offset-in-hours.d.ts +2 -0
  45. package/dist/tools/google_calendar/utils/get-timezone-offset-in-hours.js +6 -0
  46. package/dist/tools/google_calendar/view.cjs +33 -0
  47. package/dist/tools/google_calendar/view.d.ts +8 -0
  48. package/dist/tools/google_calendar/view.js +29 -0
  49. package/dist/vectorstores/pinecone.cjs +21 -34
  50. package/dist/vectorstores/pinecone.d.ts +6 -9
  51. package/dist/vectorstores/pinecone.js +21 -34
  52. package/dist/vectorstores/vectara.cjs +9 -0
  53. package/dist/vectorstores/vectara.d.ts +3 -0
  54. package/dist/vectorstores/vectara.js +9 -0
  55. package/package.json +17 -4
  56. package/tools/google_calendar.cjs +1 -0
  57. package/tools/google_calendar.d.ts +1 -0
  58. package/tools/google_calendar.js +1 -0
@@ -27,11 +27,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.PineconeStore = void 0;
30
+ /* eslint-disable no-process-env */
30
31
  const uuid = __importStar(require("uuid"));
31
32
  const flat_1 = __importDefault(require("flat"));
32
33
  const base_js_1 = require("./base.cjs");
33
34
  const document_js_1 = require("../document.cjs");
34
- const chunk_js_1 = require("../util/chunk.cjs");
35
35
  const async_caller_js_1 = require("../util/async_caller.cjs");
36
36
  /**
37
37
  * Class that extends the VectorStore class and provides methods to
@@ -135,16 +135,13 @@ class PineconeStore extends base_js_1.VectorStore {
135
135
  values,
136
136
  };
137
137
  });
138
+ const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
138
139
  // Pinecone recommends a limit of 100 vectors per upsert request
139
- const chunkSize = 100;
140
- const chunkedVectors = (0, chunk_js_1.chunkArray)(pineconeVectors, chunkSize);
141
- const batchRequests = chunkedVectors.map((chunk) => this.caller.call(async () => this.pineconeIndex.upsert({
142
- upsertRequest: {
143
- vectors: chunk,
144
- namespace: this.namespace,
145
- },
146
- })));
147
- await Promise.all(batchRequests);
140
+ const chunkSize = 50;
141
+ for (let i = 0; i < pineconeVectors.length; i += chunkSize) {
142
+ const chunk = pineconeVectors.slice(i, i + chunkSize);
143
+ await namespace.upsert(chunk);
144
+ }
148
145
  return documentIds;
149
146
  }
150
147
  /**
@@ -153,23 +150,17 @@ class PineconeStore extends base_js_1.VectorStore {
153
150
  * @returns Promise that resolves when the delete operation is complete.
154
151
  */
155
152
  async delete(params) {
156
- const { namespace = this.namespace, deleteAll, ids, ...rest } = params;
153
+ const { deleteAll, ids } = params;
154
+ const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
157
155
  if (deleteAll) {
158
- await this.pineconeIndex.delete1({
159
- deleteAll: true,
160
- namespace,
161
- ...rest,
162
- });
156
+ await namespace.deleteAll();
163
157
  }
164
158
  else if (ids) {
165
159
  const batchSize = 1000;
166
- const batchedIds = (0, chunk_js_1.chunkArray)(ids, batchSize);
167
- const batchRequests = batchedIds.map((batchIds) => this.caller.call(async () => this.pineconeIndex.delete1({
168
- ids: batchIds,
169
- namespace,
170
- ...rest,
171
- })));
172
- await Promise.all(batchRequests);
160
+ for (let i = 0; i < ids.length; i += batchSize) {
161
+ const batchIds = ids.slice(i, i + batchSize);
162
+ await namespace.deleteMany(batchIds);
163
+ }
173
164
  }
174
165
  else {
175
166
  throw new Error("Either ids or delete_all must be provided.");
@@ -188,14 +179,12 @@ class PineconeStore extends base_js_1.VectorStore {
188
179
  throw new Error("cannot provide both `filter` and `this.filter`");
189
180
  }
190
181
  const _filter = filter ?? this.filter;
191
- const results = await this.pineconeIndex.query({
192
- queryRequest: {
193
- includeMetadata: true,
194
- namespace: this.namespace,
195
- topK: k,
196
- vector: query,
197
- filter: _filter,
198
- },
182
+ const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
183
+ const results = await namespace.query({
184
+ includeMetadata: true,
185
+ topK: k,
186
+ vector: query,
187
+ filter: _filter,
199
188
  });
200
189
  const result = [];
201
190
  if (results.matches) {
@@ -229,9 +218,7 @@ class PineconeStore extends base_js_1.VectorStore {
229
218
  docs.push(newDoc);
230
219
  }
231
220
  const args = {
232
- pineconeIndex: "pineconeIndex" in dbConfig
233
- ? dbConfig.pineconeIndex
234
- : dbConfig.pineconeClient,
221
+ pineconeIndex: dbConfig.pineconeIndex,
235
222
  textKey: dbConfig.textKey,
236
223
  namespace: dbConfig.namespace,
237
224
  };
@@ -1,11 +1,11 @@
1
+ import { Index as PineconeIndex } from "@pinecone-database/pinecone";
1
2
  import { VectorStore } from "./base.js";
2
3
  import { Embeddings } from "../embeddings/base.js";
3
4
  import { Document } from "../document.js";
4
- import { AsyncCaller, type AsyncCallerParams } from "../util/async_caller.js";
5
+ import { AsyncCaller } from "../util/async_caller.js";
5
6
  type PineconeMetadata = Record<string, any>;
6
- type VectorOperationsApi = ReturnType<import("@pinecone-database/pinecone").PineconeClient["Index"]>;
7
- export interface PineconeLibArgs extends AsyncCallerParams {
8
- pineconeIndex: VectorOperationsApi;
7
+ export interface PineconeLibArgs {
8
+ pineconeIndex: PineconeIndex;
9
9
  textKey?: string;
10
10
  namespace?: string;
11
11
  filter?: PineconeMetadata;
@@ -27,7 +27,7 @@ export declare class PineconeStore extends VectorStore {
27
27
  FilterType: PineconeMetadata;
28
28
  textKey: string;
29
29
  namespace?: string;
30
- pineconeIndex: VectorOperationsApi;
30
+ pineconeIndex: PineconeIndex;
31
31
  filter?: PineconeMetadata;
32
32
  caller: AsyncCaller;
33
33
  _vectorstoreType(): string;
@@ -76,10 +76,7 @@ export declare class PineconeStore extends VectorStore {
76
76
  * @returns Promise that resolves with a new instance of the PineconeStore class.
77
77
  */
78
78
  static fromTexts(texts: string[], metadatas: object[] | object, embeddings: Embeddings, dbConfig: {
79
- /**
80
- * @deprecated Use pineconeIndex instead
81
- */
82
- pineconeClient: VectorOperationsApi;
79
+ pineconeIndex: PineconeIndex;
83
80
  textKey?: string;
84
81
  namespace?: string | undefined;
85
82
  } | PineconeLibArgs): Promise<PineconeStore>;
@@ -1,8 +1,8 @@
1
+ /* eslint-disable no-process-env */
1
2
  import * as uuid from "uuid";
2
3
  import flatten from "flat";
3
4
  import { VectorStore } from "./base.js";
4
5
  import { Document } from "../document.js";
5
- import { chunkArray } from "../util/chunk.js";
6
6
  import { AsyncCaller } from "../util/async_caller.js";
7
7
  /**
8
8
  * Class that extends the VectorStore class and provides methods to
@@ -106,16 +106,13 @@ export class PineconeStore extends VectorStore {
106
106
  values,
107
107
  };
108
108
  });
109
+ const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
109
110
  // Pinecone recommends a limit of 100 vectors per upsert request
110
- const chunkSize = 100;
111
- const chunkedVectors = chunkArray(pineconeVectors, chunkSize);
112
- const batchRequests = chunkedVectors.map((chunk) => this.caller.call(async () => this.pineconeIndex.upsert({
113
- upsertRequest: {
114
- vectors: chunk,
115
- namespace: this.namespace,
116
- },
117
- })));
118
- await Promise.all(batchRequests);
111
+ const chunkSize = 50;
112
+ for (let i = 0; i < pineconeVectors.length; i += chunkSize) {
113
+ const chunk = pineconeVectors.slice(i, i + chunkSize);
114
+ await namespace.upsert(chunk);
115
+ }
119
116
  return documentIds;
120
117
  }
121
118
  /**
@@ -124,23 +121,17 @@ export class PineconeStore extends VectorStore {
124
121
  * @returns Promise that resolves when the delete operation is complete.
125
122
  */
126
123
  async delete(params) {
127
- const { namespace = this.namespace, deleteAll, ids, ...rest } = params;
124
+ const { deleteAll, ids } = params;
125
+ const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
128
126
  if (deleteAll) {
129
- await this.pineconeIndex.delete1({
130
- deleteAll: true,
131
- namespace,
132
- ...rest,
133
- });
127
+ await namespace.deleteAll();
134
128
  }
135
129
  else if (ids) {
136
130
  const batchSize = 1000;
137
- const batchedIds = chunkArray(ids, batchSize);
138
- const batchRequests = batchedIds.map((batchIds) => this.caller.call(async () => this.pineconeIndex.delete1({
139
- ids: batchIds,
140
- namespace,
141
- ...rest,
142
- })));
143
- await Promise.all(batchRequests);
131
+ for (let i = 0; i < ids.length; i += batchSize) {
132
+ const batchIds = ids.slice(i, i + batchSize);
133
+ await namespace.deleteMany(batchIds);
134
+ }
144
135
  }
145
136
  else {
146
137
  throw new Error("Either ids or delete_all must be provided.");
@@ -159,14 +150,12 @@ export class PineconeStore extends VectorStore {
159
150
  throw new Error("cannot provide both `filter` and `this.filter`");
160
151
  }
161
152
  const _filter = filter ?? this.filter;
162
- const results = await this.pineconeIndex.query({
163
- queryRequest: {
164
- includeMetadata: true,
165
- namespace: this.namespace,
166
- topK: k,
167
- vector: query,
168
- filter: _filter,
169
- },
153
+ const namespace = this.pineconeIndex.namespace(this.namespace ?? "");
154
+ const results = await namespace.query({
155
+ includeMetadata: true,
156
+ topK: k,
157
+ vector: query,
158
+ filter: _filter,
170
159
  });
171
160
  const result = [];
172
161
  if (results.matches) {
@@ -200,9 +189,7 @@ export class PineconeStore extends VectorStore {
200
189
  docs.push(newDoc);
201
190
  }
202
191
  const args = {
203
- pineconeIndex: "pineconeIndex" in dbConfig
204
- ? dbConfig.pineconeIndex
205
- : dbConfig.pineconeClient,
192
+ pineconeIndex: dbConfig.pineconeIndex,
206
193
  textKey: dbConfig.textKey,
207
194
  namespace: dbConfig.namespace,
208
195
  };
@@ -61,6 +61,12 @@ class VectaraStore extends base_js_1.VectorStore {
61
61
  writable: true,
62
62
  value: void 0
63
63
  });
64
+ Object.defineProperty(this, "source", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: void 0
69
+ });
64
70
  Object.defineProperty(this, "vectaraApiTimeoutSeconds", {
65
71
  enumerable: true,
66
72
  configurable: true,
@@ -72,6 +78,7 @@ class VectaraStore extends base_js_1.VectorStore {
72
78
  throw new Error("Vectara api key is not provided.");
73
79
  }
74
80
  this.apiKey = apiKey;
81
+ this.source = args.source ?? "langchainjs";
75
82
  const corpusId = args.corpusId ??
76
83
  (0, env_js_1.getEnvironmentVariable)("VECTARA_CORPUS_ID")
77
84
  ?.split(",")
@@ -109,6 +116,7 @@ class VectaraStore extends base_js_1.VectorStore {
109
116
  "x-api-key": this.apiKey,
110
117
  "Content-Type": "application/json",
111
118
  "customer-id": this.customerId.toString(),
119
+ "X-Source": this.source,
112
120
  },
113
121
  };
114
122
  }
@@ -202,6 +210,7 @@ class VectaraStore extends base_js_1.VectorStore {
202
210
  method: "POST",
203
211
  headers: {
204
212
  "x-api-key": this.apiKey,
213
+ "X-Source": this.source,
205
214
  },
206
215
  body: data,
207
216
  });
@@ -10,6 +10,7 @@ export interface VectaraLibArgs {
10
10
  corpusId: number | number[];
11
11
  apiKey: string;
12
12
  verbose?: boolean;
13
+ source?: string;
13
14
  }
14
15
  /**
15
16
  * Interface for the headers required for Vectara API calls.
@@ -19,6 +20,7 @@ interface VectaraCallHeader {
19
20
  "x-api-key": string;
20
21
  "Content-Type": string;
21
22
  "customer-id": string;
23
+ "X-Source": string;
22
24
  };
23
25
  }
24
26
  /**
@@ -60,6 +62,7 @@ export declare class VectaraStore extends VectorStore {
60
62
  private corpusId;
61
63
  private customerId;
62
64
  private verbose;
65
+ private source;
63
66
  private vectaraApiTimeoutSeconds;
64
67
  _vectorstoreType(): string;
65
68
  constructor(args: VectaraLibArgs);
@@ -58,6 +58,12 @@ export class VectaraStore extends VectorStore {
58
58
  writable: true,
59
59
  value: void 0
60
60
  });
61
+ Object.defineProperty(this, "source", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: void 0
66
+ });
61
67
  Object.defineProperty(this, "vectaraApiTimeoutSeconds", {
62
68
  enumerable: true,
63
69
  configurable: true,
@@ -69,6 +75,7 @@ export class VectaraStore extends VectorStore {
69
75
  throw new Error("Vectara api key is not provided.");
70
76
  }
71
77
  this.apiKey = apiKey;
78
+ this.source = args.source ?? "langchainjs";
72
79
  const corpusId = args.corpusId ??
73
80
  getEnvironmentVariable("VECTARA_CORPUS_ID")
74
81
  ?.split(",")
@@ -106,6 +113,7 @@ export class VectaraStore extends VectorStore {
106
113
  "x-api-key": this.apiKey,
107
114
  "Content-Type": "application/json",
108
115
  "customer-id": this.customerId.toString(),
116
+ "X-Source": this.source,
109
117
  },
110
118
  };
111
119
  }
@@ -199,6 +207,7 @@ export class VectaraStore extends VectorStore {
199
207
  method: "POST",
200
208
  headers: {
201
209
  "x-api-key": this.apiKey,
210
+ "X-Source": this.source,
202
211
  },
203
212
  body: data,
204
213
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.158",
3
+ "version": "0.0.160",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -52,6 +52,9 @@
52
52
  "tools/webbrowser.cjs",
53
53
  "tools/webbrowser.js",
54
54
  "tools/webbrowser.d.ts",
55
+ "tools/google_calendar.cjs",
56
+ "tools/google_calendar.js",
57
+ "tools/google_calendar.d.ts",
55
58
  "chains.cjs",
56
59
  "chains.js",
57
60
  "chains.d.ts",
@@ -694,7 +697,7 @@
694
697
  "@mozilla/readability": "^0.4.4",
695
698
  "@notionhq/client": "^2.2.10",
696
699
  "@opensearch-project/opensearch": "^2.2.0",
697
- "@pinecone-database/pinecone": "^0.0.14",
700
+ "@pinecone-database/pinecone": "^1.1.0",
698
701
  "@planetscale/database": "^1.8.0",
699
702
  "@qdrant/js-client-rest": "^1.2.0",
700
703
  "@raycast/api": "^1.55.2",
@@ -750,6 +753,7 @@
750
753
  "fast-xml-parser": "^4.2.7",
751
754
  "firebase-admin": "^11.9.0",
752
755
  "google-auth-library": "^8.9.0",
756
+ "googleapis": "^126.0.1",
753
757
  "graphql": "^16.6.0",
754
758
  "hnswlib-node": "^1.4.2",
755
759
  "html-to-text": "^9.0.5",
@@ -816,7 +820,7 @@
816
820
  "@mozilla/readability": "*",
817
821
  "@notionhq/client": "^2.2.10",
818
822
  "@opensearch-project/opensearch": "*",
819
- "@pinecone-database/pinecone": "*",
823
+ "@pinecone-database/pinecone": "^1.1.0",
820
824
  "@planetscale/database": "^1.8.0",
821
825
  "@qdrant/js-client-rest": "^1.2.0",
822
826
  "@raycast/api": "^1.55.2",
@@ -846,6 +850,7 @@
846
850
  "fast-xml-parser": "^4.2.7",
847
851
  "firebase-admin": "^11.9.0",
848
852
  "google-auth-library": "^8.9.0",
853
+ "googleapis": "^126.0.1",
849
854
  "hnswlib-node": "^1.4.2",
850
855
  "html-to-text": "^9.0.5",
851
856
  "ignore": "^5.2.0",
@@ -1033,6 +1038,9 @@
1033
1038
  "google-auth-library": {
1034
1039
  "optional": true
1035
1040
  },
1041
+ "googleapis": {
1042
+ "optional": true
1043
+ },
1036
1044
  "hnswlib-node": {
1037
1045
  "optional": true
1038
1046
  },
@@ -1151,7 +1159,7 @@
1151
1159
  "p-retry": "4",
1152
1160
  "uuid": "^9.0.0",
1153
1161
  "yaml": "^2.2.1",
1154
- "zod": "^3.22.2",
1162
+ "zod": "^3.22.3",
1155
1163
  "zod-to-json-schema": "^3.20.4"
1156
1164
  },
1157
1165
  "publishConfig": {
@@ -1242,6 +1250,11 @@
1242
1250
  "import": "./tools/webbrowser.js",
1243
1251
  "require": "./tools/webbrowser.cjs"
1244
1252
  },
1253
+ "./tools/google_calendar": {
1254
+ "types": "./tools/google_calendar.d.ts",
1255
+ "import": "./tools/google_calendar.js",
1256
+ "require": "./tools/google_calendar.cjs"
1257
+ },
1245
1258
  "./chains": {
1246
1259
  "types": "./chains.d.ts",
1247
1260
  "import": "./chains.js",
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/tools/google_calendar/index.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/tools/google_calendar/index.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/tools/google_calendar/index.js'