UNPKG

@langchain/core

Version:
1 lines 2.12 kB
{"version":3,"file":"document.cjs","names":[],"sources":["../../src/documents/document.ts"],"sourcesContent":["export interface DocumentInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Metadata extends Record<string, any> = Record<string, any>,\n> {\n pageContent: string;\n\n metadata?: Metadata;\n\n /**\n * An optional identifier for the document.\n *\n * Ideally this should be unique across the document collection and formatted\n * as a UUID, but this will not be enforced.\n */\n id?: string;\n}\n\nexport interface DocumentInterface<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Metadata extends Record<string, any> = Record<string, any>,\n> {\n pageContent: string;\n\n metadata: Metadata;\n\n /**\n * An optional identifier for the document.\n *\n * Ideally this should be unique across the document collection and formatted\n * as a UUID, but this will not be enforced.\n */\n id?: string;\n}\n\n/**\n * Interface for interacting with a document.\n */\nexport class Document<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Metadata extends Record<string, any> = Record<string, any>,\n>\n implements DocumentInput, DocumentInterface\n{\n pageContent: string;\n\n metadata: Metadata;\n\n // The ID field is optional at the moment.\n // It will likely become required in a future major release after\n // it has been adopted by enough vectorstore implementations.\n /**\n * An optional identifier for the document.\n *\n * Ideally this should be unique across the document collection and formatted\n * as a UUID, but this will not be enforced.\n */\n id?: string;\n\n constructor(fields: DocumentInput<Metadata>) {\n this.pageContent =\n fields.pageContent !== undefined ? fields.pageContent.toString() : \"\";\n this.metadata = fields.metadata ?? ({} as Metadata);\n this.id = fields.id;\n }\n}\n"],"mappings":";;;;;AAqCA,IAAa,WAAb,MAKA;CACE;CAEA;;;;;;;CAWA;CAEA,YAAY,QAAiC;AAC3C,OAAK,cACH,OAAO,gBAAgB,SAAY,OAAO,YAAY,UAAU,GAAG;AACrE,OAAK,WAAW,OAAO,YAAa,EAAE;AACtC,OAAK,KAAK,OAAO"}