liveBook · Manning

Parsing

As explained in Build AI-Enhanced Web Apps

Document parsing is the extraction and structural interpretation of content from files such as PDFs or DOCX documents.

Document parsing extracts and structurally interprets content from files such as PDFs and DOCX documents. In document summarization and RAG workflows, parsing prepares source material for cleaning, embedding, retrieval, and grounded conversation. section 7.1.4 section 11.1.1

A practical parsing pipeline accounts for both content quality and operational safety:

  • Extract text while allowing for scattered content, encoded PDF text, tables, footnotes, annotations, and embedded images. section 7.1.4
  • Normalize parsed content by joining content arrays, trimming whitespace, removing unwanted references, collapsing spaces, and filtering non-content lines. section 7.1.4
  • Handle images separately when the PDF loader overlooks them, using image extraction followed by OCR or external language-model descriptions. section 7.1.4
  • Validate file types and sizes, process parsing and chunking on the server, and add error handling before vectorizing content. section 11.2.2

Knowledge-base upload flow

A user creates a knowledge base, uploads a PDF or DOCX file, and waits while the application parses and analyzes it. The resulting content becomes vector embeddings stored in Upstash Vector, enabling similarity search and conversational questions grounded in the uploaded documents. section 11.1.1

Listing 7.3 Normalization of document content
function normalizeDocuments(docs) {
  return docs.map((doc) => {
    let pageContent;
    if (typeof doc.pageContent === "string") {
      pageContent = doc.pageContent;
    } else if (Array.isArray(doc.pageContent)) {
      pageContent = doc.pageContent.join("\n");    #1
    }
    if (pageContent) {

      pageContent = pageContent.trim();    #2

      // Remove unwanted characters (e.g., figure references)
      pageContent = pageContent.replace(/Figure \d+:.*?\n/g, '').replace(/−\
➥d+\n/g, '');

      // Normalize spaces
      pageContent = pageContent.replace(/\s+/g, ' ');    #3
      pageContent = pageContent.replace(/(\s*l\s*){2,}/g, ' ');

      // Filter out non-content lines
      const filteredDocument = pageContent.split('\n').filter(line => 
        !line.includes('References') && !line.includes('Acknowledgments')  
      )[0];    #4
      doc.pageContent = filteredDocument;
      return doc;
    }

    return null; 
  }).filter(doc => doc.content !== null); 
// Filter out any null entries from the result
}

Use the normalization listing to inspect a JavaScript cleanup function that joins content, trims it, removes unwanted characters, normalizes spaces, and filters lines. section 7.1.4

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains extraction problems, normalization steps, image gaps, and secure processing, but stops short of implementing a complete parser.
Examples
Uses PDFs, DOCX files, tables, footnotes, annotations, images, headers, footers, and uploaded knowledge-base documents as examples.
What it assumes
Assumes familiarity with uploaded files and document-based applications while teaching parsing limitations, cleanup, validation, and server-side processing.
What you can do after
Diagnose parsing quality problems, normalize extracted content, and operate a secure document-ingestion flow for vector search.
How it connects
Connects document parsing with document summarization, RAG, chunking, vector embeddings, similarity search, OCR, and conversational agents.

Also explained in

Compare how 13 books explain parsing →

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.