langchain 0.0.165 → 0.0.167

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 (100) hide show
  1. package/dist/cache/momento.cjs +7 -7
  2. package/dist/cache/momento.d.ts +1 -1
  3. package/dist/cache/momento.js +1 -1
  4. package/dist/document_loaders/fs/unstructured.cjs +40 -0
  5. package/dist/document_loaders/fs/unstructured.d.ts +27 -0
  6. package/dist/document_loaders/fs/unstructured.js +40 -0
  7. package/dist/embeddings/bedrock.cjs +43 -22
  8. package/dist/embeddings/bedrock.d.ts +11 -4
  9. package/dist/embeddings/bedrock.js +43 -22
  10. package/dist/experimental/chat_models/anthropic_functions.cjs +34 -2
  11. package/dist/experimental/chat_models/anthropic_functions.d.ts +15 -5
  12. package/dist/experimental/chat_models/anthropic_functions.js +34 -2
  13. package/dist/llms/yandex.cjs +100 -0
  14. package/dist/llms/yandex.d.ts +40 -0
  15. package/dist/llms/yandex.js +96 -0
  16. package/dist/load/import_constants.cjs +3 -0
  17. package/dist/load/import_constants.js +3 -0
  18. package/dist/load/import_map.cjs +6 -2
  19. package/dist/load/import_map.d.ts +4 -0
  20. package/dist/load/import_map.js +4 -0
  21. package/dist/prompts/chat.cjs +19 -2
  22. package/dist/prompts/chat.d.ts +1 -0
  23. package/dist/prompts/chat.js +19 -2
  24. package/dist/retrievers/multi_vector.d.ts +3 -3
  25. package/dist/retrievers/parent_document.cjs +6 -16
  26. package/dist/retrievers/parent_document.d.ts +5 -12
  27. package/dist/retrievers/parent_document.js +6 -16
  28. package/dist/retrievers/self_query/base.cjs +4 -1
  29. package/dist/retrievers/self_query/base.d.ts +3 -2
  30. package/dist/retrievers/self_query/base.js +4 -1
  31. package/dist/retrievers/self_query/index.cjs +2 -2
  32. package/dist/retrievers/self_query/index.d.ts +2 -0
  33. package/dist/retrievers/self_query/index.js +2 -2
  34. package/dist/runnables/remote.cjs +225 -0
  35. package/dist/runnables/remote.d.ts +28 -0
  36. package/dist/runnables/remote.js +221 -0
  37. package/dist/schema/index.cjs +1 -1
  38. package/dist/schema/index.d.ts +1 -1
  39. package/dist/schema/index.js +1 -1
  40. package/dist/schema/runnable/base.cjs +4 -4
  41. package/dist/schema/runnable/base.d.ts +9 -7
  42. package/dist/schema/runnable/base.js +4 -4
  43. package/dist/schema/runnable/remote.cjs +225 -0
  44. package/dist/schema/runnable/remote.d.ts +28 -0
  45. package/dist/schema/runnable/remote.js +221 -0
  46. package/dist/schema/storage.d.ts +28 -1
  47. package/dist/storage/encoder_backed.cjs +14 -2
  48. package/dist/storage/encoder_backed.d.ts +2 -0
  49. package/dist/storage/encoder_backed.js +12 -1
  50. package/dist/storage/in_memory.cjs +1 -1
  51. package/dist/storage/in_memory.js +1 -1
  52. package/dist/storage/ioredis.cjs +4 -4
  53. package/dist/storage/ioredis.js +4 -4
  54. package/dist/storage/vercel_kv.cjs +146 -0
  55. package/dist/storage/vercel_kv.d.ts +46 -0
  56. package/dist/storage/vercel_kv.js +142 -0
  57. package/dist/stores/doc/in_memory.cjs +13 -0
  58. package/dist/stores/doc/in_memory.d.ts +6 -1
  59. package/dist/stores/doc/in_memory.js +13 -0
  60. package/dist/stores/message/momento.cjs +11 -11
  61. package/dist/stores/message/momento.d.ts +1 -1
  62. package/dist/stores/message/momento.js +1 -1
  63. package/dist/util/time.cjs +14 -0
  64. package/dist/util/time.d.ts +6 -0
  65. package/dist/util/time.js +10 -0
  66. package/dist/vectorstores/cassandra.cjs +4 -2
  67. package/dist/vectorstores/cassandra.js +4 -2
  68. package/dist/vectorstores/elasticsearch.cjs +3 -1
  69. package/dist/vectorstores/elasticsearch.js +3 -1
  70. package/dist/vectorstores/momento_vector_index.cjs +292 -0
  71. package/dist/vectorstores/momento_vector_index.d.ts +135 -0
  72. package/dist/vectorstores/momento_vector_index.js +265 -0
  73. package/dist/vectorstores/neo4j_vector.cjs +578 -0
  74. package/dist/vectorstores/neo4j_vector.d.ts +61 -0
  75. package/dist/vectorstores/neo4j_vector.js +548 -0
  76. package/dist/vectorstores/supabase.cjs +37 -8
  77. package/dist/vectorstores/supabase.d.ts +28 -1
  78. package/dist/vectorstores/supabase.js +37 -8
  79. package/llms/yandex.cjs +1 -0
  80. package/llms/yandex.d.ts +1 -0
  81. package/llms/yandex.js +1 -0
  82. package/package.json +73 -3
  83. package/runnables/remote.cjs +1 -0
  84. package/runnables/remote.d.ts +1 -0
  85. package/runnables/remote.js +1 -0
  86. package/storage/encoder_backed.cjs +1 -0
  87. package/storage/encoder_backed.d.ts +1 -0
  88. package/storage/encoder_backed.js +1 -0
  89. package/storage/vercel_kv.cjs +1 -0
  90. package/storage/vercel_kv.d.ts +1 -0
  91. package/storage/vercel_kv.js +1 -0
  92. package/util/time.cjs +1 -0
  93. package/util/time.d.ts +1 -0
  94. package/util/time.js +1 -0
  95. package/vectorstores/momento_vector_index.cjs +1 -0
  96. package/vectorstores/momento_vector_index.d.ts +1 -0
  97. package/vectorstores/momento_vector_index.js +1 -0
  98. package/vectorstores/neo4j_vector.cjs +1 -0
  99. package/vectorstores/neo4j_vector.d.ts +1 -0
  100. package/vectorstores/neo4j_vector.js +1 -0
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VercelKVStore = void 0;
4
+ const kv_1 = require("@vercel/kv");
5
+ const storage_js_1 = require("../schema/storage.cjs");
6
+ /**
7
+ * Class that extends the BaseStore class to interact with a Vercel KV
8
+ * database. It provides methods for getting, setting, and deleting data,
9
+ * as well as yielding keys from the database.
10
+ */
11
+ class VercelKVStore extends storage_js_1.BaseStore {
12
+ constructor(fields) {
13
+ super(fields);
14
+ Object.defineProperty(this, "lc_namespace", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: ["langchain", "storage"]
19
+ });
20
+ Object.defineProperty(this, "client", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ Object.defineProperty(this, "ttl", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ Object.defineProperty(this, "namespace", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "yieldKeysScanBatchSize", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: 1000
43
+ });
44
+ this.client = fields?.client ?? kv_1.kv;
45
+ this.ttl = fields?.ttl;
46
+ this.namespace = fields?.namespace;
47
+ this.yieldKeysScanBatchSize =
48
+ fields?.yieldKeysScanBatchSize ?? this.yieldKeysScanBatchSize;
49
+ }
50
+ _getPrefixedKey(key) {
51
+ if (this.namespace) {
52
+ const delimiter = "/";
53
+ return `${this.namespace}${delimiter}${key}`;
54
+ }
55
+ return key;
56
+ }
57
+ _getDeprefixedKey(key) {
58
+ if (this.namespace) {
59
+ const delimiter = "/";
60
+ return key.slice(this.namespace.length + delimiter.length);
61
+ }
62
+ return key;
63
+ }
64
+ /**
65
+ * Gets multiple keys from the Redis database.
66
+ * @param keys Array of keys to be retrieved.
67
+ * @returns An array of retrieved values.
68
+ */
69
+ async mget(keys) {
70
+ const prefixedKeys = keys.map(this._getPrefixedKey.bind(this));
71
+ const retrievedValues = await this.client.mget(...prefixedKeys);
72
+ const encoder = new TextEncoder();
73
+ return retrievedValues.map((value) => {
74
+ if (value === undefined || value === null) {
75
+ return undefined;
76
+ }
77
+ else if (typeof value === "object") {
78
+ return encoder.encode(JSON.stringify(value));
79
+ }
80
+ else {
81
+ return encoder.encode(value);
82
+ }
83
+ });
84
+ }
85
+ /**
86
+ * Sets multiple keys in the Redis database.
87
+ * @param keyValuePairs Array of key-value pairs to be set.
88
+ * @returns Promise that resolves when all keys have been set.
89
+ */
90
+ async mset(keyValuePairs) {
91
+ const decoder = new TextDecoder();
92
+ const decodedKeyValuePairs = keyValuePairs.map(([key, value]) => [
93
+ this._getPrefixedKey(key),
94
+ decoder.decode(value),
95
+ ]);
96
+ const pipeline = this.client.pipeline();
97
+ for (const [key, value] of decodedKeyValuePairs) {
98
+ if (this.ttl) {
99
+ pipeline.setex(key, this.ttl, value);
100
+ }
101
+ else {
102
+ pipeline.set(key, value);
103
+ }
104
+ }
105
+ await pipeline.exec();
106
+ }
107
+ /**
108
+ * Deletes multiple keys from the Redis database.
109
+ * @param keys Array of keys to be deleted.
110
+ * @returns Promise that resolves when all keys have been deleted.
111
+ */
112
+ async mdelete(keys) {
113
+ await this.client.del(...keys.map(this._getPrefixedKey.bind(this)));
114
+ }
115
+ /**
116
+ * Yields keys from the Redis database.
117
+ * @param prefix Optional prefix to filter the keys.
118
+ * @returns An AsyncGenerator that yields keys from the Redis database.
119
+ */
120
+ async *yieldKeys(prefix) {
121
+ let pattern;
122
+ if (prefix) {
123
+ pattern = this._getPrefixedKey(prefix);
124
+ }
125
+ else {
126
+ pattern = this._getPrefixedKey("*");
127
+ }
128
+ let [cursor, batch] = await this.client.scan(0, {
129
+ match: pattern,
130
+ count: this.yieldKeysScanBatchSize,
131
+ });
132
+ for (const key of batch) {
133
+ yield this._getDeprefixedKey(key);
134
+ }
135
+ while (cursor !== 0) {
136
+ [cursor, batch] = await this.client.scan(cursor, {
137
+ match: pattern,
138
+ count: this.yieldKeysScanBatchSize,
139
+ });
140
+ for (const key of batch) {
141
+ yield this._getDeprefixedKey(key);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ exports.VercelKVStore = VercelKVStore;
@@ -0,0 +1,46 @@
1
+ import { type VercelKV } from "@vercel/kv";
2
+ import { BaseStore } from "../schema/storage.js";
3
+ /**
4
+ * Class that extends the BaseStore class to interact with a Vercel KV
5
+ * database. It provides methods for getting, setting, and deleting data,
6
+ * as well as yielding keys from the database.
7
+ */
8
+ export declare class VercelKVStore extends BaseStore<string, Uint8Array> {
9
+ lc_namespace: string[];
10
+ protected client: VercelKV;
11
+ protected ttl?: number;
12
+ protected namespace?: string;
13
+ protected yieldKeysScanBatchSize: number;
14
+ constructor(fields?: {
15
+ client?: VercelKV;
16
+ ttl?: number;
17
+ namespace?: string;
18
+ yieldKeysScanBatchSize?: number;
19
+ });
20
+ _getPrefixedKey(key: string): string;
21
+ _getDeprefixedKey(key: string): string;
22
+ /**
23
+ * Gets multiple keys from the Redis database.
24
+ * @param keys Array of keys to be retrieved.
25
+ * @returns An array of retrieved values.
26
+ */
27
+ mget(keys: string[]): Promise<(Uint8Array | undefined)[]>;
28
+ /**
29
+ * Sets multiple keys in the Redis database.
30
+ * @param keyValuePairs Array of key-value pairs to be set.
31
+ * @returns Promise that resolves when all keys have been set.
32
+ */
33
+ mset(keyValuePairs: [string, Uint8Array][]): Promise<void>;
34
+ /**
35
+ * Deletes multiple keys from the Redis database.
36
+ * @param keys Array of keys to be deleted.
37
+ * @returns Promise that resolves when all keys have been deleted.
38
+ */
39
+ mdelete(keys: string[]): Promise<void>;
40
+ /**
41
+ * Yields keys from the Redis database.
42
+ * @param prefix Optional prefix to filter the keys.
43
+ * @returns An AsyncGenerator that yields keys from the Redis database.
44
+ */
45
+ yieldKeys(prefix?: string): AsyncGenerator<string>;
46
+ }
@@ -0,0 +1,142 @@
1
+ import { kv } from "@vercel/kv";
2
+ import { BaseStore } from "../schema/storage.js";
3
+ /**
4
+ * Class that extends the BaseStore class to interact with a Vercel KV
5
+ * database. It provides methods for getting, setting, and deleting data,
6
+ * as well as yielding keys from the database.
7
+ */
8
+ export class VercelKVStore extends BaseStore {
9
+ constructor(fields) {
10
+ super(fields);
11
+ Object.defineProperty(this, "lc_namespace", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: ["langchain", "storage"]
16
+ });
17
+ Object.defineProperty(this, "client", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "ttl", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "namespace", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "yieldKeysScanBatchSize", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: 1000
40
+ });
41
+ this.client = fields?.client ?? kv;
42
+ this.ttl = fields?.ttl;
43
+ this.namespace = fields?.namespace;
44
+ this.yieldKeysScanBatchSize =
45
+ fields?.yieldKeysScanBatchSize ?? this.yieldKeysScanBatchSize;
46
+ }
47
+ _getPrefixedKey(key) {
48
+ if (this.namespace) {
49
+ const delimiter = "/";
50
+ return `${this.namespace}${delimiter}${key}`;
51
+ }
52
+ return key;
53
+ }
54
+ _getDeprefixedKey(key) {
55
+ if (this.namespace) {
56
+ const delimiter = "/";
57
+ return key.slice(this.namespace.length + delimiter.length);
58
+ }
59
+ return key;
60
+ }
61
+ /**
62
+ * Gets multiple keys from the Redis database.
63
+ * @param keys Array of keys to be retrieved.
64
+ * @returns An array of retrieved values.
65
+ */
66
+ async mget(keys) {
67
+ const prefixedKeys = keys.map(this._getPrefixedKey.bind(this));
68
+ const retrievedValues = await this.client.mget(...prefixedKeys);
69
+ const encoder = new TextEncoder();
70
+ return retrievedValues.map((value) => {
71
+ if (value === undefined || value === null) {
72
+ return undefined;
73
+ }
74
+ else if (typeof value === "object") {
75
+ return encoder.encode(JSON.stringify(value));
76
+ }
77
+ else {
78
+ return encoder.encode(value);
79
+ }
80
+ });
81
+ }
82
+ /**
83
+ * Sets multiple keys in the Redis database.
84
+ * @param keyValuePairs Array of key-value pairs to be set.
85
+ * @returns Promise that resolves when all keys have been set.
86
+ */
87
+ async mset(keyValuePairs) {
88
+ const decoder = new TextDecoder();
89
+ const decodedKeyValuePairs = keyValuePairs.map(([key, value]) => [
90
+ this._getPrefixedKey(key),
91
+ decoder.decode(value),
92
+ ]);
93
+ const pipeline = this.client.pipeline();
94
+ for (const [key, value] of decodedKeyValuePairs) {
95
+ if (this.ttl) {
96
+ pipeline.setex(key, this.ttl, value);
97
+ }
98
+ else {
99
+ pipeline.set(key, value);
100
+ }
101
+ }
102
+ await pipeline.exec();
103
+ }
104
+ /**
105
+ * Deletes multiple keys from the Redis database.
106
+ * @param keys Array of keys to be deleted.
107
+ * @returns Promise that resolves when all keys have been deleted.
108
+ */
109
+ async mdelete(keys) {
110
+ await this.client.del(...keys.map(this._getPrefixedKey.bind(this)));
111
+ }
112
+ /**
113
+ * Yields keys from the Redis database.
114
+ * @param prefix Optional prefix to filter the keys.
115
+ * @returns An AsyncGenerator that yields keys from the Redis database.
116
+ */
117
+ async *yieldKeys(prefix) {
118
+ let pattern;
119
+ if (prefix) {
120
+ pattern = this._getPrefixedKey(prefix);
121
+ }
122
+ else {
123
+ pattern = this._getPrefixedKey("*");
124
+ }
125
+ let [cursor, batch] = await this.client.scan(0, {
126
+ match: pattern,
127
+ count: this.yieldKeysScanBatchSize,
128
+ });
129
+ for (const key of batch) {
130
+ yield this._getDeprefixedKey(key);
131
+ }
132
+ while (cursor !== 0) {
133
+ [cursor, batch] = await this.client.scan(cursor, {
134
+ match: pattern,
135
+ count: this.yieldKeysScanBatchSize,
136
+ });
137
+ for (const key of batch) {
138
+ yield this._getDeprefixedKey(key);
139
+ }
140
+ }
141
+ }
142
+ }
@@ -46,6 +46,19 @@ class InMemoryDocstore extends index_js_1.Docstore {
46
46
  this._docs.set(key, value);
47
47
  }
48
48
  }
49
+ async mget(keys) {
50
+ return Promise.all(keys.map((key) => this.search(key)));
51
+ }
52
+ async mset(keyValuePairs) {
53
+ await Promise.all(keyValuePairs.map(([key, value]) => this.add({ [key]: value })));
54
+ }
55
+ async mdelete(_keys) {
56
+ throw new Error("Not implemented.");
57
+ }
58
+ // eslint-disable-next-line require-yield
59
+ async *yieldKeys(_prefix) {
60
+ throw new Error("Not implemented");
61
+ }
49
62
  }
50
63
  exports.InMemoryDocstore = InMemoryDocstore;
51
64
  /**
@@ -1,10 +1,11 @@
1
1
  import { Document } from "../../document.js";
2
2
  import { Docstore } from "../../schema/index.js";
3
+ import { BaseStoreInterface } from "../../schema/storage.js";
3
4
  /**
4
5
  * Class for storing and retrieving documents in memory asynchronously.
5
6
  * Extends the Docstore class.
6
7
  */
7
- export declare class InMemoryDocstore extends Docstore {
8
+ export declare class InMemoryDocstore extends Docstore implements BaseStoreInterface<string, Document> {
8
9
  _docs: Map<string, Document>;
9
10
  constructor(docs?: Map<string, Document>);
10
11
  /**
@@ -19,6 +20,10 @@ export declare class InMemoryDocstore extends Docstore {
19
20
  * @returns Void
20
21
  */
21
22
  add(texts: Record<string, Document>): Promise<void>;
23
+ mget(keys: string[]): Promise<Document[]>;
24
+ mset(keyValuePairs: [string, Document][]): Promise<void>;
25
+ mdelete(_keys: string[]): Promise<void>;
26
+ yieldKeys(_prefix?: string): AsyncGenerator<string>;
22
27
  }
23
28
  /**
24
29
  * Class for storing and retrieving documents in memory synchronously.
@@ -43,6 +43,19 @@ export class InMemoryDocstore extends Docstore {
43
43
  this._docs.set(key, value);
44
44
  }
45
45
  }
46
+ async mget(keys) {
47
+ return Promise.all(keys.map((key) => this.search(key)));
48
+ }
49
+ async mset(keyValuePairs) {
50
+ await Promise.all(keyValuePairs.map(([key, value]) => this.add({ [key]: value })));
51
+ }
52
+ async mdelete(_keys) {
53
+ throw new Error("Not implemented.");
54
+ }
55
+ // eslint-disable-next-line require-yield
56
+ async *yieldKeys(_prefix) {
57
+ throw new Error("Not implemented");
58
+ }
46
59
  }
47
60
  /**
48
61
  * Class for storing and retrieving documents in memory synchronously.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MomentoChatMessageHistory = void 0;
4
4
  /* eslint-disable no-instanceof/no-instanceof */
5
- const sdk_1 = require("@gomomento/sdk");
5
+ const sdk_core_1 = require("@gomomento/sdk-core");
6
6
  const index_js_1 = require("../../schema/index.cjs");
7
7
  const utils_js_1 = require("./utils.cjs");
8
8
  const momento_js_1 = require("../../util/momento.cjs");
@@ -50,8 +50,8 @@ class MomentoChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
50
50
  this.validateTtlSeconds(props.sessionTtl);
51
51
  this.sessionTtl =
52
52
  props.sessionTtl !== undefined
53
- ? sdk_1.CollectionTtl.of(props.sessionTtl)
54
- : sdk_1.CollectionTtl.fromCacheTtl();
53
+ ? sdk_core_1.CollectionTtl.of(props.sessionTtl)
54
+ : sdk_core_1.CollectionTtl.fromCacheTtl();
55
55
  }
56
56
  /**
57
57
  * Create a new chat message history backed by Momento.
@@ -80,7 +80,7 @@ class MomentoChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
80
80
  */
81
81
  validateTtlSeconds(ttlSeconds) {
82
82
  if (ttlSeconds !== undefined && ttlSeconds <= 0) {
83
- throw new sdk_1.InvalidArgumentError("ttlSeconds must be positive.");
83
+ throw new sdk_core_1.InvalidArgumentError("ttlSeconds must be positive.");
84
84
  }
85
85
  }
86
86
  /**
@@ -90,15 +90,15 @@ class MomentoChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
90
90
  async getMessages() {
91
91
  const fetchResponse = await this.client.listFetch(this.cacheName, this.sessionId);
92
92
  let messages = [];
93
- if (fetchResponse instanceof sdk_1.CacheListFetch.Hit) {
93
+ if (fetchResponse instanceof sdk_core_1.CacheListFetch.Hit) {
94
94
  messages = fetchResponse
95
95
  .valueList()
96
96
  .map((serializedStoredMessage) => JSON.parse(serializedStoredMessage));
97
97
  }
98
- else if (fetchResponse instanceof sdk_1.CacheListFetch.Miss) {
98
+ else if (fetchResponse instanceof sdk_core_1.CacheListFetch.Miss) {
99
99
  // pass
100
100
  }
101
- else if (fetchResponse instanceof sdk_1.CacheListFetch.Error) {
101
+ else if (fetchResponse instanceof sdk_core_1.CacheListFetch.Error) {
102
102
  throw fetchResponse.innerException();
103
103
  }
104
104
  else {
@@ -114,10 +114,10 @@ class MomentoChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
114
114
  async addMessage(message) {
115
115
  const messageToAdd = JSON.stringify((0, utils_js_1.mapChatMessagesToStoredMessages)([message])[0]);
116
116
  const pushResponse = await this.client.listPushBack(this.cacheName, this.sessionId, messageToAdd, { ttl: this.sessionTtl });
117
- if (pushResponse instanceof sdk_1.CacheListPushBack.Success) {
117
+ if (pushResponse instanceof sdk_core_1.CacheListPushBack.Success) {
118
118
  // pass
119
119
  }
120
- else if (pushResponse instanceof sdk_1.CacheListPushBack.Error) {
120
+ else if (pushResponse instanceof sdk_core_1.CacheListPushBack.Error) {
121
121
  throw pushResponse.innerException();
122
122
  }
123
123
  else {
@@ -130,10 +130,10 @@ class MomentoChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
130
130
  */
131
131
  async clear() {
132
132
  const deleteResponse = await this.client.delete(this.cacheName, this.sessionId);
133
- if (deleteResponse instanceof sdk_1.CacheDelete.Success) {
133
+ if (deleteResponse instanceof sdk_core_1.CacheDelete.Success) {
134
134
  // pass
135
135
  }
136
- else if (deleteResponse instanceof sdk_1.CacheDelete.Error) {
136
+ else if (deleteResponse instanceof sdk_core_1.CacheDelete.Error) {
137
137
  throw deleteResponse.innerException();
138
138
  }
139
139
  else {
@@ -1,4 +1,4 @@
1
- import { ICacheClient } from "@gomomento/sdk";
1
+ import { ICacheClient } from "@gomomento/sdk-core";
2
2
  import { BaseMessage, BaseListChatMessageHistory } from "../../schema/index.js";
3
3
  /**
4
4
  * The settings to instantiate the Momento chat message history.
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-instanceof/no-instanceof */
2
- import { CacheDelete, CacheListFetch, CacheListPushBack, InvalidArgumentError, CollectionTtl, } from "@gomomento/sdk";
2
+ import { CacheDelete, CacheListFetch, CacheListPushBack, InvalidArgumentError, CollectionTtl, } from "@gomomento/sdk-core";
3
3
  import { BaseListChatMessageHistory, } from "../../schema/index.js";
4
4
  import { mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, } from "./utils.js";
5
5
  import { ensureCacheExists } from "../../util/momento.js";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sleep = void 0;
4
+ /**
5
+ * Sleep for a given amount of time.
6
+ * @param ms - The number of milliseconds to sleep for. Defaults to 1000.
7
+ * @returns A promise that resolves when the sleep is complete.
8
+ */
9
+ async function sleep(ms = 1000) {
10
+ return new Promise((resolve) => {
11
+ setTimeout(resolve, ms);
12
+ });
13
+ }
14
+ exports.sleep = sleep;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sleep for a given amount of time.
3
+ * @param ms - The number of milliseconds to sleep for. Defaults to 1000.
4
+ * @returns A promise that resolves when the sleep is complete.
5
+ */
6
+ export declare function sleep(ms?: number): Promise<void>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Sleep for a given amount of time.
3
+ * @param ms - The number of milliseconds to sleep for. Defaults to 1000.
4
+ * @returns A promise that resolves when the sleep is complete.
5
+ */
6
+ export async function sleep(ms = 1000) {
7
+ return new Promise((resolve) => {
8
+ setTimeout(resolve, ms);
9
+ });
10
+ }
@@ -170,7 +170,8 @@ class CassandraStore extends base_js_1.VectorStore {
170
170
  : ""}
171
171
  vector VECTOR<FLOAT, ${this.dimensions}>
172
172
  );`);
173
- await this.client.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ann_index
173
+ await this.client
174
+ .execute(`CREATE CUSTOM INDEX IF NOT EXISTS idx_vector_${this.table}
174
175
  ON ${this.keyspace}.${this.table}(vector) USING 'StorageAttachedIndex';`);
175
176
  this.isInitialized = true;
176
177
  }
@@ -188,7 +189,8 @@ class CassandraStore extends base_js_1.VectorStore {
188
189
  const document = documents[index];
189
190
  const metadataColNames = Object.keys(document.metadata);
190
191
  const metadataVals = Object.values(document.metadata);
191
- const query = `INSERT INTO ${this.keyspace}.${this.table} (vector, text${metadataColNames.length > 0 ? ", " + metadataColNames.join(", ") : ""}) VALUES ([${vector}], '${document.pageContent}'${metadataVals.length > 0
192
+ const metadataInsert = metadataColNames.length > 0 ? ", " + metadataColNames.join(", ") : "";
193
+ const query = `INSERT INTO ${this.keyspace}.${this.table} (vector, text${metadataInsert}) VALUES ([${vector}], '${document.pageContent}'${metadataVals.length > 0
192
194
  ? ", " +
193
195
  metadataVals
194
196
  .map((val) => (typeof val === "number" ? val : `'${val}'`))
@@ -167,7 +167,8 @@ export class CassandraStore extends VectorStore {
167
167
  : ""}
168
168
  vector VECTOR<FLOAT, ${this.dimensions}>
169
169
  );`);
170
- await this.client.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ann_index
170
+ await this.client
171
+ .execute(`CREATE CUSTOM INDEX IF NOT EXISTS idx_vector_${this.table}
171
172
  ON ${this.keyspace}.${this.table}(vector) USING 'StorageAttachedIndex';`);
172
173
  this.isInitialized = true;
173
174
  }
@@ -185,7 +186,8 @@ export class CassandraStore extends VectorStore {
185
186
  const document = documents[index];
186
187
  const metadataColNames = Object.keys(document.metadata);
187
188
  const metadataVals = Object.values(document.metadata);
188
- const query = `INSERT INTO ${this.keyspace}.${this.table} (vector, text${metadataColNames.length > 0 ? ", " + metadataColNames.join(", ") : ""}) VALUES ([${vector}], '${document.pageContent}'${metadataVals.length > 0
189
+ const metadataInsert = metadataColNames.length > 0 ? ", " + metadataColNames.join(", ") : "";
190
+ const query = `INSERT INTO ${this.keyspace}.${this.table} (vector, text${metadataInsert}) VALUES ([${vector}], '${document.pageContent}'${metadataVals.length > 0
189
191
  ? ", " +
190
192
  metadataVals
191
193
  .map((val) => (typeof val === "number" ? val : `'${val}'`))
@@ -86,7 +86,9 @@ class ElasticVectorSearch extends base_js_1.VectorStore {
86
86
  this.m = args.vectorSearchOptions?.m ?? 16;
87
87
  this.efConstruction = args.vectorSearchOptions?.efConstruction ?? 100;
88
88
  this.candidates = args.vectorSearchOptions?.candidates ?? 200;
89
- this.client = args.client;
89
+ this.client = args.client.child({
90
+ headers: { "user-agent": "langchain-js-vs/0.0.1" },
91
+ });
90
92
  this.indexName = args.indexName ?? "documents";
91
93
  }
92
94
  /**
@@ -60,7 +60,9 @@ export class ElasticVectorSearch extends VectorStore {
60
60
  this.m = args.vectorSearchOptions?.m ?? 16;
61
61
  this.efConstruction = args.vectorSearchOptions?.efConstruction ?? 100;
62
62
  this.candidates = args.vectorSearchOptions?.candidates ?? 200;
63
- this.client = args.client;
63
+ this.client = args.client.child({
64
+ headers: { "user-agent": "langchain-js-vs/0.0.1" },
65
+ });
64
66
  this.indexName = args.indexName ?? "documents";
65
67
  }
66
68
  /**