langchain 0.1.35 → 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 (61) hide show
  1. package/dist/chains/openai_functions/base.cjs +2 -0
  2. package/dist/chains/openai_functions/base.d.ts +2 -0
  3. package/dist/chains/openai_functions/base.js +2 -0
  4. package/dist/chains/query_constructor/index.cjs +5 -8
  5. package/dist/chains/query_constructor/index.d.ts +5 -4
  6. package/dist/chains/query_constructor/index.js +3 -6
  7. package/dist/chains/query_constructor/ir.cjs +15 -139
  8. package/dist/chains/query_constructor/ir.d.ts +1 -138
  9. package/dist/chains/query_constructor/ir.js +1 -132
  10. package/dist/chains/query_constructor/prompt.cjs +2 -2
  11. package/dist/chains/query_constructor/prompt.d.ts +1 -1
  12. package/dist/chains/query_constructor/prompt.js +1 -1
  13. package/dist/document_loaders/web/firecrawl.cjs +88 -0
  14. package/dist/document_loaders/web/firecrawl.d.ts +48 -0
  15. package/dist/document_loaders/web/firecrawl.js +81 -0
  16. package/dist/load/import_constants.cjs +1 -0
  17. package/dist/load/import_constants.js +1 -0
  18. package/dist/output_parsers/expression.cjs +1 -1
  19. package/dist/output_parsers/expression.d.ts +1 -1
  20. package/dist/output_parsers/expression.js +1 -1
  21. package/dist/retrievers/self_query/base.cjs +3 -136
  22. package/dist/retrievers/self_query/base.d.ts +1 -69
  23. package/dist/retrievers/self_query/base.js +1 -134
  24. package/dist/retrievers/self_query/chroma.cjs +9 -10
  25. package/dist/retrievers/self_query/chroma.d.ts +1 -1
  26. package/dist/retrievers/self_query/chroma.js +1 -2
  27. package/dist/retrievers/self_query/functional.cjs +2 -195
  28. package/dist/retrievers/self_query/functional.d.ts +1 -87
  29. package/dist/retrievers/self_query/functional.js +1 -194
  30. package/dist/retrievers/self_query/index.cjs +9 -13
  31. package/dist/retrievers/self_query/index.d.ts +11 -8
  32. package/dist/retrievers/self_query/index.js +7 -11
  33. package/dist/retrievers/self_query/pinecone.cjs +9 -10
  34. package/dist/retrievers/self_query/pinecone.d.ts +1 -1
  35. package/dist/retrievers/self_query/pinecone.js +1 -2
  36. package/dist/retrievers/self_query/supabase.cjs +28 -30
  37. package/dist/retrievers/self_query/supabase.d.ts +1 -2
  38. package/dist/retrievers/self_query/supabase.js +1 -3
  39. package/dist/retrievers/self_query/supabase_utils.cjs +2 -2
  40. package/dist/retrievers/self_query/supabase_utils.d.ts +1 -1
  41. package/dist/retrievers/self_query/supabase_utils.js +1 -1
  42. package/dist/retrievers/self_query/vectara.cjs +15 -17
  43. package/dist/retrievers/self_query/vectara.d.ts +1 -2
  44. package/dist/retrievers/self_query/vectara.js +1 -3
  45. package/dist/retrievers/self_query/weaviate.cjs +19 -21
  46. package/dist/retrievers/self_query/weaviate.d.ts +1 -2
  47. package/dist/retrievers/self_query/weaviate.js +1 -3
  48. package/dist/storage/in_memory.cjs +2 -81
  49. package/dist/storage/in_memory.d.ts +1 -49
  50. package/dist/storage/in_memory.js +1 -80
  51. package/dist/text_splitter.cjs +15 -727
  52. package/dist/text_splitter.d.ts +1 -77
  53. package/dist/text_splitter.js +1 -720
  54. package/document_loaders/web/firecrawl.cjs +1 -0
  55. package/document_loaders/web/firecrawl.d.cts +1 -0
  56. package/document_loaders/web/firecrawl.d.ts +1 -0
  57. package/document_loaders/web/firecrawl.js +1 -0
  58. package/package.json +22 -3
  59. package/dist/retrievers/self_query/utils.cjs +0 -94
  60. package/dist/retrievers/self_query/utils.d.ts +0 -29
  61. package/dist/retrievers/self_query/utils.js +0 -85
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PineconeTranslator = void 0;
4
- const ir_js_1 = require("../../chains/query_constructor/ir.cjs");
5
- const base_js_1 = require("./base.cjs");
4
+ const structured_query_1 = require("@langchain/core/structured_query");
6
5
  /**
7
6
  * Specialized translator class that extends the BasicTranslator. It is
8
7
  * designed to work with PineconeStore, a type of vector store in
@@ -24,17 +23,17 @@ const base_js_1 = require("./base.cjs");
24
23
  * );
25
24
  * ```
26
25
  */
27
- class PineconeTranslator extends base_js_1.BasicTranslator {
26
+ class PineconeTranslator extends structured_query_1.BasicTranslator {
28
27
  constructor() {
29
28
  super({
30
- allowedOperators: [ir_js_1.Operators.and, ir_js_1.Operators.or],
29
+ allowedOperators: [structured_query_1.Operators.and, structured_query_1.Operators.or],
31
30
  allowedComparators: [
32
- ir_js_1.Comparators.eq,
33
- ir_js_1.Comparators.ne,
34
- ir_js_1.Comparators.gt,
35
- ir_js_1.Comparators.gte,
36
- ir_js_1.Comparators.lt,
37
- ir_js_1.Comparators.lte,
31
+ structured_query_1.Comparators.eq,
32
+ structured_query_1.Comparators.ne,
33
+ structured_query_1.Comparators.gt,
34
+ structured_query_1.Comparators.gte,
35
+ structured_query_1.Comparators.lt,
36
+ structured_query_1.Comparators.lte,
38
37
  ],
39
38
  });
40
39
  }
@@ -1,5 +1,5 @@
1
1
  import type { VectorStoreInterface } from "@langchain/core/vectorstores";
2
- import { BasicTranslator } from "./base.js";
2
+ import { BasicTranslator } from "@langchain/core/structured_query";
3
3
  /**
4
4
  * Specialized translator class that extends the BasicTranslator. It is
5
5
  * designed to work with PineconeStore, a type of vector store in
@@ -1,5 +1,4 @@
1
- import { Comparators, Operators } from "../../chains/query_constructor/ir.js";
2
- import { BasicTranslator } from "./base.js";
1
+ import { BasicTranslator, Comparators, Operators, } from "@langchain/core/structured_query";
3
2
  /**
4
3
  * Specialized translator class that extends the BasicTranslator. It is
5
4
  * designed to work with PineconeStore, a type of vector store in
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SupabaseTranslator = 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
  const supabase_utils_js_1 = require("./supabase_utils.cjs");
8
6
  /**
9
7
  * A specialized translator designed to work with Supabase, extending the
@@ -24,26 +22,26 @@ const supabase_utils_js_1 = require("./supabase_utils.cjs");
24
22
  * );
25
23
  * ```
26
24
  */
27
- class SupabaseTranslator extends base_js_1.BaseTranslator {
25
+ class SupabaseTranslator extends structured_query_1.BaseTranslator {
28
26
  constructor() {
29
27
  super(...arguments);
30
28
  Object.defineProperty(this, "allowedOperators", {
31
29
  enumerable: true,
32
30
  configurable: true,
33
31
  writable: true,
34
- value: [ir_js_1.Operators.and, ir_js_1.Operators.or]
32
+ value: [structured_query_1.Operators.and, structured_query_1.Operators.or]
35
33
  });
36
34
  Object.defineProperty(this, "allowedComparators", {
37
35
  enumerable: true,
38
36
  configurable: true,
39
37
  writable: true,
40
38
  value: [
41
- ir_js_1.Comparators.eq,
42
- ir_js_1.Comparators.ne,
43
- ir_js_1.Comparators.gt,
44
- ir_js_1.Comparators.gte,
45
- ir_js_1.Comparators.lt,
46
- ir_js_1.Comparators.lte,
39
+ structured_query_1.Comparators.eq,
40
+ structured_query_1.Comparators.ne,
41
+ structured_query_1.Comparators.gt,
42
+ structured_query_1.Comparators.gte,
43
+ structured_query_1.Comparators.lt,
44
+ structured_query_1.Comparators.lte,
47
45
  ]
48
46
  });
49
47
  }
@@ -59,22 +57,22 @@ class SupabaseTranslator extends base_js_1.BaseTranslator {
59
57
  */
60
58
  getComparatorFunction(comparator) {
61
59
  switch (comparator) {
62
- case ir_js_1.Comparators.eq: {
60
+ case structured_query_1.Comparators.eq: {
63
61
  return (attr, value) => (rpc) => rpc.eq(this.buildColumnName(attr, value), value);
64
62
  }
65
- case ir_js_1.Comparators.ne: {
63
+ case structured_query_1.Comparators.ne: {
66
64
  return (attr, value) => (rpc) => rpc.neq(this.buildColumnName(attr, value), value);
67
65
  }
68
- case ir_js_1.Comparators.gt: {
66
+ case structured_query_1.Comparators.gt: {
69
67
  return (attr, value) => (rpc) => rpc.gt(this.buildColumnName(attr, value), value);
70
68
  }
71
- case ir_js_1.Comparators.gte: {
69
+ case structured_query_1.Comparators.gte: {
72
70
  return (attr, value) => (rpc) => rpc.gte(this.buildColumnName(attr, value), value);
73
71
  }
74
- case ir_js_1.Comparators.lt: {
72
+ case structured_query_1.Comparators.lt: {
75
73
  return (attr, value) => (rpc) => rpc.lt(this.buildColumnName(attr, value), value);
76
74
  }
77
- case ir_js_1.Comparators.lte: {
75
+ case structured_query_1.Comparators.lte: {
78
76
  return (attr, value) => (rpc) => rpc.lte(this.buildColumnName(attr, value), value);
79
77
  }
80
78
  default: {
@@ -92,13 +90,13 @@ class SupabaseTranslator extends base_js_1.BaseTranslator {
92
90
  */
93
91
  buildColumnName(attr, value, includeType = true) {
94
92
  let column = "";
95
- if ((0, utils_js_1.isString)(value)) {
93
+ if ((0, structured_query_1.isString)(value)) {
96
94
  column = `metadata->>${attr}`;
97
95
  }
98
- else if ((0, utils_js_1.isInt)(value)) {
96
+ else if ((0, structured_query_1.isInt)(value)) {
99
97
  column = `metadata->${attr}${includeType ? "::int" : ""}`;
100
98
  }
101
- else if ((0, utils_js_1.isFloat)(value)) {
99
+ else if ((0, structured_query_1.isFloat)(value)) {
102
100
  column = `metadata->${attr}${includeType ? "::float" : ""}`;
103
101
  }
104
102
  else {
@@ -141,7 +139,7 @@ class SupabaseTranslator extends base_js_1.BaseTranslator {
141
139
  visitOperation(operation) {
142
140
  const { operator, args } = operation;
143
141
  if (this.allowedOperators.includes(operator)) {
144
- if (operator === ir_js_1.Operators.and) {
142
+ if (operator === structured_query_1.Operators.and) {
145
143
  if (!args) {
146
144
  return (rpc) => rpc;
147
145
  }
@@ -151,7 +149,7 @@ class SupabaseTranslator extends base_js_1.BaseTranslator {
151
149
  }, rpc);
152
150
  return filter;
153
151
  }
154
- else if (operator === ir_js_1.Operators.or) {
152
+ else if (operator === structured_query_1.Operators.or) {
155
153
  return (rpc) => rpc.or(this.visitOperationAsString(operation));
156
154
  }
157
155
  else {
@@ -173,7 +171,7 @@ class SupabaseTranslator extends base_js_1.BaseTranslator {
173
171
  let { value } = comparison;
174
172
  const { comparator: _comparator, attribute } = comparison;
175
173
  let comparator = _comparator;
176
- if (comparator === ir_js_1.Comparators.ne) {
174
+ if (comparator === structured_query_1.Comparators.ne) {
177
175
  comparator = "neq";
178
176
  }
179
177
  if (Array.isArray(value)) {
@@ -227,27 +225,27 @@ class SupabaseTranslator extends base_js_1.BaseTranslator {
227
225
  * @returns The merged filter.
228
226
  */
229
227
  mergeFilters(defaultFilter, generatedFilter, mergeType = "and") {
230
- if ((0, utils_js_1.isFilterEmpty)(defaultFilter) && (0, utils_js_1.isFilterEmpty)(generatedFilter)) {
228
+ if ((0, structured_query_1.isFilterEmpty)(defaultFilter) && (0, structured_query_1.isFilterEmpty)(generatedFilter)) {
231
229
  return undefined;
232
230
  }
233
- if ((0, utils_js_1.isFilterEmpty)(defaultFilter) || mergeType === "replace") {
234
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
231
+ if ((0, structured_query_1.isFilterEmpty)(defaultFilter) || mergeType === "replace") {
232
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
235
233
  return undefined;
236
234
  }
237
235
  return generatedFilter;
238
236
  }
239
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
237
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
240
238
  if (mergeType === "and") {
241
239
  return undefined;
242
240
  }
243
241
  return defaultFilter;
244
242
  }
245
243
  let myDefaultFilter = defaultFilter;
246
- if ((0, utils_js_1.isObject)(defaultFilter)) {
244
+ if ((0, structured_query_1.isObject)(defaultFilter)) {
247
245
  const { filter } = this.visitStructuredQuery((0, supabase_utils_js_1.convertObjectFilterToStructuredQuery)(defaultFilter));
248
246
  // just in case the built filter is empty somehow
249
- if ((0, utils_js_1.isFilterEmpty)(filter)) {
250
- if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
247
+ if ((0, structured_query_1.isFilterEmpty)(filter)) {
248
+ if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
251
249
  return undefined;
252
250
  }
253
251
  return generatedFilter;
@@ -1,6 +1,5 @@
1
1
  import type { SupabaseFilterRPCCall, SupabaseMetadata, SupabaseVectorStore } from "@langchain/community/vectorstores/supabase";
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
  /**
5
4
  * Represents the possible values that can be used in a comparison in a
6
5
  * structured query. It can be a string or a number.
@@ -1,6 +1,4 @@
1
- import { Comparators, Operators, } from "../../chains/query_constructor/ir.js";
2
- import { BaseTranslator } from "./base.js";
3
- import { isFilterEmpty, isFloat, isInt, isObject, isString } from "./utils.js";
1
+ import { isFilterEmpty, isFloat, isInt, isObject, isString, BaseTranslator, Comparators, Operators, } from "@langchain/core/structured_query";
4
2
  import { ProxyParamsDuplicator, convertObjectFilterToStructuredQuery, } from "./supabase_utils.js";
5
3
  /**
6
4
  * A specialized translator designed to work with Supabase, extending the
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertObjectFilterToStructuredQuery = exports.ProxyParamsDuplicator = void 0;
4
- const ir_js_1 = require("../../chains/query_constructor/ir.cjs");
4
+ const structured_query_1 = require("@langchain/core/structured_query");
5
5
  /**
6
6
  * Utility class used to duplicate parameters for a proxy object,
7
7
  * specifically designed to work with `SupabaseFilter` objects. It
@@ -250,6 +250,6 @@ exports.ProxyParamsDuplicator = ProxyParamsDuplicator;
250
250
  * `Operation` and `Comparison` classes to build the query.
251
251
  */
252
252
  function convertObjectFilterToStructuredQuery(objFilter) {
253
- return new ir_js_1.StructuredQuery("", new ir_js_1.Operation(ir_js_1.Operators.and, Object.entries(objFilter).map(([column, value]) => new ir_js_1.Comparison(ir_js_1.Comparators.eq, column, value))));
253
+ return new structured_query_1.StructuredQuery("", new structured_query_1.Operation(structured_query_1.Operators.and, Object.entries(objFilter).map(([column, value]) => new structured_query_1.Comparison(structured_query_1.Comparators.eq, column, value))));
254
254
  }
255
255
  exports.convertObjectFilterToStructuredQuery = convertObjectFilterToStructuredQuery;
@@ -1,5 +1,5 @@
1
1
  import type { SupabaseFilter, SupabaseFilterRPCCall, SupabaseMetadata } from "@langchain/community/vectorstores/supabase";
2
- import { StructuredQuery } from "../../chains/query_constructor/ir.js";
2
+ import { StructuredQuery } from "@langchain/core/structured_query";
3
3
  /**
4
4
  * Utility class used to duplicate parameters for a proxy object,
5
5
  * specifically designed to work with `SupabaseFilter` objects. It
@@ -1,4 +1,4 @@
1
- import { Comparators, Comparison, Operation, Operators, StructuredQuery, } from "../../chains/query_constructor/ir.js";
1
+ import { Comparators, Comparison, Operation, Operators, StructuredQuery, } from "@langchain/core/structured_query";
2
2
  /**
3
3
  * Utility class used to duplicate parameters for a proxy object,
4
4
  * specifically designed to work with `SupabaseFilter` objects. It
@@ -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`
@@ -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";