This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
Break PDFs and documents into searchable chunks for retrieval-augmented
generation (RAG) pipelines.
Problem
You have PDF documents or text files that you want to use for
retrieval-augmented generation (RAG). Before you can search them, you
need to:
- Split documents into smaller chunks
- Generate embeddings for each chunk
- Store everything in a searchable index
Solution
What’s in this recipe:
- Split PDFs into sentences with token limits
- Control chunk size with token limits
- Add embeddings for semantic search
You create a view with a document_splitter iterator that automatically
breaks documents into chunks. Then you add an embedding index for
semantic search.
Setup
Load documents
Created directory ‘rag_demo’.
<pixeltable.catalog.dir.Dir at 0x3d8e31710>
Created table ‘documents’.
Inserting rows into `documents`: 1 rows [00:00, 775.86 rows/s]
Inserted 1 row with 0 errors.
1 row inserted, 2 values computed.
Split into chunks
Create a view that splits each document into sentences with a token
limit:
Inserting rows into `chunks`: 217 rows [00:00, 42111.88 rows/s]
Add semantic search
Create an embedding index on the chunks for similarity search:
Search your documents
Use similarity search to find relevant chunks:
Explanation
Separator options:
You can combine separators: separators='sentence,token_limit'
Chunk sizing:
limit: Maximum tokens per chunk (default: 500)
overlap: Tokens to overlap between chunks (default: 0)
New documents are processed automatically:
When you insert new documents, chunks and embeddings are generated
without extra code.
See also