langchain 0.0.165 → 0.0.166

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 (57) 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/experimental/chat_models/anthropic_functions.cjs +34 -2
  8. package/dist/experimental/chat_models/anthropic_functions.d.ts +15 -5
  9. package/dist/experimental/chat_models/anthropic_functions.js +34 -2
  10. package/dist/load/import_constants.cjs +1 -0
  11. package/dist/load/import_constants.js +1 -0
  12. package/dist/load/import_map.cjs +3 -1
  13. package/dist/load/import_map.d.ts +2 -0
  14. package/dist/load/import_map.js +2 -0
  15. package/dist/prompts/chat.cjs +19 -2
  16. package/dist/prompts/chat.d.ts +1 -0
  17. package/dist/prompts/chat.js +19 -2
  18. package/dist/retrievers/self_query/base.cjs +4 -1
  19. package/dist/retrievers/self_query/base.d.ts +3 -2
  20. package/dist/retrievers/self_query/base.js +4 -1
  21. package/dist/retrievers/self_query/index.cjs +2 -2
  22. package/dist/retrievers/self_query/index.d.ts +2 -0
  23. package/dist/retrievers/self_query/index.js +2 -2
  24. package/dist/runnables/remote.cjs +225 -0
  25. package/dist/runnables/remote.d.ts +28 -0
  26. package/dist/runnables/remote.js +221 -0
  27. package/dist/schema/index.cjs +1 -1
  28. package/dist/schema/index.d.ts +1 -1
  29. package/dist/schema/index.js +1 -1
  30. package/dist/schema/runnable/base.cjs +4 -4
  31. package/dist/schema/runnable/base.d.ts +9 -7
  32. package/dist/schema/runnable/base.js +4 -4
  33. package/dist/schema/runnable/remote.cjs +225 -0
  34. package/dist/schema/runnable/remote.d.ts +28 -0
  35. package/dist/schema/runnable/remote.js +221 -0
  36. package/dist/stores/message/momento.cjs +11 -11
  37. package/dist/stores/message/momento.d.ts +1 -1
  38. package/dist/stores/message/momento.js +1 -1
  39. package/dist/util/time.cjs +14 -0
  40. package/dist/util/time.d.ts +6 -0
  41. package/dist/util/time.js +10 -0
  42. package/dist/vectorstores/momento_vector_index.cjs +292 -0
  43. package/dist/vectorstores/momento_vector_index.d.ts +135 -0
  44. package/dist/vectorstores/momento_vector_index.js +265 -0
  45. package/dist/vectorstores/supabase.cjs +37 -8
  46. package/dist/vectorstores/supabase.d.ts +28 -1
  47. package/dist/vectorstores/supabase.js +37 -8
  48. package/package.json +36 -3
  49. package/runnables/remote.cjs +1 -0
  50. package/runnables/remote.d.ts +1 -0
  51. package/runnables/remote.js +1 -0
  52. package/util/time.cjs +1 -0
  53. package/util/time.d.ts +1 -0
  54. package/util/time.js +1 -0
  55. package/vectorstores/momento_vector_index.cjs +1 -0
  56. package/vectorstores/momento_vector_index.d.ts +1 -0
  57. package/vectorstores/momento_vector_index.js +1 -0
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SupabaseVectorStore = void 0;
4
4
  const base_js_1 = require("./base.cjs");
5
5
  const document_js_1 = require("../document.cjs");
6
+ const math_js_1 = require("../util/math.cjs");
6
7
  /**
7
8
  * Class for interacting with a Supabase database to store and manage
8
9
  * vectors.
@@ -103,14 +104,7 @@ class SupabaseVectorStore extends base_js_1.VectorStore {
103
104
  await this.client.from(this.tableName).delete().eq("id", id);
104
105
  }
105
106
  }
106
- /**
107
- * Performs a similarity search on the vector store.
108
- * @param query The query vector.
109
- * @param k The number of results to return.
110
- * @param filter Optional filter to apply to the search.
111
- * @returns A promise that resolves with the search results when the search is complete.
112
- */
113
- async similaritySearchVectorWithScore(query, k, filter) {
107
+ async _searchSupabase(query, k, filter) {
114
108
  if (filter && this.filter) {
115
109
  throw new Error("cannot provide both `filter` and `this.filter`");
116
110
  }
@@ -135,6 +129,17 @@ class SupabaseVectorStore extends base_js_1.VectorStore {
135
129
  if (error) {
136
130
  throw new Error(`Error searching for documents: ${error.code} ${error.message} ${error.details}`);
137
131
  }
132
+ return searches;
133
+ }
134
+ /**
135
+ * Performs a similarity search on the vector store.
136
+ * @param query The query vector.
137
+ * @param k The number of results to return.
138
+ * @param filter Optional filter to apply to the search.
139
+ * @returns A promise that resolves with the search results when the search is complete.
140
+ */
141
+ async similaritySearchVectorWithScore(query, k, filter) {
142
+ const searches = await this._searchSupabase(query, k, filter);
138
143
  const result = searches.map((resp) => [
139
144
  new document_js_1.Document({
140
145
  metadata: resp.metadata,
@@ -144,6 +149,30 @@ class SupabaseVectorStore extends base_js_1.VectorStore {
144
149
  ]);
145
150
  return result;
146
151
  }
152
+ /**
153
+ * Return documents selected using the maximal marginal relevance.
154
+ * Maximal marginal relevance optimizes for similarity to the query AND diversity
155
+ * among selected documents.
156
+ *
157
+ * @param {string} query - Text to look up documents similar to.
158
+ * @param {number} options.k - Number of documents to return.
159
+ * @param {number} options.fetchK=20- Number of documents to fetch before passing to the MMR algorithm.
160
+ * @param {number} options.lambda=0.5 - Number between 0 and 1 that determines the degree of diversity among the results,
161
+ * where 0 corresponds to maximum diversity and 1 to minimum diversity.
162
+ * @param {SupabaseLibArgs} options.filter - Optional filter to apply to the search.
163
+ *
164
+ * @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.
165
+ */
166
+ async maxMarginalRelevanceSearch(query, options) {
167
+ const queryEmbedding = await this.embeddings.embedQuery(query);
168
+ const searches = await this._searchSupabase(queryEmbedding, options.fetchK ?? 20, options.filter);
169
+ const embeddingList = searches.map((searchResp) => searchResp.embedding);
170
+ const mmrIndexes = (0, math_js_1.maximalMarginalRelevance)(queryEmbedding, embeddingList, options.lambda, options.k);
171
+ return mmrIndexes.map((idx) => new document_js_1.Document({
172
+ metadata: searches[idx].metadata,
173
+ pageContent: searches[idx].content,
174
+ }));
175
+ }
147
176
  /**
148
177
  * Creates a new SupabaseVectorStore instance from an array of texts.
149
178
  * @param texts The texts to create documents from.
@@ -1,11 +1,21 @@
1
1
  import type { SupabaseClient } from "@supabase/supabase-js";
2
2
  import type { PostgrestFilterBuilder } from "@supabase/postgrest-js";
3
- import { VectorStore } from "./base.js";
3
+ import { MaxMarginalRelevanceSearchOptions, VectorStore } from "./base.js";
4
4
  import { Embeddings } from "../embeddings/base.js";
5
5
  import { Document } from "../document.js";
6
6
  export type SupabaseMetadata = Record<string, any>;
7
7
  export type SupabaseFilter = PostgrestFilterBuilder<any, any, any>;
8
8
  export type SupabaseFilterRPCCall = (rpcCall: SupabaseFilter) => SupabaseFilter;
9
+ /**
10
+ * Interface for the response returned when searching embeddings.
11
+ */
12
+ interface SearchEmbeddingsResponse {
13
+ id: number;
14
+ content: string;
15
+ metadata: object;
16
+ embedding: number[];
17
+ similarity: number;
18
+ }
9
19
  /**
10
20
  * Interface for the arguments required to initialize a Supabase library.
11
21
  */
@@ -56,6 +66,7 @@ export declare class SupabaseVectorStore extends VectorStore {
56
66
  delete(params: {
57
67
  ids: string[] | number[];
58
68
  }): Promise<void>;
69
+ protected _searchSupabase(query: number[], k: number, filter?: this["FilterType"]): Promise<SearchEmbeddingsResponse[]>;
59
70
  /**
60
71
  * Performs a similarity search on the vector store.
61
72
  * @param query The query vector.
@@ -64,6 +75,21 @@ export declare class SupabaseVectorStore extends VectorStore {
64
75
  * @returns A promise that resolves with the search results when the search is complete.
65
76
  */
66
77
  similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
78
+ /**
79
+ * Return documents selected using the maximal marginal relevance.
80
+ * Maximal marginal relevance optimizes for similarity to the query AND diversity
81
+ * among selected documents.
82
+ *
83
+ * @param {string} query - Text to look up documents similar to.
84
+ * @param {number} options.k - Number of documents to return.
85
+ * @param {number} options.fetchK=20- Number of documents to fetch before passing to the MMR algorithm.
86
+ * @param {number} options.lambda=0.5 - Number between 0 and 1 that determines the degree of diversity among the results,
87
+ * where 0 corresponds to maximum diversity and 1 to minimum diversity.
88
+ * @param {SupabaseLibArgs} options.filter - Optional filter to apply to the search.
89
+ *
90
+ * @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.
91
+ */
92
+ maxMarginalRelevanceSearch(query: string, options: MaxMarginalRelevanceSearchOptions<this["FilterType"]>): Promise<Document[]>;
67
93
  /**
68
94
  * Creates a new SupabaseVectorStore instance from an array of texts.
69
95
  * @param texts The texts to create documents from.
@@ -89,3 +115,4 @@ export declare class SupabaseVectorStore extends VectorStore {
89
115
  */
90
116
  static fromExistingIndex(embeddings: Embeddings, dbConfig: SupabaseLibArgs): Promise<SupabaseVectorStore>;
91
117
  }
118
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { VectorStore } from "./base.js";
2
2
  import { Document } from "../document.js";
3
+ import { maximalMarginalRelevance } from "../util/math.js";
3
4
  /**
4
5
  * Class for interacting with a Supabase database to store and manage
5
6
  * vectors.
@@ -100,14 +101,7 @@ export class SupabaseVectorStore extends VectorStore {
100
101
  await this.client.from(this.tableName).delete().eq("id", id);
101
102
  }
102
103
  }
103
- /**
104
- * Performs a similarity search on the vector store.
105
- * @param query The query vector.
106
- * @param k The number of results to return.
107
- * @param filter Optional filter to apply to the search.
108
- * @returns A promise that resolves with the search results when the search is complete.
109
- */
110
- async similaritySearchVectorWithScore(query, k, filter) {
104
+ async _searchSupabase(query, k, filter) {
111
105
  if (filter && this.filter) {
112
106
  throw new Error("cannot provide both `filter` and `this.filter`");
113
107
  }
@@ -132,6 +126,17 @@ export class SupabaseVectorStore extends VectorStore {
132
126
  if (error) {
133
127
  throw new Error(`Error searching for documents: ${error.code} ${error.message} ${error.details}`);
134
128
  }
129
+ return searches;
130
+ }
131
+ /**
132
+ * Performs a similarity search on the vector store.
133
+ * @param query The query vector.
134
+ * @param k The number of results to return.
135
+ * @param filter Optional filter to apply to the search.
136
+ * @returns A promise that resolves with the search results when the search is complete.
137
+ */
138
+ async similaritySearchVectorWithScore(query, k, filter) {
139
+ const searches = await this._searchSupabase(query, k, filter);
135
140
  const result = searches.map((resp) => [
136
141
  new Document({
137
142
  metadata: resp.metadata,
@@ -141,6 +146,30 @@ export class SupabaseVectorStore extends VectorStore {
141
146
  ]);
142
147
  return result;
143
148
  }
149
+ /**
150
+ * Return documents selected using the maximal marginal relevance.
151
+ * Maximal marginal relevance optimizes for similarity to the query AND diversity
152
+ * among selected documents.
153
+ *
154
+ * @param {string} query - Text to look up documents similar to.
155
+ * @param {number} options.k - Number of documents to return.
156
+ * @param {number} options.fetchK=20- Number of documents to fetch before passing to the MMR algorithm.
157
+ * @param {number} options.lambda=0.5 - Number between 0 and 1 that determines the degree of diversity among the results,
158
+ * where 0 corresponds to maximum diversity and 1 to minimum diversity.
159
+ * @param {SupabaseLibArgs} options.filter - Optional filter to apply to the search.
160
+ *
161
+ * @returns {Promise<Document[]>} - List of documents selected by maximal marginal relevance.
162
+ */
163
+ async maxMarginalRelevanceSearch(query, options) {
164
+ const queryEmbedding = await this.embeddings.embedQuery(query);
165
+ const searches = await this._searchSupabase(queryEmbedding, options.fetchK ?? 20, options.filter);
166
+ const embeddingList = searches.map((searchResp) => searchResp.embedding);
167
+ const mmrIndexes = maximalMarginalRelevance(queryEmbedding, embeddingList, options.lambda, options.k);
168
+ return mmrIndexes.map((idx) => new Document({
169
+ metadata: searches[idx].metadata,
170
+ pageContent: searches[idx].content,
171
+ }));
172
+ }
144
173
  /**
145
174
  * Creates a new SupabaseVectorStore instance from an array of texts.
146
175
  * @param texts The texts to create documents from.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.165",
3
+ "version": "0.0.166",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -217,6 +217,9 @@
217
217
  "vectorstores/lancedb.cjs",
218
218
  "vectorstores/lancedb.js",
219
219
  "vectorstores/lancedb.d.ts",
220
+ "vectorstores/momento_vector_index.cjs",
221
+ "vectorstores/momento_vector_index.js",
222
+ "vectorstores/momento_vector_index.d.ts",
220
223
  "vectorstores/mongo.cjs",
221
224
  "vectorstores/mongo.js",
222
225
  "vectorstores/mongo.d.ts",
@@ -637,6 +640,9 @@
637
640
  "util/math.cjs",
638
641
  "util/math.js",
639
642
  "util/math.d.ts",
643
+ "util/time.cjs",
644
+ "util/time.js",
645
+ "util/time.d.ts",
640
646
  "experimental/autogpt.cjs",
641
647
  "experimental/autogpt.js",
642
648
  "experimental/autogpt.d.ts",
@@ -667,6 +673,9 @@
667
673
  "evaluation.cjs",
668
674
  "evaluation.js",
669
675
  "evaluation.d.ts",
676
+ "runnables/remote.cjs",
677
+ "runnables/remote.js",
678
+ "runnables/remote.d.ts",
670
679
  "index.cjs",
671
680
  "index.js",
672
681
  "index.d.ts"
@@ -714,7 +723,8 @@
714
723
  "@faker-js/faker": "^7.6.0",
715
724
  "@getmetal/metal-sdk": "^4.0.0",
716
725
  "@getzep/zep-js": "^0.7.0",
717
- "@gomomento/sdk": "^1.23.0",
726
+ "@gomomento/sdk": "^1.41.2",
727
+ "@gomomento/sdk-core": "^1.41.2",
718
728
  "@google-ai/generativelanguage": "^0.2.1",
719
729
  "@google-cloud/storage": "^6.10.1",
720
730
  "@huggingface/inference": "^1.5.1",
@@ -843,7 +853,9 @@
843
853
  "@elastic/elasticsearch": "^8.4.0",
844
854
  "@getmetal/metal-sdk": "*",
845
855
  "@getzep/zep-js": "^0.7.0",
846
- "@gomomento/sdk": "^1.23.0",
856
+ "@gomomento/sdk": "^1.41.2",
857
+ "@gomomento/sdk-core": "^1.41.2",
858
+ "@gomomento/sdk-web": "^1.41.2",
847
859
  "@google-ai/generativelanguage": "^0.2.1",
848
860
  "@google-cloud/storage": "^6.10.1",
849
861
  "@huggingface/inference": "^1.5.1",
@@ -966,6 +978,12 @@
966
978
  "@gomomento/sdk": {
967
979
  "optional": true
968
980
  },
981
+ "@gomomento/sdk-core": {
982
+ "optional": true
983
+ },
984
+ "@gomomento/sdk-web": {
985
+ "optional": true
986
+ },
969
987
  "@google-ai/generativelanguage": {
970
988
  "optional": true
971
989
  },
@@ -1570,6 +1588,11 @@
1570
1588
  "import": "./vectorstores/lancedb.js",
1571
1589
  "require": "./vectorstores/lancedb.cjs"
1572
1590
  },
1591
+ "./vectorstores/momento_vector_index": {
1592
+ "types": "./vectorstores/momento_vector_index.d.ts",
1593
+ "import": "./vectorstores/momento_vector_index.js",
1594
+ "require": "./vectorstores/momento_vector_index.cjs"
1595
+ },
1573
1596
  "./vectorstores/mongo": {
1574
1597
  "types": "./vectorstores/mongo.d.ts",
1575
1598
  "import": "./vectorstores/mongo.js",
@@ -2270,6 +2293,11 @@
2270
2293
  "import": "./util/math.js",
2271
2294
  "require": "./util/math.cjs"
2272
2295
  },
2296
+ "./util/time": {
2297
+ "types": "./util/time.d.ts",
2298
+ "import": "./util/time.js",
2299
+ "require": "./util/time.cjs"
2300
+ },
2273
2301
  "./experimental/autogpt": {
2274
2302
  "types": "./experimental/autogpt.d.ts",
2275
2303
  "import": "./experimental/autogpt.js",
@@ -2320,6 +2348,11 @@
2320
2348
  "import": "./evaluation.js",
2321
2349
  "require": "./evaluation.cjs"
2322
2350
  },
2351
+ "./runnables/remote": {
2352
+ "types": "./runnables/remote.d.ts",
2353
+ "import": "./runnables/remote.js",
2354
+ "require": "./runnables/remote.cjs"
2355
+ },
2323
2356
  "./package.json": "./package.json"
2324
2357
  }
2325
2358
  }
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/runnables/remote.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/runnables/remote.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/runnables/remote.js'
package/util/time.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/util/time.cjs');
package/util/time.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '../dist/util/time.js'
package/util/time.js ADDED
@@ -0,0 +1 @@
1
+ export * from '../dist/util/time.js'
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/vectorstores/momento_vector_index.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/vectorstores/momento_vector_index.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/vectorstores/momento_vector_index.js'