Core LangChain.js abstractions and schemas for building applications with Large Language Models
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Document representation and processing capabilities for content management in LangChain applications. Documents are the fundamental units of text data used throughout the framework.
Core document representation containing text content and metadata.
/**
* Core document representation
* @template Metadata - Type of metadata object
*/
class Document<Metadata = Record<string, unknown>> {
/** Main text content of the document */
pageContent: string;
/** Associated metadata */
metadata: Metadata;
/** Optional unique identifier */
id?: string;
constructor(fields: DocumentInput<Metadata>);
/** Convert to JSON representation */
toJSON(): Serialized;
/** Create document from JSON */
static fromJSON(json: Serialized): Document;
}Usage Examples:
import { Document } from "@langchain/core/documents";
// Simple document
const doc1 = new Document({
pageContent: "LangChain is a framework for building applications with LLMs.",
metadata: {
source: "documentation",
category: "introduction"
}
});
// Document with custom metadata type
interface ArticleMetadata {
title: string;
author: string;
publishDate: Date;
tags: string[];
}
const article = new Document<ArticleMetadata>({
pageContent: "This is the article content...",
metadata: {
title: "Understanding LangChain",
author: "John Doe",
publishDate: new Date("2024-01-15"),
tags: ["langchain", "llm", "tutorial"]
},
id: "article-123"
});
console.log(article.pageContent); // "This is the article content..."
console.log(article.metadata.title); // "Understanding LangChain"interface DocumentInput<Metadata = Record<string, unknown>> {
/** Main text content */
pageContent: string;
/** Document metadata */
metadata?: Metadata;
/** Optional document identifier */
id?: string;
}
interface DocumentInterface<Metadata = Record<string, unknown>> {
pageContent: string;
metadata: Metadata;
id?: string;
}