-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
document.ts
64 lines (55 loc) · 1.72 KB
/
document.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
export interface DocumentInput<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Metadata extends Record<string, any> = Record<string, any>
> {
pageContent: string;
metadata?: Metadata;
/**
* An optional identifier for the document.
*
* Ideally this should be unique across the document collection and formatted
* as a UUID, but this will not be enforced.
*/
id?: string;
}
export interface DocumentInterface<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Metadata extends Record<string, any> = Record<string, any>
> {
pageContent: string;
metadata: Metadata;
/**
* An optional identifier for the document.
*
* Ideally this should be unique across the document collection and formatted
* as a UUID, but this will not be enforced.
*/
id?: string;
}
/**
* Interface for interacting with a document.
*/
export class Document<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Metadata extends Record<string, any> = Record<string, any>
> implements DocumentInput, DocumentInterface
{
pageContent: string;
metadata: Metadata;
// The ID field is optional at the moment.
// It will likely become required in a future major release after
// it has been adopted by enough vectorstore implementations.
/**
* An optional identifier for the document.
*
* Ideally this should be unique across the document collection and formatted
* as a UUID, but this will not be enforced.
*/
id?: string;
constructor(fields: DocumentInput<Metadata>) {
this.pageContent =
fields.pageContent !== undefined ? fields.pageContent.toString() : "";
this.metadata = fields.metadata ?? ({} as Metadata);
this.id = fields.id;
}
}