@langchain/core 1.1.6 → 1.1.7
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/CHANGELOG.md +12 -0
- package/dist/caches/index.d.cts.map +1 -1
- package/dist/caches/index.d.ts.map +1 -1
- package/dist/callbacks/base.cjs.map +1 -1
- package/dist/callbacks/base.d.cts +2 -2
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.ts +2 -2
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/base.js.map +1 -1
- package/dist/callbacks/manager.cjs +3 -3
- package/dist/callbacks/manager.cjs.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -1
- package/dist/callbacks/manager.d.cts.map +1 -1
- package/dist/callbacks/manager.d.ts +1 -1
- package/dist/callbacks/manager.d.ts.map +1 -1
- package/dist/callbacks/manager.js +3 -3
- package/dist/callbacks/manager.js.map +1 -1
- package/dist/load/import_map.cjs +2 -0
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +2 -0
- package/dist/load/import_map.js.map +1 -1
- package/dist/load/index.d.ts.map +1 -1
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/runnables/base.cjs +1 -1
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.js +1 -1
- package/dist/runnables/base.js.map +1 -1
- package/dist/tracers/base.cjs +5 -2
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.d.cts.map +1 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/base.d.ts.map +1 -1
- package/dist/tracers/base.js +5 -2
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/tracer_langchain.cjs +31 -3
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.d.cts +8 -7
- package/dist/tracers/tracer_langchain.d.cts.map +1 -1
- package/dist/tracers/tracer_langchain.d.ts +8 -7
- package/dist/tracers/tracer_langchain.d.ts.map +1 -1
- package/dist/tracers/tracer_langchain.js +31 -3
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/utils/context.cjs +107 -0
- package/dist/utils/context.cjs.map +1 -0
- package/dist/utils/context.d.cts +44 -0
- package/dist/utils/context.d.cts.map +1 -0
- package/dist/utils/context.d.ts +44 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +101 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/vectorstores.d.cts.map +1 -1
- package/package.json +13 -2
- package/utils/context.cjs +1 -0
- package/utils/context.d.cts +1 -0
- package/utils/context.d.ts +1 -0
- package/utils/context.js +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/utils/context.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A tagged template function for creating formatted strings.
|
|
4
|
+
*
|
|
5
|
+
* This utility provides a clean, template literal-based API for string formatting
|
|
6
|
+
* that can be used for prompts, descriptions, and other text formatting needs.
|
|
7
|
+
*
|
|
8
|
+
* It automatically handles whitespace normalization and indentation, making it
|
|
9
|
+
* ideal for multi-line strings in code.
|
|
10
|
+
*
|
|
11
|
+
* When using this utility, it will:
|
|
12
|
+
* - Strip common leading indentation from all lines
|
|
13
|
+
* - Trim leading/trailing whitespace
|
|
14
|
+
* - Align multi-line interpolated values to match indentation
|
|
15
|
+
* - Support escape sequences: `\\n` (newline), `\\`` (backtick), `\\$` (dollar), `\\{` (brace)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { context } from "@langchain/core/utils/context";
|
|
20
|
+
*
|
|
21
|
+
* const role = "agent";
|
|
22
|
+
* const prompt = context`
|
|
23
|
+
* You are an ${role}.
|
|
24
|
+
* Your task is to help users.
|
|
25
|
+
* `;
|
|
26
|
+
* // Returns: "You are an agent.\nYour task is to help users."
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Multi-line interpolated values are aligned
|
|
32
|
+
* const items = "- Item 1\n- Item 2\n- Item 3";
|
|
33
|
+
* const message = context`
|
|
34
|
+
* Shopping list:
|
|
35
|
+
* ${items}
|
|
36
|
+
* End of list.
|
|
37
|
+
* `;
|
|
38
|
+
* // The items will be indented to match " " (4 spaces)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { context };
|
|
44
|
+
//# sourceMappingURL=context.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":["context","TemplateStringsArray"],"sources":["../../src/utils/context.d.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;\n//# sourceMappingURL=context.d.ts.map"],"mappings":";;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBA,OAAAA,UAAiBC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/utils/context.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A tagged template function for creating formatted strings.
|
|
4
|
+
*
|
|
5
|
+
* This utility provides a clean, template literal-based API for string formatting
|
|
6
|
+
* that can be used for prompts, descriptions, and other text formatting needs.
|
|
7
|
+
*
|
|
8
|
+
* It automatically handles whitespace normalization and indentation, making it
|
|
9
|
+
* ideal for multi-line strings in code.
|
|
10
|
+
*
|
|
11
|
+
* When using this utility, it will:
|
|
12
|
+
* - Strip common leading indentation from all lines
|
|
13
|
+
* - Trim leading/trailing whitespace
|
|
14
|
+
* - Align multi-line interpolated values to match indentation
|
|
15
|
+
* - Support escape sequences: `\\n` (newline), `\\`` (backtick), `\\$` (dollar), `\\{` (brace)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { context } from "@langchain/core/utils/context";
|
|
20
|
+
*
|
|
21
|
+
* const role = "agent";
|
|
22
|
+
* const prompt = context`
|
|
23
|
+
* You are an ${role}.
|
|
24
|
+
* Your task is to help users.
|
|
25
|
+
* `;
|
|
26
|
+
* // Returns: "You are an agent.\nYour task is to help users."
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Multi-line interpolated values are aligned
|
|
32
|
+
* const items = "- Item 1\n- Item 2\n- Item 3";
|
|
33
|
+
* const message = context`
|
|
34
|
+
* Shopping list:
|
|
35
|
+
* ${items}
|
|
36
|
+
* End of list.
|
|
37
|
+
* `;
|
|
38
|
+
* // The items will be indented to match " " (4 spaces)
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { context };
|
|
44
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","names":["context","TemplateStringsArray"],"sources":["../../src/utils/context.d.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;\n//# sourceMappingURL=context.d.ts.map"],"mappings":";;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBA,OAAAA,UAAiBC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { __export } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/context.ts
|
|
4
|
+
var context_exports = {};
|
|
5
|
+
__export(context_exports, { context: () => context });
|
|
6
|
+
/**
|
|
7
|
+
* A tagged template function for creating formatted strings.
|
|
8
|
+
*
|
|
9
|
+
* This utility provides a clean, template literal-based API for string formatting
|
|
10
|
+
* that can be used for prompts, descriptions, and other text formatting needs.
|
|
11
|
+
*
|
|
12
|
+
* It automatically handles whitespace normalization and indentation, making it
|
|
13
|
+
* ideal for multi-line strings in code.
|
|
14
|
+
*
|
|
15
|
+
* When using this utility, it will:
|
|
16
|
+
* - Strip common leading indentation from all lines
|
|
17
|
+
* - Trim leading/trailing whitespace
|
|
18
|
+
* - Align multi-line interpolated values to match indentation
|
|
19
|
+
* - Support escape sequences: `\\n` (newline), `\\`` (backtick), `\\$` (dollar), `\\{` (brace)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { context } from "@langchain/core/utils/context";
|
|
24
|
+
*
|
|
25
|
+
* const role = "agent";
|
|
26
|
+
* const prompt = context`
|
|
27
|
+
* You are an ${role}.
|
|
28
|
+
* Your task is to help users.
|
|
29
|
+
* `;
|
|
30
|
+
* // Returns: "You are an agent.\nYour task is to help users."
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Multi-line interpolated values are aligned
|
|
36
|
+
* const items = "- Item 1\n- Item 2\n- Item 3";
|
|
37
|
+
* const message = context`
|
|
38
|
+
* Shopping list:
|
|
39
|
+
* ${items}
|
|
40
|
+
* End of list.
|
|
41
|
+
* `;
|
|
42
|
+
* // The items will be indented to match " " (4 spaces)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function context(strings, ...values) {
|
|
46
|
+
const raw = strings.raw;
|
|
47
|
+
let result = "";
|
|
48
|
+
for (let i = 0; i < raw.length; i++) {
|
|
49
|
+
const next = raw[i].replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
50
|
+
result += next;
|
|
51
|
+
if (i < values.length) {
|
|
52
|
+
const value = alignValue(values[i], result);
|
|
53
|
+
result += typeof value === "string" ? value : JSON.stringify(value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
result = stripIndent(result);
|
|
57
|
+
result = result.trim();
|
|
58
|
+
result = result.replace(/\\n/g, "\n");
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Adjusts the indentation of a multi-line interpolated value to match the current line.
|
|
63
|
+
*
|
|
64
|
+
* @param value - The interpolated value
|
|
65
|
+
* @param precedingText - The text that comes before this value
|
|
66
|
+
* @returns The value with adjusted indentation
|
|
67
|
+
*/
|
|
68
|
+
function alignValue(value, precedingText) {
|
|
69
|
+
if (typeof value !== "string" || !value.includes("\n")) return value;
|
|
70
|
+
const currentLine = precedingText.slice(precedingText.lastIndexOf("\n") + 1);
|
|
71
|
+
const indentMatch = currentLine.match(/^(\s+)/);
|
|
72
|
+
if (indentMatch) {
|
|
73
|
+
const indent = indentMatch[1];
|
|
74
|
+
return value.replace(/\n/g, `\n${indent}`);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Strips common leading indentation from all lines.
|
|
80
|
+
*
|
|
81
|
+
* @param text - The text to process
|
|
82
|
+
* @returns The text with common indentation removed
|
|
83
|
+
*/
|
|
84
|
+
function stripIndent(text) {
|
|
85
|
+
const lines = text.split("\n");
|
|
86
|
+
let minIndent = null;
|
|
87
|
+
for (const line of lines) {
|
|
88
|
+
const match = line.match(/^(\s+)\S+/);
|
|
89
|
+
if (match) {
|
|
90
|
+
const indent = match[1].length;
|
|
91
|
+
if (minIndent === null) minIndent = indent;
|
|
92
|
+
else minIndent = Math.min(minIndent, indent);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (minIndent === null) return text;
|
|
96
|
+
return lines.map((line) => line[0] === " " || line[0] === " " ? line.slice(minIndent) : line).join("\n");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
export { context, context_exports };
|
|
101
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":["strings: TemplateStringsArray","value: unknown","precedingText: string","text: string","minIndent: number | null"],"sources":["../../src/utils/context.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport function context(\n strings: TemplateStringsArray,\n ...values: unknown[]\n): string {\n const raw = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < raw.length; i++) {\n // Handle escaped characters in template literals\n const next = raw[i]\n .replace(/\\\\\\n[ \\t]*/g, \"\") // escaped newlines (line continuation)\n .replace(/\\\\`/g, \"`\") // escaped backticks\n .replace(/\\\\\\$/g, \"$\") // escaped dollar signs\n .replace(/\\\\\\{/g, \"{\"); // escaped braces\n\n result += next;\n\n if (i < values.length) {\n const value = alignValue(values[i], result);\n result += typeof value === \"string\" ? value : JSON.stringify(value);\n }\n }\n\n // Strip common indentation\n result = stripIndent(result);\n\n // Trim leading/trailing whitespace\n result = result.trim();\n\n // Handle escaped \\n at the end (preserve intentional newlines)\n result = result.replace(/\\\\n/g, \"\\n\");\n\n return result;\n}\n\n/**\n * Adjusts the indentation of a multi-line interpolated value to match the current line.\n *\n * @param value - The interpolated value\n * @param precedingText - The text that comes before this value\n * @returns The value with adjusted indentation\n */\nfunction alignValue(value: unknown, precedingText: string): unknown {\n if (typeof value !== \"string\" || !value.includes(\"\\n\")) {\n return value;\n }\n\n const currentLine = precedingText.slice(precedingText.lastIndexOf(\"\\n\") + 1);\n const indentMatch = currentLine.match(/^(\\s+)/);\n\n if (indentMatch) {\n const indent = indentMatch[1];\n return value.replace(/\\n/g, `\\n${indent}`);\n }\n\n return value;\n}\n\n/**\n * Strips common leading indentation from all lines.\n *\n * @param text - The text to process\n * @returns The text with common indentation removed\n */\nfunction stripIndent(text: string): string {\n const lines = text.split(\"\\n\");\n\n // Find minimum indentation (only from lines that have content)\n let minIndent: number | null = null;\n for (const line of lines) {\n const match = line.match(/^(\\s+)\\S+/);\n if (match) {\n const indent = match[1].length;\n if (minIndent === null) {\n minIndent = indent;\n } else {\n minIndent = Math.min(minIndent, indent);\n }\n }\n }\n\n if (minIndent === null) {\n return text;\n }\n\n // Remove the common indentation from all lines\n return lines\n .map((line) =>\n line[0] === \" \" || line[0] === \"\\t\" ? line.slice(minIndent) : line\n )\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QACdA,SACA,GAAG,QACK;CACR,MAAM,MAAM,QAAQ;CACpB,IAAI,SAAS;AAEb,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EAEnC,MAAM,OAAO,IAAI,GACd,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,QAAQ,SAAS,IAAI,CACrB,QAAQ,SAAS,IAAI;EAExB,UAAU;AAEV,MAAI,IAAI,OAAO,QAAQ;GACrB,MAAM,QAAQ,WAAW,OAAO,IAAI,OAAO;GAC3C,UAAU,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;EACpE;CACF;CAGD,SAAS,YAAY,OAAO;CAG5B,SAAS,OAAO,MAAM;CAGtB,SAAS,OAAO,QAAQ,QAAQ,KAAK;AAErC,QAAO;AACR;;;;;;;;AASD,SAAS,WAAWC,OAAgBC,eAAgC;AAClE,KAAI,OAAO,UAAU,YAAY,CAAC,MAAM,SAAS,KAAK,CACpD,QAAO;CAGT,MAAM,cAAc,cAAc,MAAM,cAAc,YAAY,KAAK,GAAG,EAAE;CAC5E,MAAM,cAAc,YAAY,MAAM,SAAS;AAE/C,KAAI,aAAa;EACf,MAAM,SAAS,YAAY;AAC3B,SAAO,MAAM,QAAQ,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC;CAC3C;AAED,QAAO;AACR;;;;;;;AAQD,SAAS,YAAYC,MAAsB;CACzC,MAAM,QAAQ,KAAK,MAAM,KAAK;CAG9B,IAAIC,YAA2B;AAC/B,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,MAAM,YAAY;AACrC,MAAI,OAAO;GACT,MAAM,SAAS,MAAM,GAAG;AACxB,OAAI,cAAc,MAChB,YAAY;QAEZ,YAAY,KAAK,IAAI,WAAW,OAAO;EAE1C;CACF;AAED,KAAI,cAAc,KAChB,QAAO;AAIT,QAAO,MACJ,IAAI,CAAC,SACJ,KAAK,OAAO,OAAO,KAAK,OAAO,MAAO,KAAK,MAAM,UAAU,GAAG,KAC/D,CACA,KAAK,KAAK;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectorstores.d.cts","names":["EmbeddingsInterface","DocumentInterface","BaseRetriever","BaseRetrieverInterface","BaseRetrieverInput","Serializable","CallbackManagerForRetrieverRun","Callbacks","AddDocumentOptions","Record","MaxMarginalRelevanceSearchOptions","FilterType","VectorStoreRetrieverMMRSearchKwargs","VectorStoreRetrieverInput","V","VectorStoreInterface","VectorStoreRetrieverInterface","Promise","VectorStoreRetriever","Partial","VectorStore","SaveableVectorStore"],"sources":["../src/vectorstores.d.ts"],"sourcesContent":["import type { EmbeddingsInterface } from \"./embeddings.js\";\nimport type { DocumentInterface } from \"./documents/document.js\";\nimport { BaseRetriever, BaseRetrieverInterface, type BaseRetrieverInput } from \"./retrievers/index.js\";\nimport { Serializable } from \"./load/serializable.js\";\nimport { CallbackManagerForRetrieverRun, Callbacks } from \"./callbacks/manager.js\";\n/**\n * Type for options when adding a document to the VectorStore.\n */\ntype AddDocumentOptions = Record<string, any>;\n/**\n * Options for configuring a maximal marginal relevance (MMR) search.\n *\n * MMR search optimizes for both similarity to the query and diversity\n * among the results, balancing the retrieval of relevant documents\n * with variation in the content returned.\n *\n * Fields:\n *\n * - `fetchK` (optional): The initial number of documents to retrieve from the\n * vector store before applying the MMR algorithm. This larger set provides a\n * pool of documents from which the algorithm can select the most diverse\n * results based on relevance to the query.\n *\n * - `filter` (optional): A filter of type `FilterType` to refine the search\n * results, allowing additional conditions to target specific subsets\n * of documents.\n *\n * - `k`: The number of documents to return in the final results. This is the\n * primary count of documents that are most relevant to the query.\n *\n * - `lambda` (optional): A value between 0 and 1 that determines the balance\n * between relevance and diversity:\n * - A `lambda` of 0 emphasizes diversity, maximizing content variation.\n * - A `lambda` of 1 emphasizes similarity to the query, focusing on relevance.\n * Values between 0 and 1 provide a mix of relevance and diversity.\n *\n * @template FilterType - The type used for filtering results, as defined\n * by the vector store.\n */\nexport type MaxMarginalRelevanceSearchOptions<FilterType> = {\n k: number;\n fetchK?: number;\n lambda?: number;\n filter?: FilterType;\n};\n/**\n * Options for configuring a maximal marginal relevance (MMR) search\n * when using the `VectorStoreRetriever`.\n *\n * These parameters control how the MMR algorithm balances relevance to the\n * query and diversity among the retrieved documents.\n *\n * Fields:\n * - `fetchK` (optional): Specifies the initial number of documents to fetch\n * before applying the MMR algorithm. This larger set provides a pool of\n * documents from which the algorithm can select the most diverse results\n * based on relevance to the query.\n *\n * - `lambda` (optional): A value between 0 and 1 that determines the balance\n * between relevance and diversity:\n * - A `lambda` of 0 maximizes diversity among the results, prioritizing varied content.\n * - A `lambda` of 1 maximizes similarity to the query, prioritizing relevance.\n * Values between 0 and 1 provide a mix of relevance and diversity.\n */\nexport type VectorStoreRetrieverMMRSearchKwargs = {\n fetchK?: number;\n lambda?: number;\n};\n/**\n * Input configuration options for creating a `VectorStoreRetriever` instance.\n *\n * This type combines properties from `BaseRetrieverInput` with specific settings\n * for the `VectorStoreRetriever`, including options for similarity or maximal\n * marginal relevance (MMR) search types.\n *\n * Fields:\n *\n * - `callbacks` (optional): An array of callback functions that handle various\n * events during retrieval, such as logging, error handling, or progress updates.\n *\n * - `tags` (optional): An array of strings used to add contextual tags to\n * retrieval operations, allowing for easier categorization and tracking.\n *\n * - `metadata` (optional): A record of key-value pairs to store additional\n * contextual information for retrieval operations, which can be useful\n * for logging or auditing purposes.\n *\n * - `verbose` (optional): A boolean flag that, if set to `true`, enables\n * detailed logging and output during the retrieval process. Defaults to `false`.\n *\n * - `vectorStore`: The `VectorStore` instance implementing `VectorStoreInterface`\n * that will be used for document storage and retrieval.\n *\n * - `k` (optional): Specifies the number of documents to retrieve per search\n * query. Defaults to 4 if not specified.\n *\n * - `filter` (optional): A filter of type `FilterType` (defined by the vector store)\n * to refine the set of documents returned, allowing for targeted search results.\n *\n * - `searchType`: Determines the type of search to perform:\n * - `\"similarity\"`: Executes a similarity search, retrieving documents based purely\n * on vector similarity to the query.\n * - `\"mmr\"`: Executes a maximal marginal relevance (MMR) search, balancing similarity\n * and diversity in the search results.\n *\n * - `searchKwargs` (optional): Used only if `searchType` is `\"mmr\"`, this object\n * provides additional options for MMR search, including:\n * - `fetchK`: Specifies the number of documents to initially fetch before applying\n * the MMR algorithm, providing a pool from which the most diverse results are selected.\n * - `lambda`: A diversity parameter, where 0 emphasizes diversity and 1 emphasizes\n * relevance to the query. Values between 0 and 1 provide a balance of relevance and diversity.\n *\n * @template V - The type of vector store implementing `VectorStoreInterface`.\n */\nexport type VectorStoreRetrieverInput<V extends VectorStoreInterface> = BaseRetrieverInput & ({\n vectorStore: V;\n k?: number;\n filter?: V[\"FilterType\"];\n searchType?: \"similarity\";\n} | {\n vectorStore: V;\n k?: number;\n filter?: V[\"FilterType\"];\n searchType: \"mmr\";\n searchKwargs?: VectorStoreRetrieverMMRSearchKwargs;\n});\n/**\n * Interface for a retriever that uses a vector store to store and retrieve\n * document embeddings. This retriever interface allows for adding documents\n * to the underlying vector store and conducting retrieval operations.\n *\n * `VectorStoreRetrieverInterface` extends `BaseRetrieverInterface` to provide\n * document retrieval capabilities based on vector similarity.\n *\n * @interface VectorStoreRetrieverInterface\n * @extends BaseRetrieverInterface\n */\nexport interface VectorStoreRetrieverInterface<V extends VectorStoreInterface = VectorStoreInterface> extends BaseRetrieverInterface {\n vectorStore: V;\n /**\n * Adds an array of documents to the vector store.\n *\n * This method embeds the provided documents and stores them within the\n * vector store. Additional options can be specified for custom behavior\n * during the addition process.\n *\n * @param documents - An array of documents to embed and add to the vector store.\n * @param options - Optional settings to customize document addition.\n * @returns A promise that resolves to an array of document IDs or `void`,\n * depending on the implementation.\n */\n addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n}\n/**\n * Class for retrieving documents from a `VectorStore` based on vector similarity\n * or maximal marginal relevance (MMR).\n *\n * `VectorStoreRetriever` extends `BaseRetriever`, implementing methods for\n * adding documents to the underlying vector store and performing document\n * retrieval with optional configurations.\n *\n * @class VectorStoreRetriever\n * @extends BaseRetriever\n * @implements VectorStoreRetrieverInterface\n * @template V - Type of vector store implementing `VectorStoreInterface`.\n */\nexport declare class VectorStoreRetriever<V extends VectorStoreInterface = VectorStoreInterface> extends BaseRetriever implements VectorStoreRetrieverInterface {\n static lc_name(): string;\n get lc_namespace(): string[];\n /**\n * The instance of `VectorStore` used for storing and retrieving document embeddings.\n * This vector store must implement the `VectorStoreInterface` to be compatible\n * with the retriever’s operations.\n */\n vectorStore: V;\n /**\n * Specifies the number of documents to retrieve for each search query.\n * Defaults to 4 if not specified, providing a basic result count for similarity or MMR searches.\n */\n k: number;\n /**\n * Determines the type of search operation to perform on the vector store.\n *\n * - `\"similarity\"` (default): Conducts a similarity search based purely on vector similarity\n * to the query.\n * - `\"mmr\"`: Executes a maximal marginal relevance (MMR) search, balancing relevance and\n * diversity in the retrieved results.\n */\n searchType: string;\n /**\n * Additional options specific to maximal marginal relevance (MMR) search, applicable\n * only if `searchType` is set to `\"mmr\"`.\n *\n * Includes:\n * - `fetchK`: The initial number of documents fetched before applying the MMR algorithm,\n * allowing for a larger selection from which to choose the most diverse results.\n * - `lambda`: A parameter between 0 and 1 to adjust the relevance-diversity balance,\n * where 0 prioritizes diversity and 1 prioritizes relevance.\n */\n searchKwargs?: VectorStoreRetrieverMMRSearchKwargs;\n /**\n * Optional filter applied to search results, defined by the `FilterType` of the vector store.\n * Allows for refined, targeted results by restricting the returned documents based\n * on specified filter criteria.\n */\n filter?: V[\"FilterType\"];\n /**\n * Returns the type of vector store, as defined by the `vectorStore` instance.\n *\n * @returns {string} The vector store type.\n */\n _vectorstoreType(): string;\n /**\n * Initializes a new instance of `VectorStoreRetriever` with the specified configuration.\n *\n * This constructor configures the retriever to interact with a given `VectorStore`\n * and supports different retrieval strategies, including similarity search and maximal\n * marginal relevance (MMR) search. Various options allow customization of the number\n * of documents retrieved per query, filtering based on conditions, and fine-tuning\n * MMR-specific parameters.\n *\n * @param fields - Configuration options for setting up the retriever:\n *\n * - `vectorStore` (required): The `VectorStore` instance implementing `VectorStoreInterface`\n * that will be used to store and retrieve document embeddings. This is the core component\n * of the retriever, enabling vector-based similarity and MMR searches.\n *\n * - `k` (optional): Specifies the number of documents to retrieve per search query. If not\n * provided, defaults to 4. This count determines the number of most relevant documents returned\n * for each search operation, balancing performance with comprehensiveness.\n *\n * - `searchType` (optional): Defines the search approach used by the retriever, allowing for\n * flexibility between two methods:\n * - `\"similarity\"` (default): A similarity-based search, retrieving documents with high vector\n * similarity to the query. This type prioritizes relevance and is often used when diversity\n * among results is less critical.\n * - `\"mmr\"`: Maximal Marginal Relevance search, which combines relevance with diversity. MMR\n * is useful for scenarios where varied content is essential, as it selects results that\n * both match the query and introduce content diversity.\n *\n * - `filter` (optional): A filter of type `FilterType`, defined by the vector store, that allows\n * for refined and targeted search results. This filter applies specified conditions to limit\n * which documents are eligible for retrieval, offering control over the scope of results.\n *\n * - `searchKwargs` (optional, applicable only if `searchType` is `\"mmr\"`): Additional settings\n * for configuring MMR-specific behavior. These parameters allow further tuning of the MMR\n * search process:\n * - `fetchK`: The initial number of documents fetched from the vector store before the MMR\n * algorithm is applied. Fetching a larger set enables the algorithm to select a more\n * diverse subset of documents.\n * - `lambda`: A parameter controlling the relevance-diversity balance, where 0 emphasizes\n * diversity and 1 prioritizes relevance. Intermediate values provide a blend of the two,\n * allowing customization based on the importance of content variety relative to query relevance.\n */\n constructor(fields: VectorStoreRetrieverInput<V>);\n /**\n * Retrieves relevant documents based on the specified query, using either\n * similarity or maximal marginal relevance (MMR) search.\n *\n * If `searchType` is set to `\"mmr\"`, performs an MMR search to balance\n * similarity and diversity among results. If `searchType` is `\"similarity\"`,\n * retrieves results purely based on similarity to the query.\n *\n * @param query - The query string used to find relevant documents.\n * @param runManager - Optional callback manager for tracking retrieval progress.\n * @returns A promise that resolves to an array of `DocumentInterface` instances\n * representing the most relevant documents to the query.\n * @throws {Error} Throws an error if MMR search is requested but not supported\n * by the vector store.\n * @protected\n */\n _getRelevantDocuments(query: string, runManager?: CallbackManagerForRetrieverRun): Promise<DocumentInterface[]>;\n /**\n * Adds an array of documents to the vector store, embedding them as part of\n * the storage process.\n *\n * This method delegates document embedding and storage to the `addDocuments`\n * method of the underlying vector store.\n *\n * @param documents - An array of documents to embed and add to the vector store.\n * @param options - Optional settings to customize document addition.\n * @returns A promise that resolves to an array of document IDs or `void`,\n * depending on the vector store's implementation.\n */\n addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n}\n/**\n * Interface defining the structure and operations of a vector store, which\n * facilitates the storage, retrieval, and similarity search of document vectors.\n *\n * `VectorStoreInterface` provides methods for adding, deleting, and searching\n * documents based on vector embeddings, including support for similarity\n * search with optional filtering and relevance-based retrieval.\n *\n * @extends Serializable\n */\nexport interface VectorStoreInterface extends Serializable {\n /**\n * Defines the filter type used in search and delete operations. Can be an\n * object for structured conditions or a string for simpler filtering.\n */\n FilterType: object | string;\n /**\n * Instance of `EmbeddingsInterface` used to generate vector embeddings for\n * documents, enabling vector-based search operations.\n */\n embeddings: EmbeddingsInterface;\n /**\n * Returns a string identifying the type of vector store implementation,\n * useful for distinguishing between different vector storage backends.\n *\n * @returns {string} A string indicating the vector store type.\n */\n _vectorstoreType(): string;\n /**\n * Adds precomputed vectors and their corresponding documents to the vector store.\n *\n * @param vectors - An array of vectors, with each vector representing a document.\n * @param documents - An array of `DocumentInterface` instances corresponding to each vector.\n * @param options - Optional configurations for adding documents, potentially covering indexing or metadata handling.\n * @returns A promise that resolves to an array of document IDs or void, depending on implementation.\n */\n addVectors(vectors: number[][], documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Adds an array of documents to the vector store.\n *\n * @param documents - An array of documents to be embedded and stored in the vector store.\n * @param options - Optional configurations for embedding and storage operations.\n * @returns A promise that resolves to an array of document IDs or void, depending on implementation.\n */\n addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Deletes documents from the vector store based on the specified parameters.\n *\n * @param _params - A flexible object containing key-value pairs that define\n * the conditions for selecting documents to delete.\n * @returns A promise that resolves once the deletion operation is complete.\n */\n delete(_params?: Record<string, any>): Promise<void>;\n /**\n * Searches for documents similar to a given vector query and returns them\n * with similarity scores.\n *\n * @param query - A vector representing the query for similarity search.\n * @param k - The number of similar documents to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @returns A promise that resolves to an array of tuples, each containing a\n * `DocumentInterface` and its corresponding similarity score.\n */\n similaritySearchVectorWithScore(query: number[], k: number, filter?: this[\"FilterType\"]): Promise<[DocumentInterface, number][]>;\n /**\n * Searches for documents similar to a text query, embedding the query\n * and retrieving documents based on vector similarity.\n *\n * @param query - The text query to search for.\n * @param k - Optional number of similar documents to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @param callbacks - Optional callbacks for tracking progress or events\n * during the search process.\n * @returns A promise that resolves to an array of `DocumentInterface`\n * instances representing similar documents.\n */\n similaritySearch(query: string, k?: number, filter?: this[\"FilterType\"], callbacks?: Callbacks): Promise<DocumentInterface[]>;\n /**\n * Searches for documents similar to a text query and includes similarity\n * scores in the result.\n *\n * @param query - The text query to search for.\n * @param k - Optional number of similar documents to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @param callbacks - Optional callbacks for tracking progress or events\n * during the search process.\n * @returns A promise that resolves to an array of tuples, each containing\n * a `DocumentInterface` and its similarity score.\n */\n similaritySearchWithScore(query: string, k?: number, filter?: this[\"FilterType\"], callbacks?: Callbacks): Promise<[DocumentInterface, number][]>;\n /**\n * Return documents selected using the maximal marginal relevance.\n * Maximal marginal relevance optimizes for similarity to the query AND diversity\n * among selected documents.\n *\n * @param {string} query - Text to look up documents similar to.\n * @param {number} options.k - Number of documents to return.\n * @param {number} options.fetchK - Number of documents to fetch before passing to the MMR algorithm.\n * @param {number} options.lambda - Number between 0 and 1 that determines the degree of diversity among the results,\n * where 0 corresponds to maximum diversity and 1 to minimum diversity.\n * @param {this[\"FilterType\"]} options.filter - Optional filter\n * @param _callbacks\n *\n * @returns {Promise<DocumentInterface[]>} - List of documents selected by maximal marginal relevance.\n */\n maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<this[\"FilterType\"]>, callbacks: Callbacks | undefined): Promise<DocumentInterface[]>;\n /**\n * Converts the vector store into a retriever, making it suitable for use in\n * retrieval-based workflows and allowing additional configuration.\n *\n * @param kOrFields - Optional parameter for specifying either the number of\n * documents to retrieve or partial retriever configurations.\n * @param filter - Optional filter based on `FilterType` for retrieval restriction.\n * @param callbacks - Optional callbacks for tracking retrieval events or progress.\n * @param tags - General-purpose tags to add contextual information to the retriever.\n * @param metadata - General-purpose metadata providing additional context\n * for retrieval.\n * @param verbose - If `true`, enables detailed logging during retrieval.\n * @returns An instance of `VectorStoreRetriever` configured with the specified options.\n */\n asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<this>>, filter?: this[\"FilterType\"], callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<this>;\n}\n/**\n * Abstract class representing a vector storage system for performing\n * similarity searches on embedded documents.\n *\n * `VectorStore` provides methods for adding precomputed vectors or documents,\n * removing documents based on criteria, and performing similarity searches\n * with optional scoring. Subclasses are responsible for implementing specific\n * storage mechanisms and the exact behavior of certain abstract methods.\n *\n * @abstract\n * @extends Serializable\n * @implements VectorStoreInterface\n */\nexport declare abstract class VectorStore extends Serializable implements VectorStoreInterface {\n FilterType: object | string;\n /**\n * Namespace within LangChain to uniquely identify this vector store's\n * location, based on the vector store type.\n *\n * @internal\n */\n lc_namespace: string[];\n /**\n * Embeddings interface for generating vector embeddings from text queries,\n * enabling vector-based similarity searches.\n */\n embeddings: EmbeddingsInterface;\n /**\n * Initializes a new vector store with embeddings and database configuration.\n *\n * @param embeddings - Instance of `EmbeddingsInterface` used to embed queries.\n * @param dbConfig - Configuration settings for the database or storage system.\n */\n constructor(embeddings: EmbeddingsInterface, dbConfig: Record<string, any>);\n /**\n * Returns a string representing the type of vector store, which subclasses\n * must implement to identify their specific vector storage type.\n *\n * @returns {string} A string indicating the vector store type.\n * @abstract\n */\n abstract _vectorstoreType(): string;\n /**\n * Adds precomputed vectors and corresponding documents to the vector store.\n *\n * @param vectors - An array of vectors representing each document.\n * @param documents - Array of documents associated with each vector.\n * @param options - Optional configuration for adding vectors, such as indexing.\n * @returns A promise resolving to an array of document IDs or void, based on implementation.\n * @abstract\n */\n abstract addVectors(vectors: number[][], documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Adds documents to the vector store, embedding them first through the\n * `embeddings` instance.\n *\n * @param documents - Array of documents to embed and add.\n * @param options - Optional configuration for embedding and storing documents.\n * @returns A promise resolving to an array of document IDs or void, based on implementation.\n * @abstract\n */\n abstract addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Deletes documents from the vector store based on the specified parameters.\n *\n * @param _params - Flexible key-value pairs defining conditions for document deletion.\n * @returns A promise that resolves once the deletion is complete.\n */\n delete(_params?: Record<string, any>): Promise<void>;\n /**\n * Performs a similarity search using a vector query and returns results\n * along with their similarity scores.\n *\n * @param query - Vector representing the search query.\n * @param k - Number of similar results to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @returns A promise resolving to an array of tuples containing documents and their similarity scores.\n * @abstract\n */\n abstract similaritySearchVectorWithScore(query: number[], k: number, filter?: this[\"FilterType\"]): Promise<[DocumentInterface, number][]>;\n /**\n * Searches for documents similar to a text query by embedding the query and\n * performing a similarity search on the resulting vector.\n *\n * @param query - Text query for finding similar documents.\n * @param k - Number of similar results to return. Defaults to 4.\n * @param filter - Optional filter based on `FilterType`.\n * @param _callbacks - Optional callbacks for monitoring search progress\n * @returns A promise resolving to an array of `DocumentInterface` instances representing similar documents.\n */\n similaritySearch(query: string, k?: number, filter?: this[\"FilterType\"] | undefined, _callbacks?: Callbacks | undefined): Promise<DocumentInterface[]>;\n /**\n * Searches for documents similar to a text query by embedding the query,\n * and returns results with similarity scores.\n *\n * @param query - Text query for finding similar documents.\n * @param k - Number of similar results to return. Defaults to 4.\n * @param filter - Optional filter based on `FilterType`.\n * @param _callbacks - Optional callbacks for monitoring search progress\n * @returns A promise resolving to an array of tuples, each containing a\n * document and its similarity score.\n */\n similaritySearchWithScore(query: string, k?: number, filter?: this[\"FilterType\"] | undefined, _callbacks?: Callbacks | undefined): Promise<[DocumentInterface, number][]>;\n /**\n * Return documents selected using the maximal marginal relevance.\n * Maximal marginal relevance optimizes for similarity to the query AND diversity\n * among selected documents.\n *\n * @param {string} query - Text to look up documents similar to.\n * @param {number} options.k - Number of documents to return.\n * @param {number} options.fetchK - Number of documents to fetch before passing to the MMR algorithm.\n * @param {number} options.lambda - Number between 0 and 1 that determines the degree of diversity among the results,\n * where 0 corresponds to maximum diversity and 1 to minimum diversity.\n * @param {this[\"FilterType\"]} options.filter - Optional filter\n * @param _callbacks\n *\n * @returns {Promise<DocumentInterface[]>} - List of documents selected by maximal marginal relevance.\n */\n maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<this[\"FilterType\"]>, _callbacks: Callbacks | undefined): Promise<DocumentInterface[]>;\n /**\n * Creates a `VectorStore` instance from an array of text strings and optional\n * metadata, using the specified embeddings and database configuration.\n *\n * Subclasses must implement this method to define how text and metadata\n * are embedded and stored in the vector store. Throws an error if not overridden.\n *\n * @param _texts - Array of strings representing the text documents to be stored.\n * @param _metadatas - Metadata for the texts, either as an array (one for each text)\n * or a single object (applied to all texts).\n * @param _embeddings - Instance of `EmbeddingsInterface` to embed the texts.\n * @param _dbConfig - Database configuration settings.\n * @returns A promise that resolves to a new `VectorStore` instance.\n * @throws {Error} Throws an error if this method is not overridden by a subclass.\n */\n static fromTexts(_texts: string[], _metadatas: object[] | object, _embeddings: EmbeddingsInterface, _dbConfig: Record<string, any>): Promise<VectorStore>;\n /**\n * Creates a `VectorStore` instance from an array of documents, using the specified\n * embeddings and database configuration.\n *\n * Subclasses must implement this method to define how documents are embedded\n * and stored. Throws an error if not overridden.\n *\n * @param _docs - Array of `DocumentInterface` instances representing the documents to be stored.\n * @param _embeddings - Instance of `EmbeddingsInterface` to embed the documents.\n * @param _dbConfig - Database configuration settings.\n * @returns A promise that resolves to a new `VectorStore` instance.\n * @throws {Error} Throws an error if this method is not overridden by a subclass.\n */\n static fromDocuments(_docs: DocumentInterface[], _embeddings: EmbeddingsInterface, _dbConfig: Record<string, any>): Promise<VectorStore>;\n /**\n * Creates a `VectorStoreRetriever` instance with flexible configuration options.\n *\n * @param kOrFields\n * - If a number is provided, it sets the `k` parameter (number of items to retrieve).\n * - If an object is provided, it should contain various configuration options.\n * @param filter\n * - Optional filter criteria to limit the items retrieved based on the specified filter type.\n * @param callbacks\n * - Optional callbacks that may be triggered at specific stages of the retrieval process.\n * @param tags\n * - Tags to categorize or label the `VectorStoreRetriever`. Defaults to an empty array if not provided.\n * @param metadata\n * - Additional metadata as key-value pairs to add contextual information for the retrieval process.\n * @param verbose\n * - If `true`, enables detailed logging for the retrieval process. Defaults to `false`.\n *\n * @returns\n * - A configured `VectorStoreRetriever` instance based on the provided parameters.\n *\n * @example\n * Basic usage with a `k` value:\n * ```typescript\n * const retriever = myVectorStore.asRetriever(5);\n * ```\n *\n * Usage with a configuration object:\n * ```typescript\n * const retriever = myVectorStore.asRetriever({\n * k: 10,\n * filter: myFilter,\n * tags: ['example', 'test'],\n * verbose: true,\n * searchType: 'mmr',\n * searchKwargs: { alpha: 0.5 },\n * });\n * ```\n */\n asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<this>>, filter?: this[\"FilterType\"], callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<this>;\n}\n/**\n * Abstract class extending `VectorStore` that defines a contract for saving\n * and loading vector store instances.\n *\n * The `SaveableVectorStore` class allows vector store implementations to\n * persist their data and retrieve it when needed.The format for saving and\n * loading data is left to the implementing subclass.\n *\n * Subclasses must implement the `save` method to handle their custom\n * serialization logic, while the `load` method enables reconstruction of a\n * vector store from saved data, requiring compatible embeddings through the\n * `EmbeddingsInterface`.\n *\n * @abstract\n * @extends VectorStore\n */\nexport declare abstract class SaveableVectorStore extends VectorStore {\n /**\n * Saves the current state of the vector store to the specified directory.\n *\n * This method must be implemented by subclasses to define their own\n * serialization process for persisting vector data. The implementation\n * determines the structure and format of the saved data.\n *\n * @param directory - The directory path where the vector store data\n * will be saved.\n * @abstract\n */\n abstract save(directory: string): Promise<void>;\n /**\n * Loads a vector store instance from the specified directory, using the\n * provided embeddings to ensure compatibility.\n *\n * This static method reconstructs a `SaveableVectorStore` from previously\n * saved data. Implementations should interpret the saved data format to\n * recreate the vector store instance.\n *\n * @param _directory - The directory path from which the vector store\n * data will be loaded.\n * @param _embeddings - An instance of `EmbeddingsInterface` to align\n * the embeddings with the loaded vector data.\n * @returns A promise that resolves to a `SaveableVectorStore` instance\n * constructed from the saved data.\n */\n static load(_directory: string, _embeddings: EmbeddingsInterface): Promise<SaveableVectorStore>;\n}\nexport {};\n//# sourceMappingURL=vectorstores.d.ts.map"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"vectorstores.d.cts","names":["EmbeddingsInterface","DocumentInterface","BaseRetriever","BaseRetrieverInterface","BaseRetrieverInput","Serializable","CallbackManagerForRetrieverRun","Callbacks","AddDocumentOptions","Record","MaxMarginalRelevanceSearchOptions","FilterType","VectorStoreRetrieverMMRSearchKwargs","VectorStoreRetrieverInput","V","VectorStoreInterface","VectorStoreRetrieverInterface","Promise","VectorStoreRetriever","Partial","VectorStore","SaveableVectorStore"],"sources":["../src/vectorstores.d.ts"],"sourcesContent":["import type { EmbeddingsInterface } from \"./embeddings.js\";\nimport type { DocumentInterface } from \"./documents/document.js\";\nimport { BaseRetriever, BaseRetrieverInterface, type BaseRetrieverInput } from \"./retrievers/index.js\";\nimport { Serializable } from \"./load/serializable.js\";\nimport { CallbackManagerForRetrieverRun, Callbacks } from \"./callbacks/manager.js\";\n/**\n * Type for options when adding a document to the VectorStore.\n */\ntype AddDocumentOptions = Record<string, any>;\n/**\n * Options for configuring a maximal marginal relevance (MMR) search.\n *\n * MMR search optimizes for both similarity to the query and diversity\n * among the results, balancing the retrieval of relevant documents\n * with variation in the content returned.\n *\n * Fields:\n *\n * - `fetchK` (optional): The initial number of documents to retrieve from the\n * vector store before applying the MMR algorithm. This larger set provides a\n * pool of documents from which the algorithm can select the most diverse\n * results based on relevance to the query.\n *\n * - `filter` (optional): A filter of type `FilterType` to refine the search\n * results, allowing additional conditions to target specific subsets\n * of documents.\n *\n * - `k`: The number of documents to return in the final results. This is the\n * primary count of documents that are most relevant to the query.\n *\n * - `lambda` (optional): A value between 0 and 1 that determines the balance\n * between relevance and diversity:\n * - A `lambda` of 0 emphasizes diversity, maximizing content variation.\n * - A `lambda` of 1 emphasizes similarity to the query, focusing on relevance.\n * Values between 0 and 1 provide a mix of relevance and diversity.\n *\n * @template FilterType - The type used for filtering results, as defined\n * by the vector store.\n */\nexport type MaxMarginalRelevanceSearchOptions<FilterType> = {\n k: number;\n fetchK?: number;\n lambda?: number;\n filter?: FilterType;\n};\n/**\n * Options for configuring a maximal marginal relevance (MMR) search\n * when using the `VectorStoreRetriever`.\n *\n * These parameters control how the MMR algorithm balances relevance to the\n * query and diversity among the retrieved documents.\n *\n * Fields:\n * - `fetchK` (optional): Specifies the initial number of documents to fetch\n * before applying the MMR algorithm. This larger set provides a pool of\n * documents from which the algorithm can select the most diverse results\n * based on relevance to the query.\n *\n * - `lambda` (optional): A value between 0 and 1 that determines the balance\n * between relevance and diversity:\n * - A `lambda` of 0 maximizes diversity among the results, prioritizing varied content.\n * - A `lambda` of 1 maximizes similarity to the query, prioritizing relevance.\n * Values between 0 and 1 provide a mix of relevance and diversity.\n */\nexport type VectorStoreRetrieverMMRSearchKwargs = {\n fetchK?: number;\n lambda?: number;\n};\n/**\n * Input configuration options for creating a `VectorStoreRetriever` instance.\n *\n * This type combines properties from `BaseRetrieverInput` with specific settings\n * for the `VectorStoreRetriever`, including options for similarity or maximal\n * marginal relevance (MMR) search types.\n *\n * Fields:\n *\n * - `callbacks` (optional): An array of callback functions that handle various\n * events during retrieval, such as logging, error handling, or progress updates.\n *\n * - `tags` (optional): An array of strings used to add contextual tags to\n * retrieval operations, allowing for easier categorization and tracking.\n *\n * - `metadata` (optional): A record of key-value pairs to store additional\n * contextual information for retrieval operations, which can be useful\n * for logging or auditing purposes.\n *\n * - `verbose` (optional): A boolean flag that, if set to `true`, enables\n * detailed logging and output during the retrieval process. Defaults to `false`.\n *\n * - `vectorStore`: The `VectorStore` instance implementing `VectorStoreInterface`\n * that will be used for document storage and retrieval.\n *\n * - `k` (optional): Specifies the number of documents to retrieve per search\n * query. Defaults to 4 if not specified.\n *\n * - `filter` (optional): A filter of type `FilterType` (defined by the vector store)\n * to refine the set of documents returned, allowing for targeted search results.\n *\n * - `searchType`: Determines the type of search to perform:\n * - `\"similarity\"`: Executes a similarity search, retrieving documents based purely\n * on vector similarity to the query.\n * - `\"mmr\"`: Executes a maximal marginal relevance (MMR) search, balancing similarity\n * and diversity in the search results.\n *\n * - `searchKwargs` (optional): Used only if `searchType` is `\"mmr\"`, this object\n * provides additional options for MMR search, including:\n * - `fetchK`: Specifies the number of documents to initially fetch before applying\n * the MMR algorithm, providing a pool from which the most diverse results are selected.\n * - `lambda`: A diversity parameter, where 0 emphasizes diversity and 1 emphasizes\n * relevance to the query. Values between 0 and 1 provide a balance of relevance and diversity.\n *\n * @template V - The type of vector store implementing `VectorStoreInterface`.\n */\nexport type VectorStoreRetrieverInput<V extends VectorStoreInterface> = BaseRetrieverInput & ({\n vectorStore: V;\n k?: number;\n filter?: V[\"FilterType\"];\n searchType?: \"similarity\";\n} | {\n vectorStore: V;\n k?: number;\n filter?: V[\"FilterType\"];\n searchType: \"mmr\";\n searchKwargs?: VectorStoreRetrieverMMRSearchKwargs;\n});\n/**\n * Interface for a retriever that uses a vector store to store and retrieve\n * document embeddings. This retriever interface allows for adding documents\n * to the underlying vector store and conducting retrieval operations.\n *\n * `VectorStoreRetrieverInterface` extends `BaseRetrieverInterface` to provide\n * document retrieval capabilities based on vector similarity.\n *\n * @interface VectorStoreRetrieverInterface\n * @extends BaseRetrieverInterface\n */\nexport interface VectorStoreRetrieverInterface<V extends VectorStoreInterface = VectorStoreInterface> extends BaseRetrieverInterface {\n vectorStore: V;\n /**\n * Adds an array of documents to the vector store.\n *\n * This method embeds the provided documents and stores them within the\n * vector store. Additional options can be specified for custom behavior\n * during the addition process.\n *\n * @param documents - An array of documents to embed and add to the vector store.\n * @param options - Optional settings to customize document addition.\n * @returns A promise that resolves to an array of document IDs or `void`,\n * depending on the implementation.\n */\n addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n}\n/**\n * Class for retrieving documents from a `VectorStore` based on vector similarity\n * or maximal marginal relevance (MMR).\n *\n * `VectorStoreRetriever` extends `BaseRetriever`, implementing methods for\n * adding documents to the underlying vector store and performing document\n * retrieval with optional configurations.\n *\n * @class VectorStoreRetriever\n * @extends BaseRetriever\n * @implements VectorStoreRetrieverInterface\n * @template V - Type of vector store implementing `VectorStoreInterface`.\n */\nexport declare class VectorStoreRetriever<V extends VectorStoreInterface = VectorStoreInterface> extends BaseRetriever implements VectorStoreRetrieverInterface {\n static lc_name(): string;\n get lc_namespace(): string[];\n /**\n * The instance of `VectorStore` used for storing and retrieving document embeddings.\n * This vector store must implement the `VectorStoreInterface` to be compatible\n * with the retriever’s operations.\n */\n vectorStore: V;\n /**\n * Specifies the number of documents to retrieve for each search query.\n * Defaults to 4 if not specified, providing a basic result count for similarity or MMR searches.\n */\n k: number;\n /**\n * Determines the type of search operation to perform on the vector store.\n *\n * - `\"similarity\"` (default): Conducts a similarity search based purely on vector similarity\n * to the query.\n * - `\"mmr\"`: Executes a maximal marginal relevance (MMR) search, balancing relevance and\n * diversity in the retrieved results.\n */\n searchType: string;\n /**\n * Additional options specific to maximal marginal relevance (MMR) search, applicable\n * only if `searchType` is set to `\"mmr\"`.\n *\n * Includes:\n * - `fetchK`: The initial number of documents fetched before applying the MMR algorithm,\n * allowing for a larger selection from which to choose the most diverse results.\n * - `lambda`: A parameter between 0 and 1 to adjust the relevance-diversity balance,\n * where 0 prioritizes diversity and 1 prioritizes relevance.\n */\n searchKwargs?: VectorStoreRetrieverMMRSearchKwargs;\n /**\n * Optional filter applied to search results, defined by the `FilterType` of the vector store.\n * Allows for refined, targeted results by restricting the returned documents based\n * on specified filter criteria.\n */\n filter?: V[\"FilterType\"];\n /**\n * Returns the type of vector store, as defined by the `vectorStore` instance.\n *\n * @returns {string} The vector store type.\n */\n _vectorstoreType(): string;\n /**\n * Initializes a new instance of `VectorStoreRetriever` with the specified configuration.\n *\n * This constructor configures the retriever to interact with a given `VectorStore`\n * and supports different retrieval strategies, including similarity search and maximal\n * marginal relevance (MMR) search. Various options allow customization of the number\n * of documents retrieved per query, filtering based on conditions, and fine-tuning\n * MMR-specific parameters.\n *\n * @param fields - Configuration options for setting up the retriever:\n *\n * - `vectorStore` (required): The `VectorStore` instance implementing `VectorStoreInterface`\n * that will be used to store and retrieve document embeddings. This is the core component\n * of the retriever, enabling vector-based similarity and MMR searches.\n *\n * - `k` (optional): Specifies the number of documents to retrieve per search query. If not\n * provided, defaults to 4. This count determines the number of most relevant documents returned\n * for each search operation, balancing performance with comprehensiveness.\n *\n * - `searchType` (optional): Defines the search approach used by the retriever, allowing for\n * flexibility between two methods:\n * - `\"similarity\"` (default): A similarity-based search, retrieving documents with high vector\n * similarity to the query. This type prioritizes relevance and is often used when diversity\n * among results is less critical.\n * - `\"mmr\"`: Maximal Marginal Relevance search, which combines relevance with diversity. MMR\n * is useful for scenarios where varied content is essential, as it selects results that\n * both match the query and introduce content diversity.\n *\n * - `filter` (optional): A filter of type `FilterType`, defined by the vector store, that allows\n * for refined and targeted search results. This filter applies specified conditions to limit\n * which documents are eligible for retrieval, offering control over the scope of results.\n *\n * - `searchKwargs` (optional, applicable only if `searchType` is `\"mmr\"`): Additional settings\n * for configuring MMR-specific behavior. These parameters allow further tuning of the MMR\n * search process:\n * - `fetchK`: The initial number of documents fetched from the vector store before the MMR\n * algorithm is applied. Fetching a larger set enables the algorithm to select a more\n * diverse subset of documents.\n * - `lambda`: A parameter controlling the relevance-diversity balance, where 0 emphasizes\n * diversity and 1 prioritizes relevance. Intermediate values provide a blend of the two,\n * allowing customization based on the importance of content variety relative to query relevance.\n */\n constructor(fields: VectorStoreRetrieverInput<V>);\n /**\n * Retrieves relevant documents based on the specified query, using either\n * similarity or maximal marginal relevance (MMR) search.\n *\n * If `searchType` is set to `\"mmr\"`, performs an MMR search to balance\n * similarity and diversity among results. If `searchType` is `\"similarity\"`,\n * retrieves results purely based on similarity to the query.\n *\n * @param query - The query string used to find relevant documents.\n * @param runManager - Optional callback manager for tracking retrieval progress.\n * @returns A promise that resolves to an array of `DocumentInterface` instances\n * representing the most relevant documents to the query.\n * @throws {Error} Throws an error if MMR search is requested but not supported\n * by the vector store.\n * @protected\n */\n _getRelevantDocuments(query: string, runManager?: CallbackManagerForRetrieverRun): Promise<DocumentInterface[]>;\n /**\n * Adds an array of documents to the vector store, embedding them as part of\n * the storage process.\n *\n * This method delegates document embedding and storage to the `addDocuments`\n * method of the underlying vector store.\n *\n * @param documents - An array of documents to embed and add to the vector store.\n * @param options - Optional settings to customize document addition.\n * @returns A promise that resolves to an array of document IDs or `void`,\n * depending on the vector store's implementation.\n */\n addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n}\n/**\n * Interface defining the structure and operations of a vector store, which\n * facilitates the storage, retrieval, and similarity search of document vectors.\n *\n * `VectorStoreInterface` provides methods for adding, deleting, and searching\n * documents based on vector embeddings, including support for similarity\n * search with optional filtering and relevance-based retrieval.\n *\n * @extends Serializable\n */\nexport interface VectorStoreInterface extends Serializable {\n /**\n * Defines the filter type used in search and delete operations. Can be an\n * object for structured conditions or a string for simpler filtering.\n */\n FilterType: object | string;\n /**\n * Instance of `EmbeddingsInterface` used to generate vector embeddings for\n * documents, enabling vector-based search operations.\n */\n embeddings: EmbeddingsInterface;\n /**\n * Returns a string identifying the type of vector store implementation,\n * useful for distinguishing between different vector storage backends.\n *\n * @returns {string} A string indicating the vector store type.\n */\n _vectorstoreType(): string;\n /**\n * Adds precomputed vectors and their corresponding documents to the vector store.\n *\n * @param vectors - An array of vectors, with each vector representing a document.\n * @param documents - An array of `DocumentInterface` instances corresponding to each vector.\n * @param options - Optional configurations for adding documents, potentially covering indexing or metadata handling.\n * @returns A promise that resolves to an array of document IDs or void, depending on implementation.\n */\n addVectors(vectors: number[][], documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Adds an array of documents to the vector store.\n *\n * @param documents - An array of documents to be embedded and stored in the vector store.\n * @param options - Optional configurations for embedding and storage operations.\n * @returns A promise that resolves to an array of document IDs or void, depending on implementation.\n */\n addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Deletes documents from the vector store based on the specified parameters.\n *\n * @param _params - A flexible object containing key-value pairs that define\n * the conditions for selecting documents to delete.\n * @returns A promise that resolves once the deletion operation is complete.\n */\n delete(_params?: Record<string, any>): Promise<void>;\n /**\n * Searches for documents similar to a given vector query and returns them\n * with similarity scores.\n *\n * @param query - A vector representing the query for similarity search.\n * @param k - The number of similar documents to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @returns A promise that resolves to an array of tuples, each containing a\n * `DocumentInterface` and its corresponding similarity score.\n */\n similaritySearchVectorWithScore(query: number[], k: number, filter?: this[\"FilterType\"]): Promise<[DocumentInterface, number][]>;\n /**\n * Searches for documents similar to a text query, embedding the query\n * and retrieving documents based on vector similarity.\n *\n * @param query - The text query to search for.\n * @param k - Optional number of similar documents to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @param callbacks - Optional callbacks for tracking progress or events\n * during the search process.\n * @returns A promise that resolves to an array of `DocumentInterface`\n * instances representing similar documents.\n */\n similaritySearch(query: string, k?: number, filter?: this[\"FilterType\"], callbacks?: Callbacks): Promise<DocumentInterface[]>;\n /**\n * Searches for documents similar to a text query and includes similarity\n * scores in the result.\n *\n * @param query - The text query to search for.\n * @param k - Optional number of similar documents to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @param callbacks - Optional callbacks for tracking progress or events\n * during the search process.\n * @returns A promise that resolves to an array of tuples, each containing\n * a `DocumentInterface` and its similarity score.\n */\n similaritySearchWithScore(query: string, k?: number, filter?: this[\"FilterType\"], callbacks?: Callbacks): Promise<[DocumentInterface, number][]>;\n /**\n * Return documents selected using the maximal marginal relevance.\n * Maximal marginal relevance optimizes for similarity to the query AND diversity\n * among selected documents.\n *\n * @param {string} query - Text to look up documents similar to.\n * @param {number} options.k - Number of documents to return.\n * @param {number} options.fetchK - Number of documents to fetch before passing to the MMR algorithm.\n * @param {number} options.lambda - Number between 0 and 1 that determines the degree of diversity among the results,\n * where 0 corresponds to maximum diversity and 1 to minimum diversity.\n * @param {this[\"FilterType\"]} options.filter - Optional filter\n * @param _callbacks\n *\n * @returns {Promise<DocumentInterface[]>} - List of documents selected by maximal marginal relevance.\n */\n maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<this[\"FilterType\"]>, callbacks: Callbacks | undefined): Promise<DocumentInterface[]>;\n /**\n * Converts the vector store into a retriever, making it suitable for use in\n * retrieval-based workflows and allowing additional configuration.\n *\n * @param kOrFields - Optional parameter for specifying either the number of\n * documents to retrieve or partial retriever configurations.\n * @param filter - Optional filter based on `FilterType` for retrieval restriction.\n * @param callbacks - Optional callbacks for tracking retrieval events or progress.\n * @param tags - General-purpose tags to add contextual information to the retriever.\n * @param metadata - General-purpose metadata providing additional context\n * for retrieval.\n * @param verbose - If `true`, enables detailed logging during retrieval.\n * @returns An instance of `VectorStoreRetriever` configured with the specified options.\n */\n asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<this>>, filter?: this[\"FilterType\"], callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<this>;\n}\n/**\n * Abstract class representing a vector storage system for performing\n * similarity searches on embedded documents.\n *\n * `VectorStore` provides methods for adding precomputed vectors or documents,\n * removing documents based on criteria, and performing similarity searches\n * with optional scoring. Subclasses are responsible for implementing specific\n * storage mechanisms and the exact behavior of certain abstract methods.\n *\n * @abstract\n * @extends Serializable\n * @implements VectorStoreInterface\n */\nexport declare abstract class VectorStore extends Serializable implements VectorStoreInterface {\n FilterType: object | string;\n /**\n * Namespace within LangChain to uniquely identify this vector store's\n * location, based on the vector store type.\n *\n * @internal\n */\n lc_namespace: string[];\n /**\n * Embeddings interface for generating vector embeddings from text queries,\n * enabling vector-based similarity searches.\n */\n embeddings: EmbeddingsInterface;\n /**\n * Initializes a new vector store with embeddings and database configuration.\n *\n * @param embeddings - Instance of `EmbeddingsInterface` used to embed queries.\n * @param dbConfig - Configuration settings for the database or storage system.\n */\n constructor(embeddings: EmbeddingsInterface, dbConfig: Record<string, any>);\n /**\n * Returns a string representing the type of vector store, which subclasses\n * must implement to identify their specific vector storage type.\n *\n * @returns {string} A string indicating the vector store type.\n * @abstract\n */\n abstract _vectorstoreType(): string;\n /**\n * Adds precomputed vectors and corresponding documents to the vector store.\n *\n * @param vectors - An array of vectors representing each document.\n * @param documents - Array of documents associated with each vector.\n * @param options - Optional configuration for adding vectors, such as indexing.\n * @returns A promise resolving to an array of document IDs or void, based on implementation.\n * @abstract\n */\n abstract addVectors(vectors: number[][], documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Adds documents to the vector store, embedding them first through the\n * `embeddings` instance.\n *\n * @param documents - Array of documents to embed and add.\n * @param options - Optional configuration for embedding and storing documents.\n * @returns A promise resolving to an array of document IDs or void, based on implementation.\n * @abstract\n */\n abstract addDocuments(documents: DocumentInterface[], options?: AddDocumentOptions): Promise<string[] | void>;\n /**\n * Deletes documents from the vector store based on the specified parameters.\n *\n * @param _params - Flexible key-value pairs defining conditions for document deletion.\n * @returns A promise that resolves once the deletion is complete.\n */\n delete(_params?: Record<string, any>): Promise<void>;\n /**\n * Performs a similarity search using a vector query and returns results\n * along with their similarity scores.\n *\n * @param query - Vector representing the search query.\n * @param k - Number of similar results to return.\n * @param filter - Optional filter based on `FilterType` to restrict results.\n * @returns A promise resolving to an array of tuples containing documents and their similarity scores.\n * @abstract\n */\n abstract similaritySearchVectorWithScore(query: number[], k: number, filter?: this[\"FilterType\"]): Promise<[DocumentInterface, number][]>;\n /**\n * Searches for documents similar to a text query by embedding the query and\n * performing a similarity search on the resulting vector.\n *\n * @param query - Text query for finding similar documents.\n * @param k - Number of similar results to return. Defaults to 4.\n * @param filter - Optional filter based on `FilterType`.\n * @param _callbacks - Optional callbacks for monitoring search progress\n * @returns A promise resolving to an array of `DocumentInterface` instances representing similar documents.\n */\n similaritySearch(query: string, k?: number, filter?: this[\"FilterType\"] | undefined, _callbacks?: Callbacks | undefined): Promise<DocumentInterface[]>;\n /**\n * Searches for documents similar to a text query by embedding the query,\n * and returns results with similarity scores.\n *\n * @param query - Text query for finding similar documents.\n * @param k - Number of similar results to return. Defaults to 4.\n * @param filter - Optional filter based on `FilterType`.\n * @param _callbacks - Optional callbacks for monitoring search progress\n * @returns A promise resolving to an array of tuples, each containing a\n * document and its similarity score.\n */\n similaritySearchWithScore(query: string, k?: number, filter?: this[\"FilterType\"] | undefined, _callbacks?: Callbacks | undefined): Promise<[DocumentInterface, number][]>;\n /**\n * Return documents selected using the maximal marginal relevance.\n * Maximal marginal relevance optimizes for similarity to the query AND diversity\n * among selected documents.\n *\n * @param {string} query - Text to look up documents similar to.\n * @param {number} options.k - Number of documents to return.\n * @param {number} options.fetchK - Number of documents to fetch before passing to the MMR algorithm.\n * @param {number} options.lambda - Number between 0 and 1 that determines the degree of diversity among the results,\n * where 0 corresponds to maximum diversity and 1 to minimum diversity.\n * @param {this[\"FilterType\"]} options.filter - Optional filter\n * @param _callbacks\n *\n * @returns {Promise<DocumentInterface[]>} - List of documents selected by maximal marginal relevance.\n */\n maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<this[\"FilterType\"]>, _callbacks: Callbacks | undefined): Promise<DocumentInterface[]>;\n /**\n * Creates a `VectorStore` instance from an array of text strings and optional\n * metadata, using the specified embeddings and database configuration.\n *\n * Subclasses must implement this method to define how text and metadata\n * are embedded and stored in the vector store. Throws an error if not overridden.\n *\n * @param _texts - Array of strings representing the text documents to be stored.\n * @param _metadatas - Metadata for the texts, either as an array (one for each text)\n * or a single object (applied to all texts).\n * @param _embeddings - Instance of `EmbeddingsInterface` to embed the texts.\n * @param _dbConfig - Database configuration settings.\n * @returns A promise that resolves to a new `VectorStore` instance.\n * @throws {Error} Throws an error if this method is not overridden by a subclass.\n */\n static fromTexts(_texts: string[], _metadatas: object[] | object, _embeddings: EmbeddingsInterface, _dbConfig: Record<string, any>): Promise<VectorStore>;\n /**\n * Creates a `VectorStore` instance from an array of documents, using the specified\n * embeddings and database configuration.\n *\n * Subclasses must implement this method to define how documents are embedded\n * and stored. Throws an error if not overridden.\n *\n * @param _docs - Array of `DocumentInterface` instances representing the documents to be stored.\n * @param _embeddings - Instance of `EmbeddingsInterface` to embed the documents.\n * @param _dbConfig - Database configuration settings.\n * @returns A promise that resolves to a new `VectorStore` instance.\n * @throws {Error} Throws an error if this method is not overridden by a subclass.\n */\n static fromDocuments(_docs: DocumentInterface[], _embeddings: EmbeddingsInterface, _dbConfig: Record<string, any>): Promise<VectorStore>;\n /**\n * Creates a `VectorStoreRetriever` instance with flexible configuration options.\n *\n * @param kOrFields\n * - If a number is provided, it sets the `k` parameter (number of items to retrieve).\n * - If an object is provided, it should contain various configuration options.\n * @param filter\n * - Optional filter criteria to limit the items retrieved based on the specified filter type.\n * @param callbacks\n * - Optional callbacks that may be triggered at specific stages of the retrieval process.\n * @param tags\n * - Tags to categorize or label the `VectorStoreRetriever`. Defaults to an empty array if not provided.\n * @param metadata\n * - Additional metadata as key-value pairs to add contextual information for the retrieval process.\n * @param verbose\n * - If `true`, enables detailed logging for the retrieval process. Defaults to `false`.\n *\n * @returns\n * - A configured `VectorStoreRetriever` instance based on the provided parameters.\n *\n * @example\n * Basic usage with a `k` value:\n * ```typescript\n * const retriever = myVectorStore.asRetriever(5);\n * ```\n *\n * Usage with a configuration object:\n * ```typescript\n * const retriever = myVectorStore.asRetriever({\n * k: 10,\n * filter: myFilter,\n * tags: ['example', 'test'],\n * verbose: true,\n * searchType: 'mmr',\n * searchKwargs: { alpha: 0.5 },\n * });\n * ```\n */\n asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<this>>, filter?: this[\"FilterType\"], callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<this>;\n}\n/**\n * Abstract class extending `VectorStore` that defines a contract for saving\n * and loading vector store instances.\n *\n * The `SaveableVectorStore` class allows vector store implementations to\n * persist their data and retrieve it when needed.The format for saving and\n * loading data is left to the implementing subclass.\n *\n * Subclasses must implement the `save` method to handle their custom\n * serialization logic, while the `load` method enables reconstruction of a\n * vector store from saved data, requiring compatible embeddings through the\n * `EmbeddingsInterface`.\n *\n * @abstract\n * @extends VectorStore\n */\nexport declare abstract class SaveableVectorStore extends VectorStore {\n /**\n * Saves the current state of the vector store to the specified directory.\n *\n * This method must be implemented by subclasses to define their own\n * serialization process for persisting vector data. The implementation\n * determines the structure and format of the saved data.\n *\n * @param directory - The directory path where the vector store data\n * will be saved.\n * @abstract\n */\n abstract save(directory: string): Promise<void>;\n /**\n * Loads a vector store instance from the specified directory, using the\n * provided embeddings to ensure compatibility.\n *\n * This static method reconstructs a `SaveableVectorStore` from previously\n * saved data. Implementations should interpret the saved data format to\n * recreate the vector store instance.\n *\n * @param _directory - The directory path from which the vector store\n * data will be loaded.\n * @param _embeddings - An instance of `EmbeddingsInterface` to align\n * the embeddings with the loaded vector data.\n * @returns A promise that resolves to a `SaveableVectorStore` instance\n * constructed from the saved data.\n */\n static load(_directory: string, _embeddings: EmbeddingsInterface): Promise<SaveableVectorStore>;\n}\nexport {};\n//# sourceMappingURL=vectorstores.d.ts.map"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"camelcase": "6",
|
|
22
22
|
"decamelize": "1.2.0",
|
|
23
23
|
"js-tiktoken": "^1.0.12",
|
|
24
|
-
"langsmith": "
|
|
24
|
+
"langsmith": ">=0.4.0 <1.0.0",
|
|
25
25
|
"mustache": "^4.2.0",
|
|
26
26
|
"p-queue": "^6.6.2",
|
|
27
27
|
"uuid": "^10.0.0",
|
|
@@ -578,6 +578,17 @@
|
|
|
578
578
|
"default": "./dist/utils/chunk_array.js"
|
|
579
579
|
}
|
|
580
580
|
},
|
|
581
|
+
"./utils/context": {
|
|
582
|
+
"input": "./src/utils/context.ts",
|
|
583
|
+
"require": {
|
|
584
|
+
"types": "./dist/utils/context.d.cts",
|
|
585
|
+
"default": "./dist/utils/context.cjs"
|
|
586
|
+
},
|
|
587
|
+
"import": {
|
|
588
|
+
"types": "./dist/utils/context.d.ts",
|
|
589
|
+
"default": "./dist/utils/context.js"
|
|
590
|
+
}
|
|
591
|
+
},
|
|
581
592
|
"./utils/env": {
|
|
582
593
|
"input": "./src/utils/env.ts",
|
|
583
594
|
"require": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("../dist/utils/context.cjs");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/utils/context.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/utils/context.js";
|
package/utils/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/utils/context.js";
|