Skip to content

Commit

Permalink
core[patch]: fix: Document should handle empty pageContent (fixes #5884
Browse files Browse the repository at this point in the history
…) (#5885)

* fix: Document should handle empty pageContent (fixes #5884)

* Format

---------

Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
  • Loading branch information
glorat and jacoblee93 authored Jun 25, 2024
1 parent 43829d6 commit 5b73067
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions langchain-core/src/documents/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export class Document<
metadata: Metadata;

constructor(fields: DocumentInput<Metadata>) {
this.pageContent = fields.pageContent
? fields.pageContent.toString()
: this.pageContent;
this.pageContent =
fields.pageContent !== undefined ? fields.pageContent.toString() : "";
this.metadata = fields.metadata ?? ({} as Metadata);
}
}
7 changes: 7 additions & 0 deletions langchain-core/src/tests/document.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from "@jest/globals";
import { Document } from "../documents/document.js";

test("Document should handle empty pageContent", () => {
const doc = new Document({ pageContent: "" });
expect(doc.pageContent).toEqual("");
});

0 comments on commit 5b73067

Please sign in to comment.