-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
base.ts
79 lines (68 loc) · 2.31 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Serializable } from "@langchain/core/load/serializable";
// Arbitrary value, used for generating namespaced UUIDs.
export const UUIDV5_NAMESPACE = "10f90ea3-90a4-4962-bf75-83a0f3c1c62a";
export type UpdateOptions = {
groupIds?: (string | null)[];
timeAtLeast?: number;
};
export type ListKeyOptions = {
before?: number;
after?: number;
groupIds?: (string | null)[];
limit?: number;
};
export interface RecordManagerInterface {
/**
* Creates schema in the record manager.
* @returns Promise
*/
createSchema(): Promise<void>;
/**
* Returns current time from the record manager.
* @returns Current time
*/
getTime(): Promise<number>;
/**
* Updates keys in the record manager.
* @param keys List of keys to update
* @param groupIds List of groupIds to update
* @param timeAtLeast Update only if current time is at least this value
* @returns Promise
* @throws Error if timeAtLeast is provided and current time is less than timeAtLeast
* @throws Error if number of keys does not match number of groupIds
*/
update(keys: string[], updateOptions: UpdateOptions): Promise<void>;
/**
* Checks if keys exist in the record manager.
* @param keys List of keys to check
* @returns List of booleans indicating if key exists in same order as provided keys
*/
exists(keys: string[]): Promise<boolean[]>;
/**
* Lists keys from the record manager.
* @param before List keys before this timestamp
* @param after List keys after this timestamp
* @param groupIds List keys with these groupIds
* @param limit Limit the number of keys returned
* @returns List of keys
*
*/
listKeys(options: ListKeyOptions): Promise<string[]>;
/**
* Deletes keys from the record manager.
* @param keys List of keys to delete
*/
deleteKeys(keys: string[]): Promise<void>;
}
export abstract class RecordManager
extends Serializable
implements RecordManagerInterface
{
lc_namespace = ["langchain", "recordmanagers"];
abstract createSchema(): Promise<void>;
abstract getTime(): Promise<number>;
abstract update(keys: string[], updateOptions?: UpdateOptions): Promise<void>;
abstract exists(keys: string[]): Promise<boolean[]>;
abstract listKeys(options?: ListKeyOptions): Promise<string[]>;
abstract deleteKeys(keys: string[]): Promise<void>;
}