File tree Expand file tree Collapse file tree 5 files changed +36
-2
lines changed
langchain-core/src/documents
langchain/src/document_loaders/tests Expand file tree Collapse file tree 5 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,14 @@ export interface DocumentInput<
5
5
pageContent : string ;
6
6
7
7
metadata ?: Metadata ;
8
+
9
+ /**
10
+ * An optional identifier for the document.
11
+ *
12
+ * Ideally this should be unique across the document collection and formatted
13
+ * as a UUID, but this will not be enforced.
14
+ */
15
+ id ?: string ;
8
16
}
9
17
10
18
export interface DocumentInterface <
@@ -14,6 +22,14 @@ export interface DocumentInterface<
14
22
pageContent : string ;
15
23
16
24
metadata : Metadata ;
25
+
26
+ /**
27
+ * An optional identifier for the document.
28
+ *
29
+ * Ideally this should be unique across the document collection and formatted
30
+ * as a UUID, but this will not be enforced.
31
+ */
32
+ id ?: string ;
17
33
}
18
34
19
35
/**
@@ -28,9 +44,21 @@ export class Document<
28
44
29
45
metadata : Metadata ;
30
46
47
+ // The ID field is optional at the moment.
48
+ // It will likely become required in a future major release after
49
+ // it has been adopted by enough vectorstore implementations.
50
+ /**
51
+ * An optional identifier for the document.
52
+ *
53
+ * Ideally this should be unique across the document collection and formatted
54
+ * as a UUID, but this will not be enforced.
55
+ */
56
+ id ?: string ;
57
+
31
58
constructor ( fields : DocumentInput < Metadata > ) {
32
59
this . pageContent =
33
60
fields . pageContent !== undefined ? fields . pageContent . toString ( ) : "" ;
34
61
this . metadata = fields . metadata ?? ( { } as Metadata ) ;
62
+ this . id = fields . id ;
35
63
}
36
64
}
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ test("Test CSV loader from blob", async () => {
46
46
expect ( docs . length ) . toBe ( 2 ) ;
47
47
expect ( docs [ 0 ] ) . toMatchInlineSnapshot ( `
48
48
Document {
49
+ "id": undefined,
49
50
"metadata": {
50
51
"blobType": "text/csv",
51
52
"line": 1,
@@ -57,6 +58,7 @@ test("Test CSV loader from blob", async () => {
57
58
` ) ;
58
59
expect ( docs [ 1 ] ) . toMatchInlineSnapshot ( `
59
60
Document {
61
+ "id": undefined,
60
62
"metadata": {
61
63
"blobType": "text/csv",
62
64
"line": 2,
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ test("Test JSON loader from blob", async () => {
39
39
expect ( docs . length ) . toBe ( 2 ) ;
40
40
expect ( docs [ 0 ] ) . toMatchInlineSnapshot ( `
41
41
Document {
42
+ "id": undefined,
42
43
"metadata": {
43
44
"blobType": "application/json",
44
45
"line": 1,
@@ -49,6 +50,7 @@ test("Test JSON loader from blob", async () => {
49
50
` ) ;
50
51
expect ( docs [ 1 ] ) . toMatchInlineSnapshot ( `
51
52
Document {
53
+ "id": undefined,
52
54
"metadata": {
53
55
"blobType": "application/json",
54
56
"line": 2,
@@ -87,6 +89,7 @@ test("Test JSON loader from blob", async () => {
87
89
expect ( docs . length ) . toBe ( 10 ) ;
88
90
expect ( docs [ 0 ] ) . toMatchInlineSnapshot ( `
89
91
Document {
92
+ "id": undefined,
90
93
"metadata": {
91
94
"blobType": "application/json",
92
95
"line": 1,
@@ -97,6 +100,7 @@ test("Test JSON loader from blob", async () => {
97
100
` ) ;
98
101
expect ( docs [ 1 ] ) . toMatchInlineSnapshot ( `
99
102
Document {
103
+ "id": undefined,
100
104
"metadata": {
101
105
"blobType": "application/json",
102
106
"line": 2,
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ test("Test JSONL loader from blob", async () => {
40
40
expect ( docs . length ) . toBe ( 2 ) ;
41
41
expect ( docs [ 0 ] ) . toMatchInlineSnapshot ( `
42
42
Document {
43
+ "id": undefined,
43
44
"metadata": {
44
45
"blobType": "application/jsonl+json",
45
46
"line": 1,
@@ -50,6 +51,7 @@ test("Test JSONL loader from blob", async () => {
50
51
` ) ;
51
52
expect ( docs [ 1 ] ) . toMatchInlineSnapshot ( `
52
53
Document {
54
+ "id": undefined,
53
55
"metadata": {
54
56
"blobType": "application/jsonl+json",
55
57
"line": 2,
Original file line number Diff line number Diff line change @@ -23,8 +23,6 @@ export interface TypeORMVectorStoreArgs {
23
23
*/
24
24
export class TypeORMVectorStoreDocument extends Document {
25
25
embedding : string ;
26
-
27
- id ?: string ;
28
26
}
29
27
30
28
const defaultDocumentTableName = "documents" ;
You can’t perform that action at this time.
0 commit comments