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,194 +1 @@
1
- import { Comparators, Operators, } from "../../chains/query_constructor/ir.js";
2
- import { BaseTranslator } from "./base.js";
3
- import { castValue, isFilterEmpty } from "./utils.js";
4
- /**
5
- * A class that extends `BaseTranslator` to translate structured queries
6
- * into functional filters.
7
- * @example
8
- * ```typescript
9
- * const functionalTranslator = new FunctionalTranslator();
10
- * const relevantDocuments = await functionalTranslator.getRelevantDocuments(
11
- * "Which movies are rated higher than 8.5?",
12
- * );
13
- * ```
14
- */
15
- export class FunctionalTranslator extends BaseTranslator {
16
- constructor() {
17
- super(...arguments);
18
- Object.defineProperty(this, "allowedOperators", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: [Operators.and, Operators.or]
23
- });
24
- Object.defineProperty(this, "allowedComparators", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: [
29
- Comparators.eq,
30
- Comparators.ne,
31
- Comparators.gt,
32
- Comparators.gte,
33
- Comparators.lt,
34
- Comparators.lte,
35
- ]
36
- });
37
- }
38
- formatFunction() {
39
- throw new Error("Not implemented");
40
- }
41
- /**
42
- * Returns a function that performs a comparison based on the provided
43
- * comparator.
44
- * @param comparator The comparator to base the comparison function on.
45
- * @returns A function that takes two arguments and returns a boolean based on the comparison.
46
- */
47
- getComparatorFunction(comparator) {
48
- switch (comparator) {
49
- case Comparators.eq: {
50
- return (a, b) => a === b;
51
- }
52
- case Comparators.ne: {
53
- return (a, b) => a !== b;
54
- }
55
- case Comparators.gt: {
56
- return (a, b) => a > b;
57
- }
58
- case Comparators.gte: {
59
- return (a, b) => a >= b;
60
- }
61
- case Comparators.lt: {
62
- return (a, b) => a < b;
63
- }
64
- case Comparators.lte: {
65
- return (a, b) => a <= b;
66
- }
67
- default: {
68
- throw new Error("Unknown comparator");
69
- }
70
- }
71
- }
72
- /**
73
- * Returns a function that performs an operation based on the provided
74
- * operator.
75
- * @param operator The operator to base the operation function on.
76
- * @returns A function that takes two boolean arguments and returns a boolean based on the operation.
77
- */
78
- getOperatorFunction(operator) {
79
- switch (operator) {
80
- case Operators.and: {
81
- return (a, b) => a && b;
82
- }
83
- case Operators.or: {
84
- return (a, b) => a || b;
85
- }
86
- default: {
87
- throw new Error("Unknown operator");
88
- }
89
- }
90
- }
91
- /**
92
- * Visits the operation part of a structured query and translates it into
93
- * a functional filter.
94
- * @param operation The operation part of a structured query.
95
- * @returns A function that takes a `Document` as an argument and returns a boolean based on the operation.
96
- */
97
- visitOperation(operation) {
98
- const { operator, args } = operation;
99
- if (this.allowedOperators.includes(operator)) {
100
- const operatorFunction = this.getOperatorFunction(operator);
101
- return (document) => {
102
- if (!args) {
103
- return true;
104
- }
105
- return args.reduce((acc, arg) => {
106
- const result = arg.accept(this);
107
- if (typeof result === "function") {
108
- return operatorFunction(acc, result(document));
109
- }
110
- else {
111
- throw new Error("Filter is not a function");
112
- }
113
- }, true);
114
- };
115
- }
116
- else {
117
- throw new Error("Operator not allowed");
118
- }
119
- }
120
- /**
121
- * Visits the comparison part of a structured query and translates it into
122
- * a functional filter.
123
- * @param comparison The comparison part of a structured query.
124
- * @returns A function that takes a `Document` as an argument and returns a boolean based on the comparison.
125
- */
126
- visitComparison(comparison) {
127
- const { comparator, attribute, value } = comparison;
128
- const undefinedTrue = [Comparators.ne];
129
- if (this.allowedComparators.includes(comparator)) {
130
- const comparatorFunction = this.getComparatorFunction(comparator);
131
- return (document) => {
132
- const documentValue = document.metadata[attribute];
133
- if (documentValue === undefined) {
134
- if (undefinedTrue.includes(comparator)) {
135
- return true;
136
- }
137
- return false;
138
- }
139
- return comparatorFunction(documentValue, castValue(value));
140
- };
141
- }
142
- else {
143
- throw new Error("Comparator not allowed");
144
- }
145
- }
146
- /**
147
- * Visits a structured query and translates it into a functional filter.
148
- * @param query The structured query to translate.
149
- * @returns An object containing a `filter` property, which is a function that takes a `Document` as an argument and returns a boolean based on the structured query.
150
- */
151
- visitStructuredQuery(query) {
152
- if (!query.filter) {
153
- return {};
154
- }
155
- const filterFunction = query.filter?.accept(this);
156
- if (typeof filterFunction !== "function") {
157
- throw new Error("Structured query filter is not a function");
158
- }
159
- return { filter: filterFunction };
160
- }
161
- /**
162
- * Merges two filters into one, based on the specified merge type.
163
- * @param defaultFilter The default filter function.
164
- * @param generatedFilter The generated filter function.
165
- * @param mergeType The type of merge to perform. Can be 'and', 'or', or 'replace'. Default is 'and'.
166
- * @returns A function that takes a `Document` as an argument and returns a boolean based on the merged filters, or `undefined` if both filters are empty.
167
- */
168
- mergeFilters(defaultFilter, generatedFilter, mergeType = "and") {
169
- if (isFilterEmpty(defaultFilter) && isFilterEmpty(generatedFilter)) {
170
- return undefined;
171
- }
172
- if (isFilterEmpty(defaultFilter) || mergeType === "replace") {
173
- if (isFilterEmpty(generatedFilter)) {
174
- return undefined;
175
- }
176
- return generatedFilter;
177
- }
178
- if (isFilterEmpty(generatedFilter)) {
179
- if (mergeType === "and") {
180
- return undefined;
181
- }
182
- return defaultFilter;
183
- }
184
- if (mergeType === "and") {
185
- return (document) => defaultFilter(document) && generatedFilter(document);
186
- }
187
- else if (mergeType === "or") {
188
- return (document) => defaultFilter(document) || generatedFilter(document);
189
- }
190
- else {
191
- throw new Error("Unknown merge type");
192
- }
193
- }
194
- }
1
+ export { FunctionalTranslator, } from "@langchain/core/structured_query";
@@ -2,12 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SelfQueryRetriever = exports.FunctionalTranslator = exports.BasicTranslator = exports.BaseTranslator = void 0;
4
4
  const retrievers_1 = require("@langchain/core/retrievers");
5
+ const structured_query_1 = require("@langchain/core/structured_query");
6
+ Object.defineProperty(exports, "BaseTranslator", { enumerable: true, get: function () { return structured_query_1.BaseTranslator; } });
7
+ Object.defineProperty(exports, "BasicTranslator", { enumerable: true, get: function () { return structured_query_1.BasicTranslator; } });
8
+ Object.defineProperty(exports, "FunctionalTranslator", { enumerable: true, get: function () { return structured_query_1.FunctionalTranslator; } });
5
9
  const index_js_1 = require("../../chains/query_constructor/index.cjs");
6
- const functional_js_1 = require("./functional.cjs");
7
- Object.defineProperty(exports, "FunctionalTranslator", { enumerable: true, get: function () { return functional_js_1.FunctionalTranslator; } });
8
- const base_js_1 = require("./base.cjs");
9
- Object.defineProperty(exports, "BaseTranslator", { enumerable: true, get: function () { return base_js_1.BaseTranslator; } });
10
- Object.defineProperty(exports, "BasicTranslator", { enumerable: true, get: function () { return base_js_1.BasicTranslator; } });
11
10
  /**
12
11
  * Class for question answering over an index. It retrieves relevant
13
12
  * documents based on a query. It extends the BaseRetriever class and
@@ -41,7 +40,7 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
41
40
  writable: true,
42
41
  value: void 0
43
42
  });
44
- Object.defineProperty(this, "llmChain", {
43
+ Object.defineProperty(this, "queryConstructor", {
45
44
  enumerable: true,
46
45
  configurable: true,
47
46
  writable: true,
@@ -72,17 +71,14 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
72
71
  value: { k: 4, forceDefaultFilter: false }
73
72
  });
74
73
  this.vectorStore = options.vectorStore;
75
- this.llmChain = options.llmChain;
74
+ this.queryConstructor = options.queryConstructor;
76
75
  this.verbose = options.verbose ?? false;
77
76
  this.searchParams = options.searchParams ?? this.searchParams;
78
77
  this.useOriginalQuery = options.useOriginalQuery ?? this.useOriginalQuery;
79
78
  this.structuredQueryTranslator = options.structuredQueryTranslator;
80
79
  }
81
80
  async _getRelevantDocuments(query, runManager) {
82
- const { [this.llmChain.outputKey]: output } = await this.llmChain.call({
83
- [this.llmChain.inputKeys[0]]: query,
84
- }, runManager?.getChild("llm_chain"));
85
- const generatedStructuredQuery = output;
81
+ const generatedStructuredQuery = await this.queryConstructor.invoke({ query }, runManager?.getChild("query_constructor"));
86
82
  const nextArg = this.structuredQueryTranslator.visitStructuredQuery(generatedStructuredQuery);
87
83
  const filter = this.structuredQueryTranslator.mergeFilters(this.searchParams?.filter, nextArg.filter, this.searchParams?.mergeFiltersOperator, this.searchParams?.forceDefaultFilter);
88
84
  const generatedQuery = generatedStructuredQuery.query;
@@ -103,7 +99,7 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
103
99
  */
104
100
  static fromLLM(options) {
105
101
  const { structuredQueryTranslator, allowedComparators, allowedOperators, llm, documentContents, attributeInfo, examples, vectorStore, ...rest } = options;
106
- const llmChain = (0, index_js_1.loadQueryConstructorChain)({
102
+ const queryConstructor = (0, index_js_1.loadQueryConstructorRunnable)({
107
103
  llm,
108
104
  documentContents,
109
105
  attributeInfo,
@@ -113,7 +109,7 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
113
109
  });
114
110
  return new SelfQueryRetriever({
115
111
  ...rest,
116
- llmChain,
112
+ queryConstructor,
117
113
  vectorStore,
118
114
  structuredQueryTranslator,
119
115
  });
@@ -1,11 +1,10 @@
1
+ import { RunnableInterface } from "@langchain/core/runnables";
1
2
  import { BaseRetriever, type BaseRetrieverInput } from "@langchain/core/retrievers";
2
3
  import { Document } from "@langchain/core/documents";
3
4
  import { VectorStore } from "@langchain/core/vectorstores";
4
- import { CallbackManagerForRetrieverRun } from "@langchain/core/callbacks/manager";
5
- import { LLMChain } from "../../chains/llm_chain.js";
6
- import { QueryConstructorChainOptions } from "../../chains/query_constructor/index.js";
7
- import { FunctionalTranslator } from "./functional.js";
8
- import { BaseTranslator, BasicTranslator } from "./base.js";
5
+ import { BaseTranslator, BasicTranslator, FunctionalTranslator, StructuredQuery } from "@langchain/core/structured_query";
6
+ import { CallbackManagerForRetrieverRun } from "../../callbacks/manager.js";
7
+ import { QueryConstructorRunnableOptions } from "../../chains/query_constructor/index.js";
9
8
  export { BaseTranslator, BasicTranslator, FunctionalTranslator };
10
9
  /**
11
10
  * Interface for the arguments required to create a SelfQueryRetriever
@@ -14,7 +13,9 @@ export { BaseTranslator, BasicTranslator, FunctionalTranslator };
14
13
  export interface SelfQueryRetrieverArgs<T extends VectorStore> extends BaseRetrieverInput {
15
14
  vectorStore: T;
16
15
  structuredQueryTranslator: BaseTranslator<T>;
17
- llmChain: LLMChain;
16
+ queryConstructor: RunnableInterface<{
17
+ query: string;
18
+ }, StructuredQuery>;
18
19
  verbose?: boolean;
19
20
  useOriginalQuery?: boolean;
20
21
  searchParams?: {
@@ -46,7 +47,9 @@ export declare class SelfQueryRetriever<T extends VectorStore> extends BaseRetri
46
47
  static lc_name(): string;
47
48
  get lc_namespace(): string[];
48
49
  vectorStore: T;
49
- llmChain: LLMChain;
50
+ queryConstructor: RunnableInterface<{
51
+ query: string;
52
+ }, StructuredQuery>;
50
53
  verbose?: boolean;
51
54
  structuredQueryTranslator: BaseTranslator<T>;
52
55
  useOriginalQuery: boolean;
@@ -67,5 +70,5 @@ export declare class SelfQueryRetriever<T extends VectorStore> extends BaseRetri
67
70
  * @param options The options used to create the SelfQueryRetriever instance. It includes the QueryConstructorChainOptions and all the SelfQueryRetrieverArgs except 'llmChain'.
68
71
  * @returns A new instance of SelfQueryRetriever.
69
72
  */
70
- static fromLLM<T extends VectorStore>(options: QueryConstructorChainOptions & Omit<SelfQueryRetrieverArgs<T>, "llmChain">): SelfQueryRetriever<T>;
73
+ static fromLLM<T extends VectorStore>(options: QueryConstructorRunnableOptions & Omit<SelfQueryRetrieverArgs<T>, "queryConstructor">): SelfQueryRetriever<T>;
71
74
  }
@@ -1,7 +1,6 @@
1
1
  import { BaseRetriever, } from "@langchain/core/retrievers";
2
- import { loadQueryConstructorChain, } from "../../chains/query_constructor/index.js";
3
- import { FunctionalTranslator } from "./functional.js";
4
- import { BaseTranslator, BasicTranslator } from "./base.js";
2
+ import { BaseTranslator, BasicTranslator, FunctionalTranslator, } from "@langchain/core/structured_query";
3
+ import { loadQueryConstructorRunnable, } from "../../chains/query_constructor/index.js";
5
4
  export { BaseTranslator, BasicTranslator, FunctionalTranslator };
6
5
  /**
7
6
  * Class for question answering over an index. It retrieves relevant
@@ -36,7 +35,7 @@ export class SelfQueryRetriever extends BaseRetriever {
36
35
  writable: true,
37
36
  value: void 0
38
37
  });
39
- Object.defineProperty(this, "llmChain", {
38
+ Object.defineProperty(this, "queryConstructor", {
40
39
  enumerable: true,
41
40
  configurable: true,
42
41
  writable: true,
@@ -67,17 +66,14 @@ export class SelfQueryRetriever extends BaseRetriever {
67
66
  value: { k: 4, forceDefaultFilter: false }
68
67
  });
69
68
  this.vectorStore = options.vectorStore;
70
- this.llmChain = options.llmChain;
69
+ this.queryConstructor = options.queryConstructor;
71
70
  this.verbose = options.verbose ?? false;
72
71
  this.searchParams = options.searchParams ?? this.searchParams;
73
72
  this.useOriginalQuery = options.useOriginalQuery ?? this.useOriginalQuery;
74
73
  this.structuredQueryTranslator = options.structuredQueryTranslator;
75
74
  }
76
75
  async _getRelevantDocuments(query, runManager) {
77
- const { [this.llmChain.outputKey]: output } = await this.llmChain.call({
78
- [this.llmChain.inputKeys[0]]: query,
79
- }, runManager?.getChild("llm_chain"));
80
- const generatedStructuredQuery = output;
76
+ const generatedStructuredQuery = await this.queryConstructor.invoke({ query }, runManager?.getChild("query_constructor"));
81
77
  const nextArg = this.structuredQueryTranslator.visitStructuredQuery(generatedStructuredQuery);
82
78
  const filter = this.structuredQueryTranslator.mergeFilters(this.searchParams?.filter, nextArg.filter, this.searchParams?.mergeFiltersOperator, this.searchParams?.forceDefaultFilter);
83
79
  const generatedQuery = generatedStructuredQuery.query;
@@ -98,7 +94,7 @@ export class SelfQueryRetriever extends BaseRetriever {
98
94
  */
99
95
  static fromLLM(options) {
100
96
  const { structuredQueryTranslator, allowedComparators, allowedOperators, llm, documentContents, attributeInfo, examples, vectorStore, ...rest } = options;
101
- const llmChain = loadQueryConstructorChain({
97
+ const queryConstructor = loadQueryConstructorRunnable({
102
98
  llm,
103
99
  documentContents,
104
100
  attributeInfo,
@@ -108,7 +104,7 @@ export class SelfQueryRetriever extends BaseRetriever {
108
104
  });
109
105
  return new SelfQueryRetriever({
110
106
  ...rest,
111
- llmChain,
107
+ queryConstructor,
112
108
  vectorStore,
113
109
  structuredQueryTranslator,
114
110
  });
@@ -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