DocumentChunking packs double-newline-separated paragraphs toward chunk_size. It splits an oversized paragraph at sentence boundaries.
1
Create a Python file
document_chunking.py
2
Set up your virtual environment
3
Install dependencies
4
Export your OpenAI API key
5
Run PgVector
6
Run the script
split_on_pages=False so PDFReader combines the pages before applying DocumentChunking. Keep the default value of True to chunk each page independently.
Chunk Size
chunk_size is a target rather than a strict ceiling. Paragraph separators, a sentence longer than the target, and overlap can produce a longer chunk. Overlap is prepended without an added separator.