langchain 0.0.171 → 0.0.172
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/agents/format_scratchpad/log.cjs +1 -0
- package/agents/format_scratchpad/log.d.ts +1 -0
- package/agents/format_scratchpad/log.js +1 -0
- package/agents/format_scratchpad/log_to_message.cjs +1 -0
- package/agents/format_scratchpad/log_to_message.d.ts +1 -0
- package/agents/format_scratchpad/log_to_message.js +1 -0
- package/agents/format_scratchpad/xml.cjs +1 -0
- package/agents/format_scratchpad/xml.d.ts +1 -0
- package/agents/format_scratchpad/xml.js +1 -0
- package/agents/format_scratchpad.cjs +1 -1
- package/agents/format_scratchpad.d.ts +1 -1
- package/agents/format_scratchpad.js +1 -1
- package/agents/react/output_parser.cjs +1 -0
- package/agents/react/output_parser.d.ts +1 -0
- package/agents/react/output_parser.js +1 -0
- package/dist/agents/format_scratchpad/log.cjs +16 -0
- package/dist/agents/format_scratchpad/log.d.ts +9 -0
- package/dist/agents/format_scratchpad/log.js +12 -0
- package/dist/agents/format_scratchpad/log_to_message.cjs +22 -0
- package/dist/agents/format_scratchpad/log_to_message.d.ts +2 -0
- package/dist/agents/format_scratchpad/log_to_message.js +18 -0
- package/dist/agents/{format_scratchpad.cjs → format_scratchpad/openai_functions.cjs} +3 -3
- package/dist/agents/{format_scratchpad.d.ts → format_scratchpad/openai_functions.d.ts} +1 -1
- package/dist/agents/{format_scratchpad.js → format_scratchpad/openai_functions.js} +3 -3
- package/dist/agents/format_scratchpad/xml.cjs +12 -0
- package/dist/agents/format_scratchpad/xml.d.ts +2 -0
- package/dist/agents/format_scratchpad/xml.js +8 -0
- package/dist/agents/react/output_parser.cjs +96 -0
- package/dist/agents/react/output_parser.d.ts +47 -0
- package/dist/agents/react/output_parser.js +92 -0
- package/dist/agents/react/prompt.cjs +13 -0
- package/dist/agents/react/prompt.d.ts +1 -0
- package/dist/agents/react/prompt.js +10 -0
- package/dist/embeddings/openai.cjs +11 -0
- package/dist/embeddings/openai.d.ts +2 -0
- package/dist/embeddings/openai.js +11 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +8 -3
- package/dist/load/import_map.d.ts +6 -1
- package/dist/load/import_map.js +6 -1
- package/dist/storage/file_system.cjs +147 -0
- package/dist/storage/file_system.d.ts +60 -0
- package/dist/storage/file_system.js +140 -0
- package/dist/tools/render.cjs +18 -0
- package/dist/tools/render.d.ts +13 -0
- package/dist/tools/render.js +14 -0
- package/dist/vectorstores/analyticdb.cjs +7 -3
- package/dist/vectorstores/analyticdb.d.ts +1 -1
- package/dist/vectorstores/analyticdb.js +7 -3
- package/dist/vectorstores/qdrant.cjs +19 -11
- package/dist/vectorstores/qdrant.d.ts +1 -1
- package/dist/vectorstores/qdrant.js +19 -11
- package/dist/vectorstores/redis.cjs +4 -1
- package/dist/vectorstores/redis.d.ts +1 -1
- package/dist/vectorstores/redis.js +4 -1
- package/package.json +49 -1
- package/storage/file_system.cjs +1 -0
- package/storage/file_system.d.ts +1 -0
- package/storage/file_system.js +1 -0
- package/tools/render.cjs +1 -0
- package/tools/render.d.ts +1 -0
- package/tools/render.js +1 -0
package/dist/load/import_map.js
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
export * as load__serializable from "../load/serializable.js";
|
|
3
3
|
export * as agents from "../agents/index.js";
|
|
4
4
|
export * as agents__toolkits from "../agents/toolkits/index.js";
|
|
5
|
-
export * as agents__format_scratchpad from "../agents/format_scratchpad.js";
|
|
5
|
+
export * as agents__format_scratchpad from "../agents/format_scratchpad/openai_functions.js";
|
|
6
|
+
export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log.js";
|
|
7
|
+
export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
|
|
8
|
+
export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
|
|
9
|
+
export * as agents__react__output_parser from "../agents/react/output_parser.js";
|
|
6
10
|
export * as base_language from "../base_language/index.js";
|
|
7
11
|
export * as tools from "../tools/index.js";
|
|
12
|
+
export * as tools__render from "../tools/render.js";
|
|
8
13
|
export * as chains from "../chains/index.js";
|
|
9
14
|
export * as chains__openai_functions from "../chains/openai_functions/index.js";
|
|
10
15
|
export * as embeddings__base from "../embeddings/base.js";
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LocalFileStore = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const storage_js_1 = require("../schema/storage.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* File system implementation of the BaseStore using a dictionary. Used for
|
|
12
|
+
* storing key-value pairs in the file system.
|
|
13
|
+
*/
|
|
14
|
+
class LocalFileStore extends storage_js_1.BaseStore {
|
|
15
|
+
constructor(fields) {
|
|
16
|
+
super(fields);
|
|
17
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: ["langchain", "storage"]
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "rootPath", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this.rootPath = fields.rootPath;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read and parse the file at the given path.
|
|
33
|
+
* @param key The key to read the file for.
|
|
34
|
+
* @returns Promise that resolves to the parsed file content.
|
|
35
|
+
*/
|
|
36
|
+
async getParsedFile(key) {
|
|
37
|
+
try {
|
|
38
|
+
const fileContent = await fs_1.promises.readFile(this.getFullPath(key));
|
|
39
|
+
if (!fileContent) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return fileContent;
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
// File does not exist yet.
|
|
47
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
48
|
+
if ("code" in e && e.code === "ENOENT") {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Error reading and parsing file at path: ${this.rootPath}.\nError: ${JSON.stringify(e)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Writes the given key-value pairs to the file at the given path.
|
|
56
|
+
* @param fileContent An object with the key-value pairs to be written to the file.
|
|
57
|
+
*/
|
|
58
|
+
async setFileContent(content, key) {
|
|
59
|
+
try {
|
|
60
|
+
await fs_1.promises.writeFile(this.getFullPath(key), content);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the full path of the file where the value of the given key is stored.
|
|
68
|
+
* @param key the key to get the full path for
|
|
69
|
+
*/
|
|
70
|
+
getFullPath(key) {
|
|
71
|
+
try {
|
|
72
|
+
const keyAsTxtFile = `${key}.txt`;
|
|
73
|
+
const fullPath = path_1.default.join(this.rootPath, keyAsTxtFile);
|
|
74
|
+
return fullPath;
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
throw new Error(`Error getting full path for key: ${key}.\nError: ${JSON.stringify(e)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the values associated with the given keys from the store.
|
|
82
|
+
* @param keys Keys to retrieve values for.
|
|
83
|
+
* @returns Array of values associated with the given keys.
|
|
84
|
+
*/
|
|
85
|
+
async mget(keys) {
|
|
86
|
+
const values = [];
|
|
87
|
+
for (const key of keys) {
|
|
88
|
+
const fileContent = await this.getParsedFile(key);
|
|
89
|
+
values.push(fileContent);
|
|
90
|
+
}
|
|
91
|
+
return values;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sets the values for the given keys in the store.
|
|
95
|
+
* @param keyValuePairs Array of key-value pairs to set in the store.
|
|
96
|
+
* @returns Promise that resolves when all key-value pairs have been set.
|
|
97
|
+
*/
|
|
98
|
+
async mset(keyValuePairs) {
|
|
99
|
+
await Promise.all(keyValuePairs.map(([key, value]) => this.setFileContent(value, key)));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Deletes the given keys and their associated values from the store.
|
|
103
|
+
* @param keys Keys to delete from the store.
|
|
104
|
+
* @returns Promise that resolves when all keys have been deleted.
|
|
105
|
+
*/
|
|
106
|
+
async mdelete(keys) {
|
|
107
|
+
await Promise.all(keys.map((key) => fs_1.promises.unlink(this.getFullPath(key))));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
111
|
+
* provided, it only yields keys that start with the prefix.
|
|
112
|
+
* @param prefix Optional prefix to filter keys.
|
|
113
|
+
* @returns AsyncGenerator that yields keys from the store.
|
|
114
|
+
*/
|
|
115
|
+
async *yieldKeys(prefix) {
|
|
116
|
+
const allFiles = await fs_1.promises.readdir(this.rootPath);
|
|
117
|
+
const allKeys = allFiles.map((file) => file.replace(".txt", ""));
|
|
118
|
+
for (const key of allKeys) {
|
|
119
|
+
if (prefix === undefined || key.startsWith(prefix)) {
|
|
120
|
+
yield key;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Static method for initializing the class.
|
|
126
|
+
* Preforms a check to see if the directory exists, and if not, creates it.
|
|
127
|
+
* @param path Path to the directory.
|
|
128
|
+
* @returns Promise that resolves to an instance of the class.
|
|
129
|
+
*/
|
|
130
|
+
static async fromPath(rootPath) {
|
|
131
|
+
try {
|
|
132
|
+
// Verifies the directory exists at the provided path, and that it is readable and writable.
|
|
133
|
+
await fs_1.promises.access(rootPath, fs_1.promises.constants.R_OK | fs_1.promises.constants.W_OK);
|
|
134
|
+
}
|
|
135
|
+
catch (_) {
|
|
136
|
+
try {
|
|
137
|
+
// Directory does not exist, create it.
|
|
138
|
+
await fs_1.promises.mkdir(rootPath, { recursive: true });
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return new this({ rootPath });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.LocalFileStore = LocalFileStore;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseStore } from "../schema/storage.js";
|
|
2
|
+
/**
|
|
3
|
+
* File system implementation of the BaseStore using a dictionary. Used for
|
|
4
|
+
* storing key-value pairs in the file system.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LocalFileStore extends BaseStore<string, Uint8Array> {
|
|
7
|
+
lc_namespace: string[];
|
|
8
|
+
rootPath: string;
|
|
9
|
+
constructor(fields: {
|
|
10
|
+
rootPath: string;
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Read and parse the file at the given path.
|
|
14
|
+
* @param key The key to read the file for.
|
|
15
|
+
* @returns Promise that resolves to the parsed file content.
|
|
16
|
+
*/
|
|
17
|
+
private getParsedFile;
|
|
18
|
+
/**
|
|
19
|
+
* Writes the given key-value pairs to the file at the given path.
|
|
20
|
+
* @param fileContent An object with the key-value pairs to be written to the file.
|
|
21
|
+
*/
|
|
22
|
+
private setFileContent;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the full path of the file where the value of the given key is stored.
|
|
25
|
+
* @param key the key to get the full path for
|
|
26
|
+
*/
|
|
27
|
+
private getFullPath;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the values associated with the given keys from the store.
|
|
30
|
+
* @param keys Keys to retrieve values for.
|
|
31
|
+
* @returns Array of values associated with the given keys.
|
|
32
|
+
*/
|
|
33
|
+
mget(keys: string[]): Promise<(Uint8Array | undefined)[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the values for the given keys in the store.
|
|
36
|
+
* @param keyValuePairs Array of key-value pairs to set in the store.
|
|
37
|
+
* @returns Promise that resolves when all key-value pairs have been set.
|
|
38
|
+
*/
|
|
39
|
+
mset(keyValuePairs: [string, Uint8Array][]): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Deletes the given keys and their associated values from the store.
|
|
42
|
+
* @param keys Keys to delete from the store.
|
|
43
|
+
* @returns Promise that resolves when all keys have been deleted.
|
|
44
|
+
*/
|
|
45
|
+
mdelete(keys: string[]): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
48
|
+
* provided, it only yields keys that start with the prefix.
|
|
49
|
+
* @param prefix Optional prefix to filter keys.
|
|
50
|
+
* @returns AsyncGenerator that yields keys from the store.
|
|
51
|
+
*/
|
|
52
|
+
yieldKeys(prefix?: string): AsyncGenerator<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Static method for initializing the class.
|
|
55
|
+
* Preforms a check to see if the directory exists, and if not, creates it.
|
|
56
|
+
* @param path Path to the directory.
|
|
57
|
+
* @returns Promise that resolves to an instance of the class.
|
|
58
|
+
*/
|
|
59
|
+
static fromPath(rootPath: string): Promise<LocalFileStore>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { promises as fsPromises } from "fs";
|
|
2
|
+
import nodePath from "path";
|
|
3
|
+
import { BaseStore } from "../schema/storage.js";
|
|
4
|
+
/**
|
|
5
|
+
* File system implementation of the BaseStore using a dictionary. Used for
|
|
6
|
+
* storing key-value pairs in the file system.
|
|
7
|
+
*/
|
|
8
|
+
export class LocalFileStore extends BaseStore {
|
|
9
|
+
constructor(fields) {
|
|
10
|
+
super(fields);
|
|
11
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: ["langchain", "storage"]
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "rootPath", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
this.rootPath = fields.rootPath;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read and parse the file at the given path.
|
|
27
|
+
* @param key The key to read the file for.
|
|
28
|
+
* @returns Promise that resolves to the parsed file content.
|
|
29
|
+
*/
|
|
30
|
+
async getParsedFile(key) {
|
|
31
|
+
try {
|
|
32
|
+
const fileContent = await fsPromises.readFile(this.getFullPath(key));
|
|
33
|
+
if (!fileContent) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return fileContent;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
// File does not exist yet.
|
|
41
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
42
|
+
if ("code" in e && e.code === "ENOENT") {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Error reading and parsing file at path: ${this.rootPath}.\nError: ${JSON.stringify(e)}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Writes the given key-value pairs to the file at the given path.
|
|
50
|
+
* @param fileContent An object with the key-value pairs to be written to the file.
|
|
51
|
+
*/
|
|
52
|
+
async setFileContent(content, key) {
|
|
53
|
+
try {
|
|
54
|
+
await fsPromises.writeFile(this.getFullPath(key), content);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the full path of the file where the value of the given key is stored.
|
|
62
|
+
* @param key the key to get the full path for
|
|
63
|
+
*/
|
|
64
|
+
getFullPath(key) {
|
|
65
|
+
try {
|
|
66
|
+
const keyAsTxtFile = `${key}.txt`;
|
|
67
|
+
const fullPath = nodePath.join(this.rootPath, keyAsTxtFile);
|
|
68
|
+
return fullPath;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw new Error(`Error getting full path for key: ${key}.\nError: ${JSON.stringify(e)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves the values associated with the given keys from the store.
|
|
76
|
+
* @param keys Keys to retrieve values for.
|
|
77
|
+
* @returns Array of values associated with the given keys.
|
|
78
|
+
*/
|
|
79
|
+
async mget(keys) {
|
|
80
|
+
const values = [];
|
|
81
|
+
for (const key of keys) {
|
|
82
|
+
const fileContent = await this.getParsedFile(key);
|
|
83
|
+
values.push(fileContent);
|
|
84
|
+
}
|
|
85
|
+
return values;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sets the values for the given keys in the store.
|
|
89
|
+
* @param keyValuePairs Array of key-value pairs to set in the store.
|
|
90
|
+
* @returns Promise that resolves when all key-value pairs have been set.
|
|
91
|
+
*/
|
|
92
|
+
async mset(keyValuePairs) {
|
|
93
|
+
await Promise.all(keyValuePairs.map(([key, value]) => this.setFileContent(value, key)));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Deletes the given keys and their associated values from the store.
|
|
97
|
+
* @param keys Keys to delete from the store.
|
|
98
|
+
* @returns Promise that resolves when all keys have been deleted.
|
|
99
|
+
*/
|
|
100
|
+
async mdelete(keys) {
|
|
101
|
+
await Promise.all(keys.map((key) => fsPromises.unlink(this.getFullPath(key))));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
105
|
+
* provided, it only yields keys that start with the prefix.
|
|
106
|
+
* @param prefix Optional prefix to filter keys.
|
|
107
|
+
* @returns AsyncGenerator that yields keys from the store.
|
|
108
|
+
*/
|
|
109
|
+
async *yieldKeys(prefix) {
|
|
110
|
+
const allFiles = await fsPromises.readdir(this.rootPath);
|
|
111
|
+
const allKeys = allFiles.map((file) => file.replace(".txt", ""));
|
|
112
|
+
for (const key of allKeys) {
|
|
113
|
+
if (prefix === undefined || key.startsWith(prefix)) {
|
|
114
|
+
yield key;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Static method for initializing the class.
|
|
120
|
+
* Preforms a check to see if the directory exists, and if not, creates it.
|
|
121
|
+
* @param path Path to the directory.
|
|
122
|
+
* @returns Promise that resolves to an instance of the class.
|
|
123
|
+
*/
|
|
124
|
+
static async fromPath(rootPath) {
|
|
125
|
+
try {
|
|
126
|
+
// Verifies the directory exists at the provided path, and that it is readable and writable.
|
|
127
|
+
await fsPromises.access(rootPath, fsPromises.constants.R_OK | fsPromises.constants.W_OK);
|
|
128
|
+
}
|
|
129
|
+
catch (_) {
|
|
130
|
+
try {
|
|
131
|
+
// Directory does not exist, create it.
|
|
132
|
+
await fsPromises.mkdir(rootPath, { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return new this({ rootPath });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderTextDescription = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Render the tool name and description in plain text.
|
|
6
|
+
*
|
|
7
|
+
* Output will be in the format of:
|
|
8
|
+
* ```
|
|
9
|
+
* search: This tool is used for search
|
|
10
|
+
* calculator: This tool is used for math
|
|
11
|
+
* ```
|
|
12
|
+
* @param tools
|
|
13
|
+
* @returns a string of all tools and their descriptions
|
|
14
|
+
*/
|
|
15
|
+
function renderTextDescription(tools) {
|
|
16
|
+
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
|
|
17
|
+
}
|
|
18
|
+
exports.renderTextDescription = renderTextDescription;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StructuredTool } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Render the tool name and description in plain text.
|
|
4
|
+
*
|
|
5
|
+
* Output will be in the format of:
|
|
6
|
+
* ```
|
|
7
|
+
* search: This tool is used for search
|
|
8
|
+
* calculator: This tool is used for math
|
|
9
|
+
* ```
|
|
10
|
+
* @param tools
|
|
11
|
+
* @returns a string of all tools and their descriptions
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderTextDescription(tools: StructuredTool[]): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render the tool name and description in plain text.
|
|
3
|
+
*
|
|
4
|
+
* Output will be in the format of:
|
|
5
|
+
* ```
|
|
6
|
+
* search: This tool is used for search
|
|
7
|
+
* calculator: This tool is used for math
|
|
8
|
+
* ```
|
|
9
|
+
* @param tools
|
|
10
|
+
* @returns a string of all tools and their descriptions
|
|
11
|
+
*/
|
|
12
|
+
export function renderTextDescription(tools) {
|
|
13
|
+
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
|
|
14
|
+
}
|
|
@@ -34,7 +34,6 @@ const promises_1 = require("node:stream/promises");
|
|
|
34
34
|
const node_stream_1 = require("node:stream");
|
|
35
35
|
const base_js_1 = require("./base.cjs");
|
|
36
36
|
const document_js_1 = require("../document.cjs");
|
|
37
|
-
const _LANGCHAIN_DEFAULT_EMBEDDING_DIM = 1536;
|
|
38
37
|
const _LANGCHAIN_DEFAULT_COLLECTION_NAME = "langchain_document";
|
|
39
38
|
/**
|
|
40
39
|
* Class that provides methods for creating and managing a collection of
|
|
@@ -85,8 +84,7 @@ class AnalyticDBVectorStore extends base_js_1.VectorStore {
|
|
|
85
84
|
user: args.connectionOptions.user,
|
|
86
85
|
password: args.connectionOptions.password,
|
|
87
86
|
});
|
|
88
|
-
this.embeddingDimension =
|
|
89
|
-
args.embeddingDimension || _LANGCHAIN_DEFAULT_EMBEDDING_DIM;
|
|
87
|
+
this.embeddingDimension = args.embeddingDimension;
|
|
90
88
|
this.collectionName =
|
|
91
89
|
args.collectionName || _LANGCHAIN_DEFAULT_COLLECTION_NAME;
|
|
92
90
|
this.preDeleteCollection = args.preDeleteCollection || false;
|
|
@@ -106,6 +104,9 @@ class AnalyticDBVectorStore extends base_js_1.VectorStore {
|
|
|
106
104
|
* @returns Promise that resolves when the table and index are created.
|
|
107
105
|
*/
|
|
108
106
|
async createTableIfNotExists() {
|
|
107
|
+
if (!this.embeddingDimension) {
|
|
108
|
+
this.embeddingDimension = (await this.embeddings.embedQuery("test")).length;
|
|
109
|
+
}
|
|
109
110
|
const client = await this.pool.connect();
|
|
110
111
|
try {
|
|
111
112
|
await client.query("BEGIN");
|
|
@@ -194,6 +195,9 @@ class AnalyticDBVectorStore extends base_js_1.VectorStore {
|
|
|
194
195
|
if (vectors.length !== documents.length) {
|
|
195
196
|
throw new Error(`Vectors and documents must have the same length`);
|
|
196
197
|
}
|
|
198
|
+
if (!this.embeddingDimension) {
|
|
199
|
+
this.embeddingDimension = (await this.embeddings.embedQuery("test")).length;
|
|
200
|
+
}
|
|
197
201
|
if (vectors[0].length !== this.embeddingDimension) {
|
|
198
202
|
throw new Error(`Vectors must have the same length as the number of dimensions (${this.embeddingDimension})`);
|
|
199
203
|
}
|
|
@@ -21,7 +21,7 @@ export interface AnalyticDBArgs {
|
|
|
21
21
|
export declare class AnalyticDBVectorStore extends VectorStore {
|
|
22
22
|
FilterType: Record<string, any>;
|
|
23
23
|
private pool;
|
|
24
|
-
private embeddingDimension
|
|
24
|
+
private embeddingDimension?;
|
|
25
25
|
private collectionName;
|
|
26
26
|
private preDeleteCollection;
|
|
27
27
|
private isCreateCollection;
|
|
@@ -5,7 +5,6 @@ import { pipeline } from "node:stream/promises";
|
|
|
5
5
|
import { Readable } from "node:stream";
|
|
6
6
|
import { VectorStore } from "./base.js";
|
|
7
7
|
import { Document } from "../document.js";
|
|
8
|
-
const _LANGCHAIN_DEFAULT_EMBEDDING_DIM = 1536;
|
|
9
8
|
const _LANGCHAIN_DEFAULT_COLLECTION_NAME = "langchain_document";
|
|
10
9
|
/**
|
|
11
10
|
* Class that provides methods for creating and managing a collection of
|
|
@@ -56,8 +55,7 @@ export class AnalyticDBVectorStore extends VectorStore {
|
|
|
56
55
|
user: args.connectionOptions.user,
|
|
57
56
|
password: args.connectionOptions.password,
|
|
58
57
|
});
|
|
59
|
-
this.embeddingDimension =
|
|
60
|
-
args.embeddingDimension || _LANGCHAIN_DEFAULT_EMBEDDING_DIM;
|
|
58
|
+
this.embeddingDimension = args.embeddingDimension;
|
|
61
59
|
this.collectionName =
|
|
62
60
|
args.collectionName || _LANGCHAIN_DEFAULT_COLLECTION_NAME;
|
|
63
61
|
this.preDeleteCollection = args.preDeleteCollection || false;
|
|
@@ -77,6 +75,9 @@ export class AnalyticDBVectorStore extends VectorStore {
|
|
|
77
75
|
* @returns Promise that resolves when the table and index are created.
|
|
78
76
|
*/
|
|
79
77
|
async createTableIfNotExists() {
|
|
78
|
+
if (!this.embeddingDimension) {
|
|
79
|
+
this.embeddingDimension = (await this.embeddings.embedQuery("test")).length;
|
|
80
|
+
}
|
|
80
81
|
const client = await this.pool.connect();
|
|
81
82
|
try {
|
|
82
83
|
await client.query("BEGIN");
|
|
@@ -165,6 +166,9 @@ export class AnalyticDBVectorStore extends VectorStore {
|
|
|
165
166
|
if (vectors.length !== documents.length) {
|
|
166
167
|
throw new Error(`Vectors and documents must have the same length`);
|
|
167
168
|
}
|
|
169
|
+
if (!this.embeddingDimension) {
|
|
170
|
+
this.embeddingDimension = (await this.embeddings.embedQuery("test")).length;
|
|
171
|
+
}
|
|
168
172
|
if (vectors[0].length !== this.embeddingDimension) {
|
|
169
173
|
throw new Error(`Vectors must have the same length as the number of dimensions (${this.embeddingDimension})`);
|
|
170
174
|
}
|
|
@@ -54,12 +54,7 @@ class QdrantVectorStore extends base_js_1.VectorStore {
|
|
|
54
54
|
apiKey,
|
|
55
55
|
});
|
|
56
56
|
this.collectionName = args.collectionName ?? "documents";
|
|
57
|
-
this.collectionConfig = args.collectionConfig
|
|
58
|
-
vectors: {
|
|
59
|
-
size: 1536,
|
|
60
|
-
distance: "Cosine",
|
|
61
|
-
},
|
|
62
|
-
};
|
|
57
|
+
this.collectionConfig = args.collectionConfig;
|
|
63
58
|
}
|
|
64
59
|
/**
|
|
65
60
|
* Method to add documents to the Qdrant database. It generates vectors
|
|
@@ -93,10 +88,17 @@ class QdrantVectorStore extends base_js_1.VectorStore {
|
|
|
93
88
|
metadata: documents[idx].metadata,
|
|
94
89
|
},
|
|
95
90
|
}));
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
try {
|
|
92
|
+
await this.client.upsert(this.collectionName, {
|
|
93
|
+
wait: true,
|
|
94
|
+
points,
|
|
95
|
+
});
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
const error = new Error(`${e?.status ?? "Undefined error code"} ${e?.message}: ${e?.data?.status?.error}`);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
100
102
|
}
|
|
101
103
|
/**
|
|
102
104
|
* Method to search for vectors in the Qdrant database that are similar to
|
|
@@ -135,7 +137,13 @@ class QdrantVectorStore extends base_js_1.VectorStore {
|
|
|
135
137
|
const response = await this.client.getCollections();
|
|
136
138
|
const collectionNames = response.collections.map((collection) => collection.name);
|
|
137
139
|
if (!collectionNames.includes(this.collectionName)) {
|
|
138
|
-
|
|
140
|
+
const collectionConfig = this.collectionConfig ?? {
|
|
141
|
+
vectors: {
|
|
142
|
+
size: (await this.embeddings.embedQuery("test")).length,
|
|
143
|
+
distance: "Cosine",
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
await this.client.createCollection(this.collectionName, collectionConfig);
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
/**
|
|
@@ -28,7 +28,7 @@ export declare class QdrantVectorStore extends VectorStore {
|
|
|
28
28
|
};
|
|
29
29
|
client: QdrantClient;
|
|
30
30
|
collectionName: string;
|
|
31
|
-
collectionConfig
|
|
31
|
+
collectionConfig?: QdrantSchemas["CreateCollection"];
|
|
32
32
|
_vectorstoreType(): string;
|
|
33
33
|
constructor(embeddings: Embeddings, args: QdrantLibArgs);
|
|
34
34
|
/**
|
|
@@ -51,12 +51,7 @@ export class QdrantVectorStore extends VectorStore {
|
|
|
51
51
|
apiKey,
|
|
52
52
|
});
|
|
53
53
|
this.collectionName = args.collectionName ?? "documents";
|
|
54
|
-
this.collectionConfig = args.collectionConfig
|
|
55
|
-
vectors: {
|
|
56
|
-
size: 1536,
|
|
57
|
-
distance: "Cosine",
|
|
58
|
-
},
|
|
59
|
-
};
|
|
54
|
+
this.collectionConfig = args.collectionConfig;
|
|
60
55
|
}
|
|
61
56
|
/**
|
|
62
57
|
* Method to add documents to the Qdrant database. It generates vectors
|
|
@@ -90,10 +85,17 @@ export class QdrantVectorStore extends VectorStore {
|
|
|
90
85
|
metadata: documents[idx].metadata,
|
|
91
86
|
},
|
|
92
87
|
}));
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
try {
|
|
89
|
+
await this.client.upsert(this.collectionName, {
|
|
90
|
+
wait: true,
|
|
91
|
+
points,
|
|
92
|
+
});
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
const error = new Error(`${e?.status ?? "Undefined error code"} ${e?.message}: ${e?.data?.status?.error}`);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
/**
|
|
99
101
|
* Method to search for vectors in the Qdrant database that are similar to
|
|
@@ -132,7 +134,13 @@ export class QdrantVectorStore extends VectorStore {
|
|
|
132
134
|
const response = await this.client.getCollections();
|
|
133
135
|
const collectionNames = response.collections.map((collection) => collection.name);
|
|
134
136
|
if (!collectionNames.includes(this.collectionName)) {
|
|
135
|
-
|
|
137
|
+
const collectionConfig = this.collectionConfig ?? {
|
|
138
|
+
vectors: {
|
|
139
|
+
size: (await this.embeddings.embedQuery("test")).length,
|
|
140
|
+
distance: "Cosine",
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
await this.client.createCollection(this.collectionName, collectionConfig);
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
/**
|
|
@@ -108,6 +108,9 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
108
108
|
* @returns A promise that resolves when the vectors have been added.
|
|
109
109
|
*/
|
|
110
110
|
async addVectors(vectors, documents, { keys, batchSize = 1000 } = {}) {
|
|
111
|
+
if (!vectors.length || !vectors[0].length) {
|
|
112
|
+
throw new Error("No vectors provided");
|
|
113
|
+
}
|
|
111
114
|
// check if the index exists and create it if it doesn't
|
|
112
115
|
await this.createIndex(vectors[0].length);
|
|
113
116
|
const info = await this.redisClient.ft.info(this.indexName);
|
|
@@ -222,7 +225,7 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
222
225
|
/**
|
|
223
226
|
* Method for creating an index in the RedisVectorStore. If the index
|
|
224
227
|
* already exists, it does nothing.
|
|
225
|
-
* @param dimensions The dimensions of the index
|
|
228
|
+
* @param dimensions The dimensions of the index
|
|
226
229
|
* @returns A promise that resolves when the index has been created.
|
|
227
230
|
*/
|
|
228
231
|
async createIndex(dimensions = 1536) {
|
|
@@ -137,7 +137,7 @@ export declare class RedisVectorStore extends VectorStore {
|
|
|
137
137
|
/**
|
|
138
138
|
* Method for creating an index in the RedisVectorStore. If the index
|
|
139
139
|
* already exists, it does nothing.
|
|
140
|
-
* @param dimensions The dimensions of the index
|
|
140
|
+
* @param dimensions The dimensions of the index
|
|
141
141
|
* @returns A promise that resolves when the index has been created.
|
|
142
142
|
*/
|
|
143
143
|
createIndex(dimensions?: number): Promise<void>;
|
|
@@ -105,6 +105,9 @@ export class RedisVectorStore extends VectorStore {
|
|
|
105
105
|
* @returns A promise that resolves when the vectors have been added.
|
|
106
106
|
*/
|
|
107
107
|
async addVectors(vectors, documents, { keys, batchSize = 1000 } = {}) {
|
|
108
|
+
if (!vectors.length || !vectors[0].length) {
|
|
109
|
+
throw new Error("No vectors provided");
|
|
110
|
+
}
|
|
108
111
|
// check if the index exists and create it if it doesn't
|
|
109
112
|
await this.createIndex(vectors[0].length);
|
|
110
113
|
const info = await this.redisClient.ft.info(this.indexName);
|
|
@@ -219,7 +222,7 @@ export class RedisVectorStore extends VectorStore {
|
|
|
219
222
|
/**
|
|
220
223
|
* Method for creating an index in the RedisVectorStore. If the index
|
|
221
224
|
* already exists, it does nothing.
|
|
222
|
-
* @param dimensions The dimensions of the index
|
|
225
|
+
* @param dimensions The dimensions of the index
|
|
223
226
|
* @returns A promise that resolves when the index has been created.
|
|
224
227
|
*/
|
|
225
228
|
async createIndex(dimensions = 1536) {
|