langchain 0.0.194 → 0.0.196
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.
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/embeddings/hf.cjs +1 -2
- package/dist/embeddings/hf.js +1 -2
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/openai_assistant/index.cjs +2 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -1
- package/dist/experimental/openai_assistant/index.js +2 -1
- package/dist/experimental/openai_files/index.cjs +88 -0
- package/dist/experimental/openai_files/index.d.ts +79 -0
- package/dist/experimental/openai_files/index.js +84 -0
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/retrievers/chaindesk.cjs +9 -1
- package/dist/retrievers/chaindesk.d.ts +3 -1
- package/dist/retrievers/chaindesk.js +9 -1
- package/dist/retrievers/self_query/vectara.cjs +138 -0
- package/dist/retrievers/self_query/vectara.d.ts +41 -0
- package/dist/retrievers/self_query/vectara.js +134 -0
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/dist/vectorstores/vectara.cjs +77 -7
- package/dist/vectorstores/vectara.d.ts +9 -3
- package/dist/vectorstores/vectara.js +54 -7
- package/experimental/openai_files.cjs +1 -0
- package/experimental/openai_files.d.ts +1 -0
- package/experimental/openai_files.js +1 -0
- package/package.json +27 -5
- package/retrievers/self_query/vectara.cjs +1 -0
- package/retrievers/self_query/vectara.d.ts +1 -0
- package/retrievers/self_query/vectara.js +1 -0
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -19,7 +19,7 @@ class ChaindeskRetriever extends retriever_js_1.BaseRetriever {
|
|
|
19
19
|
static lc_name() {
|
|
20
20
|
return "ChaindeskRetriever";
|
|
21
21
|
}
|
|
22
|
-
constructor({ datastoreId, apiKey, topK, ...rest }) {
|
|
22
|
+
constructor({ datastoreId, apiKey, topK, filter, ...rest }) {
|
|
23
23
|
super();
|
|
24
24
|
Object.defineProperty(this, "lc_namespace", {
|
|
25
25
|
enumerable: true,
|
|
@@ -45,6 +45,12 @@ class ChaindeskRetriever extends retriever_js_1.BaseRetriever {
|
|
|
45
45
|
writable: true,
|
|
46
46
|
value: void 0
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(this, "filter", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: void 0
|
|
53
|
+
});
|
|
48
54
|
Object.defineProperty(this, "apiKey", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
configurable: true,
|
|
@@ -55,6 +61,7 @@ class ChaindeskRetriever extends retriever_js_1.BaseRetriever {
|
|
|
55
61
|
this.datastoreId = datastoreId;
|
|
56
62
|
this.apiKey = apiKey;
|
|
57
63
|
this.topK = topK;
|
|
64
|
+
this.filter = filter;
|
|
58
65
|
}
|
|
59
66
|
async getRelevantDocuments(query) {
|
|
60
67
|
const r = await this.caller.call(fetch, `https://app.chaindesk.ai/api/datastores/${this.datastoreId}/query`, {
|
|
@@ -62,6 +69,7 @@ class ChaindeskRetriever extends retriever_js_1.BaseRetriever {
|
|
|
62
69
|
body: JSON.stringify({
|
|
63
70
|
query,
|
|
64
71
|
...(this.topK ? { topK: this.topK } : {}),
|
|
72
|
+
...(this.filter ? { filters: this.filter } : {}),
|
|
65
73
|
}),
|
|
66
74
|
headers: {
|
|
67
75
|
"Content-Type": "application/json",
|
|
@@ -4,6 +4,7 @@ import { AsyncCaller, type AsyncCallerParams } from "../util/async_caller.js";
|
|
|
4
4
|
export interface ChaindeskRetrieverArgs extends AsyncCallerParams, BaseRetrieverInput {
|
|
5
5
|
datastoreId: string;
|
|
6
6
|
topK?: number;
|
|
7
|
+
filter?: Record<string, unknown>;
|
|
7
8
|
apiKey?: string;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -23,7 +24,8 @@ export declare class ChaindeskRetriever extends BaseRetriever {
|
|
|
23
24
|
caller: AsyncCaller;
|
|
24
25
|
datastoreId: string;
|
|
25
26
|
topK?: number;
|
|
27
|
+
filter?: Record<string, unknown>;
|
|
26
28
|
apiKey?: string;
|
|
27
|
-
constructor({ datastoreId, apiKey, topK, ...rest }: ChaindeskRetrieverArgs);
|
|
29
|
+
constructor({ datastoreId, apiKey, topK, filter, ...rest }: ChaindeskRetrieverArgs);
|
|
28
30
|
getRelevantDocuments(query: string): Promise<Document[]>;
|
|
29
31
|
}
|
|
@@ -16,7 +16,7 @@ export class ChaindeskRetriever extends BaseRetriever {
|
|
|
16
16
|
static lc_name() {
|
|
17
17
|
return "ChaindeskRetriever";
|
|
18
18
|
}
|
|
19
|
-
constructor({ datastoreId, apiKey, topK, ...rest }) {
|
|
19
|
+
constructor({ datastoreId, apiKey, topK, filter, ...rest }) {
|
|
20
20
|
super();
|
|
21
21
|
Object.defineProperty(this, "lc_namespace", {
|
|
22
22
|
enumerable: true,
|
|
@@ -42,6 +42,12 @@ export class ChaindeskRetriever extends BaseRetriever {
|
|
|
42
42
|
writable: true,
|
|
43
43
|
value: void 0
|
|
44
44
|
});
|
|
45
|
+
Object.defineProperty(this, "filter", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
45
51
|
Object.defineProperty(this, "apiKey", {
|
|
46
52
|
enumerable: true,
|
|
47
53
|
configurable: true,
|
|
@@ -52,6 +58,7 @@ export class ChaindeskRetriever extends BaseRetriever {
|
|
|
52
58
|
this.datastoreId = datastoreId;
|
|
53
59
|
this.apiKey = apiKey;
|
|
54
60
|
this.topK = topK;
|
|
61
|
+
this.filter = filter;
|
|
55
62
|
}
|
|
56
63
|
async getRelevantDocuments(query) {
|
|
57
64
|
const r = await this.caller.call(fetch, `https://app.chaindesk.ai/api/datastores/${this.datastoreId}/query`, {
|
|
@@ -59,6 +66,7 @@ export class ChaindeskRetriever extends BaseRetriever {
|
|
|
59
66
|
body: JSON.stringify({
|
|
60
67
|
query,
|
|
61
68
|
...(this.topK ? { topK: this.topK } : {}),
|
|
69
|
+
...(this.filter ? { filters: this.filter } : {}),
|
|
62
70
|
}),
|
|
63
71
|
headers: {
|
|
64
72
|
"Content-Type": "application/json",
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
7
|
+
function processValue(value) {
|
|
8
|
+
/** Convert a value to a string and add single quotes if it is a string. */
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
return `'${value}'`;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return String(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class VectaraTranslator extends base_js_1.BaseTranslator {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
Object.defineProperty(this, "allowedOperators", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: [ir_js_1.Operators.and, ir_js_1.Operators.or]
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "allowedComparators", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
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,
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
formatFunction(func) {
|
|
40
|
+
if (func in ir_js_1.Comparators) {
|
|
41
|
+
if (this.allowedComparators.length > 0 &&
|
|
42
|
+
this.allowedComparators.indexOf(func) === -1) {
|
|
43
|
+
throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (func in ir_js_1.Operators) {
|
|
47
|
+
if (this.allowedOperators.length > 0 &&
|
|
48
|
+
this.allowedOperators.indexOf(func) === -1) {
|
|
49
|
+
throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error("Unknown comparator or operator");
|
|
54
|
+
}
|
|
55
|
+
const mapDict = {
|
|
56
|
+
and: " and ",
|
|
57
|
+
or: " or ",
|
|
58
|
+
eq: "=",
|
|
59
|
+
ne: "!=",
|
|
60
|
+
lt: "<",
|
|
61
|
+
lte: "<=",
|
|
62
|
+
gt: ">",
|
|
63
|
+
gte: ">=",
|
|
64
|
+
};
|
|
65
|
+
return mapDict[func];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Visits an operation and returns a VectaraOperationResult. The
|
|
69
|
+
* operation's arguments are visited and the operator is formatted.
|
|
70
|
+
* @param operation The operation to visit.
|
|
71
|
+
* @returns A VectaraOperationResult.
|
|
72
|
+
*/
|
|
73
|
+
visitOperation(operation) {
|
|
74
|
+
const args = operation.args?.map((arg) => arg.accept(this));
|
|
75
|
+
const operator = this.formatFunction(operation.operator);
|
|
76
|
+
return `( ${args.join(operator)} )`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Visits a comparison and returns a VectaraComparisonResult. The
|
|
80
|
+
* comparison's value is checked for type and the comparator is formatted.
|
|
81
|
+
* Throws an error if the value type is not supported.
|
|
82
|
+
* @param comparison The comparison to visit.
|
|
83
|
+
* @returns A VectaraComparisonResult.
|
|
84
|
+
*/
|
|
85
|
+
visitComparison(comparison) {
|
|
86
|
+
const comparator = this.formatFunction(comparison.comparator);
|
|
87
|
+
return `( doc.${comparison.attribute} ${comparator} ${processValue(comparison.value)} )`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Visits a structured query and returns a VectaraStructuredQueryResult.
|
|
91
|
+
* If the query has a filter, it is visited.
|
|
92
|
+
* @param query The structured query to visit.
|
|
93
|
+
* @returns A VectaraStructuredQueryResult.
|
|
94
|
+
*/
|
|
95
|
+
visitStructuredQuery(query) {
|
|
96
|
+
let nextArg = {};
|
|
97
|
+
if (query.filter) {
|
|
98
|
+
nextArg = {
|
|
99
|
+
filter: { filter: query.filter.accept(this) },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return nextArg;
|
|
103
|
+
}
|
|
104
|
+
mergeFilters(defaultFilter, generatedFilter, mergeType = "and", forceDefaultFilter = false) {
|
|
105
|
+
if ((0, utils_js_1.isFilterEmpty)(defaultFilter) && (0, utils_js_1.isFilterEmpty)(generatedFilter)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
if ((0, utils_js_1.isFilterEmpty)(defaultFilter) || mergeType === "replace") {
|
|
109
|
+
if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return generatedFilter;
|
|
113
|
+
}
|
|
114
|
+
if ((0, utils_js_1.isFilterEmpty)(generatedFilter)) {
|
|
115
|
+
if (forceDefaultFilter) {
|
|
116
|
+
return defaultFilter;
|
|
117
|
+
}
|
|
118
|
+
if (mergeType === "and") {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return defaultFilter;
|
|
122
|
+
}
|
|
123
|
+
if (mergeType === "and") {
|
|
124
|
+
return {
|
|
125
|
+
filter: `${defaultFilter} and ${generatedFilter}`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else if (mergeType === "or") {
|
|
129
|
+
return {
|
|
130
|
+
filter: `${defaultFilter} or ${generatedFilter}`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
throw new Error("Unknown merge type");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.VectaraTranslator = VectaraTranslator;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Comparator, Comparison, Operation, Operator, StructuredQuery } from "../../chains/query_constructor/ir.js";
|
|
2
|
+
import { VectaraFilter, VectaraStore } from "../../vectorstores/vectara.js";
|
|
3
|
+
import { BaseTranslator } from "./base.js";
|
|
4
|
+
export type VectaraVisitorResult = VectaraOperationResult | VectaraComparisonResult | VectaraVisitorStructuredQueryResult;
|
|
5
|
+
export type VectaraOperationResult = String;
|
|
6
|
+
export type VectaraComparisonResult = String;
|
|
7
|
+
export type VectaraVisitorStructuredQueryResult = {
|
|
8
|
+
filter?: {
|
|
9
|
+
filter?: VectaraOperationResult | VectaraComparisonResult;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare class VectaraTranslator<T extends VectaraStore> extends BaseTranslator<T> {
|
|
13
|
+
VisitOperationOutput: VectaraOperationResult;
|
|
14
|
+
VisitComparisonOutput: VectaraComparisonResult;
|
|
15
|
+
allowedOperators: Operator[];
|
|
16
|
+
allowedComparators: Comparator[];
|
|
17
|
+
formatFunction(func: Operator | Comparator): string;
|
|
18
|
+
/**
|
|
19
|
+
* Visits an operation and returns a VectaraOperationResult. The
|
|
20
|
+
* operation's arguments are visited and the operator is formatted.
|
|
21
|
+
* @param operation The operation to visit.
|
|
22
|
+
* @returns A VectaraOperationResult.
|
|
23
|
+
*/
|
|
24
|
+
visitOperation(operation: Operation): this["VisitOperationOutput"];
|
|
25
|
+
/**
|
|
26
|
+
* Visits a comparison and returns a VectaraComparisonResult. The
|
|
27
|
+
* comparison's value is checked for type and the comparator is formatted.
|
|
28
|
+
* Throws an error if the value type is not supported.
|
|
29
|
+
* @param comparison The comparison to visit.
|
|
30
|
+
* @returns A VectaraComparisonResult.
|
|
31
|
+
*/
|
|
32
|
+
visitComparison(comparison: Comparison): this["VisitComparisonOutput"];
|
|
33
|
+
/**
|
|
34
|
+
* Visits a structured query and returns a VectaraStructuredQueryResult.
|
|
35
|
+
* If the query has a filter, it is visited.
|
|
36
|
+
* @param query The structured query to visit.
|
|
37
|
+
* @returns A VectaraStructuredQueryResult.
|
|
38
|
+
*/
|
|
39
|
+
visitStructuredQuery(query: StructuredQuery): this["VisitStructuredQueryOutput"];
|
|
40
|
+
mergeFilters(defaultFilter: VectaraFilter | undefined, generatedFilter: VectaraFilter | undefined, mergeType?: string, forceDefaultFilter?: boolean): VectaraFilter | undefined;
|
|
41
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Comparators, Operators, } from "../../chains/query_constructor/ir.js";
|
|
2
|
+
import { BaseTranslator } from "./base.js";
|
|
3
|
+
import { isFilterEmpty } from "./utils.js";
|
|
4
|
+
function processValue(value) {
|
|
5
|
+
/** Convert a value to a string and add single quotes if it is a string. */
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
return `'${value}'`;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return String(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class VectaraTranslator extends BaseTranslator {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
Object.defineProperty(this, "allowedOperators", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: [Operators.and, Operators.or]
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "allowedComparators", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: [
|
|
27
|
+
Comparators.eq,
|
|
28
|
+
Comparators.ne,
|
|
29
|
+
Comparators.lt,
|
|
30
|
+
Comparators.lte,
|
|
31
|
+
Comparators.gt,
|
|
32
|
+
Comparators.gte,
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
formatFunction(func) {
|
|
37
|
+
if (func in Comparators) {
|
|
38
|
+
if (this.allowedComparators.length > 0 &&
|
|
39
|
+
this.allowedComparators.indexOf(func) === -1) {
|
|
40
|
+
throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (func in Operators) {
|
|
44
|
+
if (this.allowedOperators.length > 0 &&
|
|
45
|
+
this.allowedOperators.indexOf(func) === -1) {
|
|
46
|
+
throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("Unknown comparator or operator");
|
|
51
|
+
}
|
|
52
|
+
const mapDict = {
|
|
53
|
+
and: " and ",
|
|
54
|
+
or: " or ",
|
|
55
|
+
eq: "=",
|
|
56
|
+
ne: "!=",
|
|
57
|
+
lt: "<",
|
|
58
|
+
lte: "<=",
|
|
59
|
+
gt: ">",
|
|
60
|
+
gte: ">=",
|
|
61
|
+
};
|
|
62
|
+
return mapDict[func];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Visits an operation and returns a VectaraOperationResult. The
|
|
66
|
+
* operation's arguments are visited and the operator is formatted.
|
|
67
|
+
* @param operation The operation to visit.
|
|
68
|
+
* @returns A VectaraOperationResult.
|
|
69
|
+
*/
|
|
70
|
+
visitOperation(operation) {
|
|
71
|
+
const args = operation.args?.map((arg) => arg.accept(this));
|
|
72
|
+
const operator = this.formatFunction(operation.operator);
|
|
73
|
+
return `( ${args.join(operator)} )`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Visits a comparison and returns a VectaraComparisonResult. The
|
|
77
|
+
* comparison's value is checked for type and the comparator is formatted.
|
|
78
|
+
* Throws an error if the value type is not supported.
|
|
79
|
+
* @param comparison The comparison to visit.
|
|
80
|
+
* @returns A VectaraComparisonResult.
|
|
81
|
+
*/
|
|
82
|
+
visitComparison(comparison) {
|
|
83
|
+
const comparator = this.formatFunction(comparison.comparator);
|
|
84
|
+
return `( doc.${comparison.attribute} ${comparator} ${processValue(comparison.value)} )`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Visits a structured query and returns a VectaraStructuredQueryResult.
|
|
88
|
+
* If the query has a filter, it is visited.
|
|
89
|
+
* @param query The structured query to visit.
|
|
90
|
+
* @returns A VectaraStructuredQueryResult.
|
|
91
|
+
*/
|
|
92
|
+
visitStructuredQuery(query) {
|
|
93
|
+
let nextArg = {};
|
|
94
|
+
if (query.filter) {
|
|
95
|
+
nextArg = {
|
|
96
|
+
filter: { filter: query.filter.accept(this) },
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return nextArg;
|
|
100
|
+
}
|
|
101
|
+
mergeFilters(defaultFilter, generatedFilter, mergeType = "and", forceDefaultFilter = false) {
|
|
102
|
+
if (isFilterEmpty(defaultFilter) && isFilterEmpty(generatedFilter)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
if (isFilterEmpty(defaultFilter) || mergeType === "replace") {
|
|
106
|
+
if (isFilterEmpty(generatedFilter)) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return generatedFilter;
|
|
110
|
+
}
|
|
111
|
+
if (isFilterEmpty(generatedFilter)) {
|
|
112
|
+
if (forceDefaultFilter) {
|
|
113
|
+
return defaultFilter;
|
|
114
|
+
}
|
|
115
|
+
if (mergeType === "and") {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
return defaultFilter;
|
|
119
|
+
}
|
|
120
|
+
if (mergeType === "and") {
|
|
121
|
+
return {
|
|
122
|
+
filter: `${defaultFilter} and ${generatedFilter}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else if (mergeType === "or") {
|
|
126
|
+
return {
|
|
127
|
+
filter: `${defaultFilter} or ${generatedFilter}`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
throw new Error("Unknown merge type");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("
|
|
17
|
+
__exportStar(require("langchain-core/runnables"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "langchain-core/runnables";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "langchain-core/runnables";
|
package/dist/schema/document.cjs
CHANGED
|
@@ -1,44 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MappingDocumentTransformer = exports.BaseDocumentTransformer = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
* Abstract base class for document transformation systems.
|
|
7
|
-
*
|
|
8
|
-
* A document transformation system takes an array of Documents and returns an
|
|
9
|
-
* array of transformed Documents. These arrays do not necessarily have to have
|
|
10
|
-
* the same length.
|
|
11
|
-
*
|
|
12
|
-
* One example of this is a text splitter that splits a large document into
|
|
13
|
-
* many smaller documents.
|
|
14
|
-
*/
|
|
15
|
-
class BaseDocumentTransformer extends index_js_1.Runnable {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: ["langchain", "document_transformers"]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Method to invoke the document transformation. This method calls the
|
|
27
|
-
* transformDocuments method with the provided input.
|
|
28
|
-
* @param input The input documents to be transformed.
|
|
29
|
-
* @param _options Optional configuration object to customize the behavior of callbacks.
|
|
30
|
-
* @returns A Promise that resolves to the transformed documents.
|
|
31
|
-
*/
|
|
32
|
-
invoke(input, _options) {
|
|
33
|
-
return this.transformDocuments(input);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.BaseDocumentTransformer = BaseDocumentTransformer;
|
|
4
|
+
const document_1 = require("langchain-core/schema/document");
|
|
5
|
+
Object.defineProperty(exports, "BaseDocumentTransformer", { enumerable: true, get: function () { return document_1.BaseDocumentTransformer; } });
|
|
37
6
|
/**
|
|
38
7
|
* Class for document transformers that return exactly one transformed document
|
|
39
8
|
* for each input document.
|
|
40
9
|
*/
|
|
41
|
-
class MappingDocumentTransformer extends BaseDocumentTransformer {
|
|
10
|
+
class MappingDocumentTransformer extends document_1.BaseDocumentTransformer {
|
|
42
11
|
async transformDocuments(documents) {
|
|
43
12
|
const newDocuments = [];
|
|
44
13
|
for (const document of documents) {
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseDocumentTransformer } from "langchain-core/schema/document";
|
|
2
2
|
import { Document } from "../document.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for document transformation systems.
|
|
6
|
-
*
|
|
7
|
-
* A document transformation system takes an array of Documents and returns an
|
|
8
|
-
* array of transformed Documents. These arrays do not necessarily have to have
|
|
9
|
-
* the same length.
|
|
10
|
-
*
|
|
11
|
-
* One example of this is a text splitter that splits a large document into
|
|
12
|
-
* many smaller documents.
|
|
13
|
-
*/
|
|
14
|
-
export declare abstract class BaseDocumentTransformer<RunInput extends Document[] = Document[], RunOutput extends Document[] = Document[]> extends Runnable<RunInput, RunOutput> {
|
|
15
|
-
lc_namespace: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Transform a list of documents.
|
|
18
|
-
* @param documents A sequence of documents to be transformed.
|
|
19
|
-
* @returns A list of transformed documents.
|
|
20
|
-
*/
|
|
21
|
-
abstract transformDocuments(documents: RunInput): Promise<RunOutput>;
|
|
22
|
-
/**
|
|
23
|
-
* Method to invoke the document transformation. This method calls the
|
|
24
|
-
* transformDocuments method with the provided input.
|
|
25
|
-
* @param input The input documents to be transformed.
|
|
26
|
-
* @param _options Optional configuration object to customize the behavior of callbacks.
|
|
27
|
-
* @returns A Promise that resolves to the transformed documents.
|
|
28
|
-
*/
|
|
29
|
-
invoke(input: RunInput, _options?: Partial<BaseCallbackConfig>): Promise<RunOutput>;
|
|
30
|
-
}
|
|
3
|
+
export { BaseDocumentTransformer };
|
|
31
4
|
/**
|
|
32
5
|
* Class for document transformers that return exactly one transformed document
|
|
33
6
|
* for each input document.
|
package/dist/schema/document.js
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* Abstract base class for document transformation systems.
|
|
4
|
-
*
|
|
5
|
-
* A document transformation system takes an array of Documents and returns an
|
|
6
|
-
* array of transformed Documents. These arrays do not necessarily have to have
|
|
7
|
-
* the same length.
|
|
8
|
-
*
|
|
9
|
-
* One example of this is a text splitter that splits a large document into
|
|
10
|
-
* many smaller documents.
|
|
11
|
-
*/
|
|
12
|
-
export class BaseDocumentTransformer extends Runnable {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: ["langchain", "document_transformers"]
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Method to invoke the document transformation. This method calls the
|
|
24
|
-
* transformDocuments method with the provided input.
|
|
25
|
-
* @param input The input documents to be transformed.
|
|
26
|
-
* @param _options Optional configuration object to customize the behavior of callbacks.
|
|
27
|
-
* @returns A Promise that resolves to the transformed documents.
|
|
28
|
-
*/
|
|
29
|
-
invoke(input, _options) {
|
|
30
|
-
return this.transformDocuments(input);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import { BaseDocumentTransformer } from "langchain-core/schema/document";
|
|
2
|
+
export { BaseDocumentTransformer };
|
|
33
3
|
/**
|
|
34
4
|
* Class for document transformers that return exactly one transformed document
|
|
35
5
|
* for each input document.
|