liveBook · Manning

Document

As explained in Build AI-Enhanced Web Apps

A Document is a structured LangChain object representing retrieved content and associated document information.

A Document is a structured LangChain object containing a text fragment in pageContent and associated metadata. Loaders produce lists of Documents from source files, making parsed content ready for chunking, summarization, embeddings, or vector storage. section 7.1.3 section 6.2.1

Document ingestion typically detects a file type, selects a loader, parses the source, and splits the resulting Documents into smaller overlapping chunks. RecursiveCharacterTextSplitter preserves semantic structure while constraining chunk size for model context windows. section 7.1.3 section 6.2.1

Loading and chunking uploaded files

Use PDFLoader or DocxLoader according to the file extension, then pass the returned Documents to RecursiveCharacterTextSplitter. For example, a PDF such as aesops-fables.pdf becomes parsed Documents, which can be split with a 1,500-character chunk size and 200-character overlap before summarization. section 7.1.3

Listing 6.5 Splitting a text into a list of chunks for retrieval
const splitter = new RecursiveCharacterTextSplitter({
  chunkSize: 100,    #1
  chunkOverlap: 20,    #2
});
const output = await splitter.createDocuments([text]);    #3

/* Example output structure:
[
  Document {
    pageContent: "Artificial Intelligence (AI) is intelligence",
    metadata: { id: 2 }
  },
  Document {
    ...
  },
  ...
]
*/

Inspect the JavaScript output showing each Document's pageContent and metadata after text splitting. section 6.2.1

How Build AI-Enhanced Web Apps covers it

How deep it goes
Defines content and metadata, then explains loader output and recursive chunking; it stops short of Document class internals.
Examples
Uses PDF and DOCX uploads, Aesop's fables, pageContent and metadata output, and overlapping chunks for summarization.
What it assumes
Assumes JavaScript or TypeScript familiarity while introducing document parsing, chunking, metadata, and context-window preparation.
What you can do after
Build document-ingestion pipelines with PDFLoader, DocxLoader, and RecursiveCharacterTextSplitter.
How it connects
Connects document loaders with text splitters, embeddings, vector databases, retrievers, and retrieval-augmented generation.

Also explained in

Compare how 8 books explain Document →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.