langchain 0.1.34 → 0.1.36

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 (72) hide show
  1. package/dist/chains/history_aware_retriever.cjs +1 -2
  2. package/dist/chains/history_aware_retriever.d.ts +1 -2
  3. package/dist/chains/history_aware_retriever.js +1 -2
  4. package/dist/chains/openai_functions/base.cjs +2 -0
  5. package/dist/chains/openai_functions/base.d.ts +2 -0
  6. package/dist/chains/openai_functions/base.js +2 -0
  7. package/dist/chains/query_constructor/index.cjs +5 -8
  8. package/dist/chains/query_constructor/index.d.ts +5 -4
  9. package/dist/chains/query_constructor/index.js +3 -6
  10. package/dist/chains/query_constructor/ir.cjs +15 -139
  11. package/dist/chains/query_constructor/ir.d.ts +1 -138
  12. package/dist/chains/query_constructor/ir.js +1 -132
  13. package/dist/chains/query_constructor/prompt.cjs +2 -2
  14. package/dist/chains/query_constructor/prompt.d.ts +1 -1
  15. package/dist/chains/query_constructor/prompt.js +1 -1
  16. package/dist/document_loaders/web/firecrawl.cjs +88 -0
  17. package/dist/document_loaders/web/firecrawl.d.ts +48 -0
  18. package/dist/document_loaders/web/firecrawl.js +81 -0
  19. package/dist/load/import_constants.cjs +1 -0
  20. package/dist/load/import_constants.js +1 -0
  21. package/dist/output_parsers/expression.cjs +1 -1
  22. package/dist/output_parsers/expression.d.ts +1 -1
  23. package/dist/output_parsers/expression.js +1 -1
  24. package/dist/retrievers/multi_query.cjs +24 -3
  25. package/dist/retrievers/multi_query.d.ts +6 -0
  26. package/dist/retrievers/multi_query.js +24 -3
  27. package/dist/retrievers/parent_document.cjs +20 -1
  28. package/dist/retrievers/parent_document.d.ts +6 -0
  29. package/dist/retrievers/parent_document.js +20 -1
  30. package/dist/retrievers/self_query/base.cjs +3 -136
  31. package/dist/retrievers/self_query/base.d.ts +1 -69
  32. package/dist/retrievers/self_query/base.js +1 -134
  33. package/dist/retrievers/self_query/chroma.cjs +9 -10
  34. package/dist/retrievers/self_query/chroma.d.ts +1 -1
  35. package/dist/retrievers/self_query/chroma.js +1 -2
  36. package/dist/retrievers/self_query/functional.cjs +2 -195
  37. package/dist/retrievers/self_query/functional.d.ts +1 -87
  38. package/dist/retrievers/self_query/functional.js +1 -194
  39. package/dist/retrievers/self_query/index.cjs +9 -13
  40. package/dist/retrievers/self_query/index.d.ts +11 -8
  41. package/dist/retrievers/self_query/index.js +7 -11
  42. package/dist/retrievers/self_query/pinecone.cjs +9 -10
  43. package/dist/retrievers/self_query/pinecone.d.ts +1 -1
  44. package/dist/retrievers/self_query/pinecone.js +1 -2
  45. package/dist/retrievers/self_query/supabase.cjs +28 -30
  46. package/dist/retrievers/self_query/supabase.d.ts +1 -2
  47. package/dist/retrievers/self_query/supabase.js +1 -3
  48. package/dist/retrievers/self_query/supabase_utils.cjs +2 -2
  49. package/dist/retrievers/self_query/supabase_utils.d.ts +1 -1
  50. package/dist/retrievers/self_query/supabase_utils.js +1 -1
  51. package/dist/retrievers/self_query/vectara.cjs +15 -17
  52. package/dist/retrievers/self_query/vectara.d.ts +1 -2
  53. package/dist/retrievers/self_query/vectara.js +1 -3
  54. package/dist/retrievers/self_query/weaviate.cjs +19 -21
  55. package/dist/retrievers/self_query/weaviate.d.ts +1 -2
  56. package/dist/retrievers/self_query/weaviate.js +1 -3
  57. package/dist/smith/runner_utils.cjs +18 -10
  58. package/dist/smith/runner_utils.js +18 -10
  59. package/dist/storage/in_memory.cjs +2 -81
  60. package/dist/storage/in_memory.d.ts +1 -49
  61. package/dist/storage/in_memory.js +1 -80
  62. package/dist/text_splitter.cjs +15 -727
  63. package/dist/text_splitter.d.ts +1 -77
  64. package/dist/text_splitter.js +1 -720
  65. package/document_loaders/web/firecrawl.cjs +1 -0
  66. package/document_loaders/web/firecrawl.d.cts +1 -0
  67. package/document_loaders/web/firecrawl.d.ts +1 -0
  68. package/document_loaders/web/firecrawl.js +1 -0
  69. package/package.json +22 -3
  70. package/dist/retrievers/self_query/utils.cjs +0 -94
  71. package/dist/retrievers/self_query/utils.d.ts +0 -29
  72. package/dist/retrievers/self_query/utils.js +0 -85
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VectaraTranslator = void 0;
4
- const ir_js_1 = require("../../chains/query_constructor/ir.cjs");
5
- const base_js_1 = require("./base.cjs");
6
- const utils_js_1 = require("./utils.cjs");
4
+ const structured_query_1 = require("@langchain/core/structured_query");
7
5
  function processValue(value) {
8
6
  /** Convert a value to a string and add single quotes if it is a string. */
9
7
  if (typeof value === "string") {
@@ -13,37 +11,37 @@ function processValue(value) {
13
11
  return String(value);
14
12
  }
15
13
  }
16
- class VectaraTranslator extends base_js_1.BaseTranslator {
14
+ class VectaraTranslator extends structured_query_1.BaseTranslator {
17
15
  constructor() {
18
16
  super(...arguments);
19
17
  Object.defineProperty(this, "allowedOperators", {
20
18
  enumerable: true,
21
19
  configurable: true,
22
20
  writable: true,
23
- value: [ir_js_1.Operators.and, ir_js_1.Operators.or]
21
+ value: [structured_query_1.Operators.and, structured_query_1.Operators.or]
24
22
  });
25
23
  Object.defineProperty(this, "allowedComparators", {
26
24
  enumerable: true,
27
25
  configurable: true,
28
26
  writable: true,
29
27
  value: [
30
- ir_js_1.Comparators.eq,
31
- ir_js_1.Comparators.ne,
32
- ir_js_1.Comparators.lt,
33
- ir_js_1.Comparators.lte,
34
- ir_js_1.Comparators.gt,
35
- ir_js_1.Comparators.gte,
28
+ structured_query_1.Comparators.eq,
29
+ structured_query_1.Comparators.ne,
30
+ structured_query_1.Comparators.lt,
31
+ structured_query_1.Comparators.lte,
32
+ structured_query_1.Comparators.gt,
33
+ structured_query_1.Comparators.gte,
36
34
  ]
37
35
  });
38
36
  }
39
37
  formatFunction(func) {
40
- if (func in ir_js_1.Comparators) {
38
+ if (func in structured_query_1.Comparators) {
41
39
  if (this.allowedComparators.length > 0 &&
42
40
  this.allowedComparators.indexOf(func) === -1) {
43
41
  throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
44
42
  }
45
43
  }
46
- else if (func in ir_js_1.Operators) {
44
+ else if (func in structured_query_1.Operators) {
47
45
  if (this.allowedOperators.length > 0 &&
48
46
  this.allowedOperators.indexOf(func) === -1) {
49
47
  throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
@@ -102,16 +100,16 @@ class VectaraTranslator extends base_js_1.BaseTranslator {
102
100
  return nextArg;
103
101
  }
104
102
  mergeFilters(defaultFilter, generatedFilter, mergeType = "and", forceDefaultFilter = false) {
105
- if ((0, utils_js_1.isFilterEmpty)(defaultFilter) && (0, utils_js_1.isFilterEmpty)(generatedFilter)) {
103
+ if ((0, structured_query_1.isFilterEmpty)(defaultFilter) && (0, structured_query_1.isFilterEmpty)(generatedFilter)) {
106
104
  return undefined;
107
105
  }
108
- if ((0, utils_js_1.isFilterEmpty)(defaultFilter) || mergeType === "replace") {
109
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
106
+ if ((0, structured_query_1.isFilterEmpty)(defaultFilter) || mergeType === "replace") {
107
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
110
108
  return undefined;
111
109
  }
112
110
  return generatedFilter;
113
111
  }
114
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
112
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
115
113
  if (forceDefaultFilter) {
116
114
  return defaultFilter;
117
115
  }
@@ -1,6 +1,5 @@
1
1
  import { VectaraFilter, VectaraStore } from "@langchain/community/vectorstores/vectara";
2
- import { Comparator, Comparison, Operation, Operator, StructuredQuery } from "../../chains/query_constructor/ir.js";
3
- import { BaseTranslator } from "./base.js";
2
+ import { BaseTranslator, Comparator, Comparison, Operation, Operator, StructuredQuery } from "@langchain/core/structured_query";
4
3
  export type VectaraVisitorResult = VectaraOperationResult | VectaraComparisonResult | VectaraVisitorStructuredQueryResult;
5
4
  export type VectaraOperationResult = String;
6
5
  export type VectaraComparisonResult = String;
@@ -1,6 +1,4 @@
1
- import { Comparators, Operators, } from "../../chains/query_constructor/ir.js";
2
- import { BaseTranslator } from "./base.js";
3
- import { isFilterEmpty } from "./utils.js";
1
+ import { BaseTranslator, isFilterEmpty, Comparators, Operators, } from "@langchain/core/structured_query";
4
2
  function processValue(value) {
5
3
  /** Convert a value to a string and add single quotes if it is a string. */
6
4
  if (typeof value === "string") {
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WeaviateTranslator = void 0;
4
- const ir_js_1 = require("../../chains/query_constructor/ir.cjs");
5
- const base_js_1 = require("./base.cjs");
6
- const utils_js_1 = require("./utils.cjs");
4
+ const structured_query_1 = require("@langchain/core/structured_query");
7
5
  /**
8
6
  * A class that translates or converts data into a format that can be used
9
7
  * with Weaviate, a vector search engine. It extends the `BaseTranslator`
@@ -23,26 +21,26 @@ const utils_js_1 = require("./utils.cjs");
23
21
  * );
24
22
  * ```
25
23
  */
26
- class WeaviateTranslator extends base_js_1.BaseTranslator {
24
+ class WeaviateTranslator extends structured_query_1.BaseTranslator {
27
25
  constructor() {
28
26
  super(...arguments);
29
27
  Object.defineProperty(this, "allowedOperators", {
30
28
  enumerable: true,
31
29
  configurable: true,
32
30
  writable: true,
33
- value: [ir_js_1.Operators.and, ir_js_1.Operators.or]
31
+ value: [structured_query_1.Operators.and, structured_query_1.Operators.or]
34
32
  });
35
33
  Object.defineProperty(this, "allowedComparators", {
36
34
  enumerable: true,
37
35
  configurable: true,
38
36
  writable: true,
39
37
  value: [
40
- ir_js_1.Comparators.eq,
41
- ir_js_1.Comparators.ne,
42
- ir_js_1.Comparators.lt,
43
- ir_js_1.Comparators.lte,
44
- ir_js_1.Comparators.gt,
45
- ir_js_1.Comparators.gte,
38
+ structured_query_1.Comparators.eq,
39
+ structured_query_1.Comparators.ne,
40
+ structured_query_1.Comparators.lt,
41
+ structured_query_1.Comparators.lte,
42
+ structured_query_1.Comparators.gt,
43
+ structured_query_1.Comparators.gte,
46
44
  ]
47
45
  });
48
46
  }
@@ -54,13 +52,13 @@ class WeaviateTranslator extends base_js_1.BaseTranslator {
54
52
  * @returns A string representation of the function.
55
53
  */
56
54
  formatFunction(func) {
57
- if (func in ir_js_1.Comparators) {
55
+ if (func in structured_query_1.Comparators) {
58
56
  if (this.allowedComparators.length > 0 &&
59
57
  this.allowedComparators.indexOf(func) === -1) {
60
58
  throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
61
59
  }
62
60
  }
63
- else if (func in ir_js_1.Operators) {
61
+ else if (func in structured_query_1.Operators) {
64
62
  if (this.allowedOperators.length > 0 &&
65
63
  this.allowedOperators.indexOf(func) === -1) {
66
64
  throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
@@ -102,21 +100,21 @@ class WeaviateTranslator extends base_js_1.BaseTranslator {
102
100
  * @returns A WeaviateComparisonResult.
103
101
  */
104
102
  visitComparison(comparison) {
105
- if ((0, utils_js_1.isString)(comparison.value)) {
103
+ if ((0, structured_query_1.isString)(comparison.value)) {
106
104
  return {
107
105
  path: [comparison.attribute],
108
106
  operator: this.formatFunction(comparison.comparator),
109
107
  valueText: comparison.value,
110
108
  };
111
109
  }
112
- if ((0, utils_js_1.isInt)(comparison.value)) {
110
+ if ((0, structured_query_1.isInt)(comparison.value)) {
113
111
  return {
114
112
  path: [comparison.attribute],
115
113
  operator: this.formatFunction(comparison.comparator),
116
114
  valueInt: parseInt(comparison.value, 10),
117
115
  };
118
116
  }
119
- if ((0, utils_js_1.isFloat)(comparison.value)) {
117
+ if ((0, structured_query_1.isFloat)(comparison.value)) {
120
118
  return {
121
119
  path: [comparison.attribute],
122
120
  operator: this.formatFunction(comparison.comparator),
@@ -152,17 +150,17 @@ class WeaviateTranslator extends base_js_1.BaseTranslator {
152
150
  * @returns A merged WeaviateFilter, or undefined if both filters are empty.
153
151
  */
154
152
  mergeFilters(defaultFilter, generatedFilter, mergeType = "and") {
155
- if ((0, utils_js_1.isFilterEmpty)(defaultFilter?.where) &&
156
- (0, utils_js_1.isFilterEmpty)(generatedFilter?.where)) {
153
+ if ((0, structured_query_1.isFilterEmpty)(defaultFilter?.where) &&
154
+ (0, structured_query_1.isFilterEmpty)(generatedFilter?.where)) {
157
155
  return undefined;
158
156
  }
159
- if ((0, utils_js_1.isFilterEmpty)(defaultFilter?.where) || mergeType === "replace") {
160
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter?.where)) {
157
+ if ((0, structured_query_1.isFilterEmpty)(defaultFilter?.where) || mergeType === "replace") {
158
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter?.where)) {
161
159
  return undefined;
162
160
  }
163
161
  return generatedFilter;
164
162
  }
165
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter?.where)) {
163
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter?.where)) {
166
164
  if (mergeType === "and") {
167
165
  return undefined;
168
166
  }
@@ -1,6 +1,5 @@
1
1
  import { WeaviateFilter, WeaviateStore } from "@langchain/community/vectorstores/weaviate";
2
- import { Comparator, Comparison, Operation, Operator, StructuredQuery } from "../../chains/query_constructor/ir.js";
3
- import { BaseTranslator } from "./base.js";
2
+ import { BaseTranslator, Comparator, Comparison, Operation, Operator, StructuredQuery } from "@langchain/core/structured_query";
4
3
  type WeaviateOperatorValues = {
5
4
  valueText: string;
6
5
  valueInt: number;
@@ -1,6 +1,4 @@
1
- import { Comparators, Operators, } from "../../chains/query_constructor/ir.js";
2
- import { BaseTranslator } from "./base.js";
3
- import { isFilterEmpty, isString, isInt, isFloat } from "./utils.js";
1
+ import { isFilterEmpty, isString, isInt, isFloat, BaseTranslator, Comparators, Operators, } from "@langchain/core/structured_query";
4
2
  /**
5
3
  * A class that translates or converts data into a format that can be used
6
4
  * with Weaviate, a vector search engine. It extends the `BaseTranslator`
@@ -5,6 +5,7 @@ const messages_1 = require("@langchain/core/messages");
5
5
  const runnables_1 = require("@langchain/core/runnables");
6
6
  const tracer_langchain_1 = require("@langchain/core/tracers/tracer_langchain");
7
7
  const base_1 = require("@langchain/core/tracers/base");
8
+ const async_caller_1 = require("@langchain/core/utils/async_caller");
8
9
  const langsmith_1 = require("langsmith");
9
10
  const loader_js_1 = require("../evaluation/loader.cjs");
10
11
  const config_js_1 = require("./config.cjs");
@@ -403,31 +404,37 @@ const loadExamples = async ({ datasetName, client, projectName, }) => {
403
404
  runExtractors,
404
405
  };
405
406
  };
406
- const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
407
+ const applyEvaluators = async ({ evaluation, runs, examples, client, maxConcurrency, }) => {
407
408
  // TODO: Parallelize and/or put in callbacks to speed up evals.
408
409
  const { evaluators } = evaluation;
409
410
  const progress = new progress_js_1.ProgressBar({
410
411
  total: examples.length,
411
412
  format: "Running Evaluators: {bar} {percentage}% | {value}/{total}\n",
412
413
  });
413
- const results = {};
414
- for (let i = 0; i < runs.length; i += 1) {
415
- const run = runs[i];
416
- const example = examples[i];
414
+ const caller = new async_caller_1.AsyncCaller({
415
+ maxConcurrency,
416
+ });
417
+ const requests = runs.map(async (run, i) => caller.call(async () => {
417
418
  const evaluatorResults = await Promise.allSettled(evaluators.map((evaluator) => client.evaluateRun(run, evaluator, {
418
- referenceExample: example,
419
+ referenceExample: examples[i],
419
420
  loadChildRuns: false,
420
421
  })));
421
422
  progress.increment();
422
- results[example.id] = {
423
+ return {
423
424
  execution_time: run?.end_time && run.start_time
424
425
  ? run.end_time - run.start_time
425
426
  : undefined,
426
- feedback: evaluatorResults.map((evalResult) => evalResult.status === "fulfilled" ? evalResult.value : evalResult.reason),
427
+ feedback: evaluatorResults.map((evalResult) => evalResult.status === "fulfilled"
428
+ ? evalResult.value
429
+ : evalResult.reason),
427
430
  run_id: run.id,
428
431
  };
429
- }
430
- return results;
432
+ }));
433
+ const results = await Promise.all(requests);
434
+ return results.reduce((acc, result, i) => ({
435
+ ...acc,
436
+ [examples[i].id]: result,
437
+ }), {});
431
438
  };
432
439
  const getExamplesInputs = (examples, chainOrFactory, dataType) => {
433
440
  if (dataType === "chat") {
@@ -553,6 +560,7 @@ async function runOnDataset(chainOrFactory, datasetName, options) {
553
560
  runs,
554
561
  examples,
555
562
  client: testClient,
563
+ maxConcurrency: testConcurrency,
556
564
  });
557
565
  }
558
566
  const results = {
@@ -2,6 +2,7 @@ import { mapStoredMessagesToChatMessages } from "@langchain/core/messages";
2
2
  import { Runnable, RunnableLambda, getCallbackManagerForConfig, } from "@langchain/core/runnables";
3
3
  import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
4
4
  import { BaseTracer } from "@langchain/core/tracers/base";
5
+ import { AsyncCaller } from "@langchain/core/utils/async_caller";
5
6
  import { Client, RunTree, } from "langsmith";
6
7
  import { loadEvaluator } from "../evaluation/loader.js";
7
8
  import { isOffTheShelfEvaluator, isCustomEvaluator, } from "./config.js";
@@ -400,31 +401,37 @@ const loadExamples = async ({ datasetName, client, projectName, }) => {
400
401
  runExtractors,
401
402
  };
402
403
  };
403
- const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
404
+ const applyEvaluators = async ({ evaluation, runs, examples, client, maxConcurrency, }) => {
404
405
  // TODO: Parallelize and/or put in callbacks to speed up evals.
405
406
  const { evaluators } = evaluation;
406
407
  const progress = new ProgressBar({
407
408
  total: examples.length,
408
409
  format: "Running Evaluators: {bar} {percentage}% | {value}/{total}\n",
409
410
  });
410
- const results = {};
411
- for (let i = 0; i < runs.length; i += 1) {
412
- const run = runs[i];
413
- const example = examples[i];
411
+ const caller = new AsyncCaller({
412
+ maxConcurrency,
413
+ });
414
+ const requests = runs.map(async (run, i) => caller.call(async () => {
414
415
  const evaluatorResults = await Promise.allSettled(evaluators.map((evaluator) => client.evaluateRun(run, evaluator, {
415
- referenceExample: example,
416
+ referenceExample: examples[i],
416
417
  loadChildRuns: false,
417
418
  })));
418
419
  progress.increment();
419
- results[example.id] = {
420
+ return {
420
421
  execution_time: run?.end_time && run.start_time
421
422
  ? run.end_time - run.start_time
422
423
  : undefined,
423
- feedback: evaluatorResults.map((evalResult) => evalResult.status === "fulfilled" ? evalResult.value : evalResult.reason),
424
+ feedback: evaluatorResults.map((evalResult) => evalResult.status === "fulfilled"
425
+ ? evalResult.value
426
+ : evalResult.reason),
424
427
  run_id: run.id,
425
428
  };
426
- }
427
- return results;
429
+ }));
430
+ const results = await Promise.all(requests);
431
+ return results.reduce((acc, result, i) => ({
432
+ ...acc,
433
+ [examples[i].id]: result,
434
+ }), {});
428
435
  };
429
436
  const getExamplesInputs = (examples, chainOrFactory, dataType) => {
430
437
  if (dataType === "chat") {
@@ -550,6 +557,7 @@ export async function runOnDataset(chainOrFactory, datasetName, options) {
550
557
  runs,
551
558
  examples,
552
559
  client: testClient,
560
+ maxConcurrency: testConcurrency,
553
561
  });
554
562
  }
555
563
  const results = {
@@ -1,84 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryStore = void 0;
4
- const stores_1 = require("@langchain/core/stores");
5
- /**
6
- * In-memory implementation of the BaseStore using a dictionary. Used for
7
- * storing key-value pairs in memory.
8
- * @example
9
- * ```typescript
10
- * const store = new InMemoryStore<BaseMessage>();
11
- * await store.mset(
12
- * Array.from({ length: 5 }).map((_, index) => [
13
- * `message:id:${index}`,
14
- * index % 2 === 0
15
- * ? new AIMessage("ai stuff...")
16
- * : new HumanMessage("human stuff..."),
17
- * ]),
18
- * );
19
- *
20
- * const retrievedMessages = await store.mget(["message:id:0", "message:id:1"]);
21
- * await store.mdelete(await store.yieldKeys("message:id:").toArray());
22
- * ```
23
- */
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- class InMemoryStore extends stores_1.BaseStore {
26
- constructor() {
27
- super(...arguments);
28
- Object.defineProperty(this, "lc_namespace", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: ["langchain", "storage"]
33
- });
34
- Object.defineProperty(this, "store", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: {}
39
- });
40
- }
41
- /**
42
- * Retrieves the values associated with the given keys from the store.
43
- * @param keys Keys to retrieve values for.
44
- * @returns Array of values associated with the given keys.
45
- */
46
- async mget(keys) {
47
- return keys.map((key) => this.store[key]);
48
- }
49
- /**
50
- * Sets the values for the given keys in the store.
51
- * @param keyValuePairs Array of key-value pairs to set in the store.
52
- * @returns Promise that resolves when all key-value pairs have been set.
53
- */
54
- async mset(keyValuePairs) {
55
- for (const [key, value] of keyValuePairs) {
56
- this.store[key] = value;
57
- }
58
- }
59
- /**
60
- * Deletes the given keys and their associated values from the store.
61
- * @param keys Keys to delete from the store.
62
- * @returns Promise that resolves when all keys have been deleted.
63
- */
64
- async mdelete(keys) {
65
- for (const key of keys) {
66
- delete this.store[key];
67
- }
68
- }
69
- /**
70
- * Asynchronous generator that yields keys from the store. If a prefix is
71
- * provided, it only yields keys that start with the prefix.
72
- * @param prefix Optional prefix to filter keys.
73
- * @returns AsyncGenerator that yields keys from the store.
74
- */
75
- async *yieldKeys(prefix) {
76
- const keys = Object.keys(this.store);
77
- for (const key of keys) {
78
- if (prefix === undefined || key.startsWith(prefix)) {
79
- yield key;
80
- }
81
- }
82
- }
83
- }
84
- exports.InMemoryStore = InMemoryStore;
4
+ var stores_1 = require("@langchain/core/stores");
5
+ Object.defineProperty(exports, "InMemoryStore", { enumerable: true, get: function () { return stores_1.InMemoryStore; } });
@@ -1,49 +1 @@
1
- import { BaseStore } from "@langchain/core/stores";
2
- /**
3
- * In-memory implementation of the BaseStore using a dictionary. Used for
4
- * storing key-value pairs in memory.
5
- * @example
6
- * ```typescript
7
- * const store = new InMemoryStore<BaseMessage>();
8
- * await store.mset(
9
- * Array.from({ length: 5 }).map((_, index) => [
10
- * `message:id:${index}`,
11
- * index % 2 === 0
12
- * ? new AIMessage("ai stuff...")
13
- * : new HumanMessage("human stuff..."),
14
- * ]),
15
- * );
16
- *
17
- * const retrievedMessages = await store.mget(["message:id:0", "message:id:1"]);
18
- * await store.mdelete(await store.yieldKeys("message:id:").toArray());
19
- * ```
20
- */
21
- export declare class InMemoryStore<T = any> extends BaseStore<string, T> {
22
- lc_namespace: string[];
23
- protected store: Record<string, T>;
24
- /**
25
- * Retrieves the values associated with the given keys from the store.
26
- * @param keys Keys to retrieve values for.
27
- * @returns Array of values associated with the given keys.
28
- */
29
- mget(keys: string[]): Promise<T[]>;
30
- /**
31
- * Sets the values for the given keys in the store.
32
- * @param keyValuePairs Array of key-value pairs to set in the store.
33
- * @returns Promise that resolves when all key-value pairs have been set.
34
- */
35
- mset(keyValuePairs: [string, T][]): Promise<void>;
36
- /**
37
- * Deletes the given keys and their associated values from the store.
38
- * @param keys Keys to delete from the store.
39
- * @returns Promise that resolves when all keys have been deleted.
40
- */
41
- mdelete(keys: string[]): Promise<void>;
42
- /**
43
- * Asynchronous generator that yields keys from the store. If a prefix is
44
- * provided, it only yields keys that start with the prefix.
45
- * @param prefix Optional prefix to filter keys.
46
- * @returns AsyncGenerator that yields keys from the store.
47
- */
48
- yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;
49
- }
1
+ export { InMemoryStore } from "@langchain/core/stores";
@@ -1,80 +1 @@
1
- import { BaseStore } from "@langchain/core/stores";
2
- /**
3
- * In-memory implementation of the BaseStore using a dictionary. Used for
4
- * storing key-value pairs in memory.
5
- * @example
6
- * ```typescript
7
- * const store = new InMemoryStore<BaseMessage>();
8
- * await store.mset(
9
- * Array.from({ length: 5 }).map((_, index) => [
10
- * `message:id:${index}`,
11
- * index % 2 === 0
12
- * ? new AIMessage("ai stuff...")
13
- * : new HumanMessage("human stuff..."),
14
- * ]),
15
- * );
16
- *
17
- * const retrievedMessages = await store.mget(["message:id:0", "message:id:1"]);
18
- * await store.mdelete(await store.yieldKeys("message:id:").toArray());
19
- * ```
20
- */
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- export class InMemoryStore extends BaseStore {
23
- constructor() {
24
- super(...arguments);
25
- Object.defineProperty(this, "lc_namespace", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: ["langchain", "storage"]
30
- });
31
- Object.defineProperty(this, "store", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: {}
36
- });
37
- }
38
- /**
39
- * Retrieves the values associated with the given keys from the store.
40
- * @param keys Keys to retrieve values for.
41
- * @returns Array of values associated with the given keys.
42
- */
43
- async mget(keys) {
44
- return keys.map((key) => this.store[key]);
45
- }
46
- /**
47
- * Sets the values for the given keys in the store.
48
- * @param keyValuePairs Array of key-value pairs to set in the store.
49
- * @returns Promise that resolves when all key-value pairs have been set.
50
- */
51
- async mset(keyValuePairs) {
52
- for (const [key, value] of keyValuePairs) {
53
- this.store[key] = value;
54
- }
55
- }
56
- /**
57
- * Deletes the given keys and their associated values from the store.
58
- * @param keys Keys to delete from the store.
59
- * @returns Promise that resolves when all keys have been deleted.
60
- */
61
- async mdelete(keys) {
62
- for (const key of keys) {
63
- delete this.store[key];
64
- }
65
- }
66
- /**
67
- * Asynchronous generator that yields keys from the store. If a prefix is
68
- * provided, it only yields keys that start with the prefix.
69
- * @param prefix Optional prefix to filter keys.
70
- * @returns AsyncGenerator that yields keys from the store.
71
- */
72
- async *yieldKeys(prefix) {
73
- const keys = Object.keys(this.store);
74
- for (const key of keys) {
75
- if (prefix === undefined || key.startsWith(prefix)) {
76
- yield key;
77
- }
78
- }
79
- }
80
- }
1
+ export { InMemoryStore } from "@langchain/core/stores";