pdf_rag
Build and query a RAG index over PDF content to chunk documents, semantically search passages, and synthesize findings across multiple PDFs.
Instructions
Build and query a RAG index over PDF content.
Chunks, indexes, and semantically searches PDF text via LanceDB. Tables are indexed as structured chunks (section='table'). Supports query-by-example and cross-document synthesis.
Return Format
A dict with keys:
success: bool - whether the operation succeeded
message: str - human-readable summary
operation-specific keys:
chunk: {chunks, doc_id}
index: {chunks_indexed, doc_id}
search: {results: [{doc_id, chunk_id, page_num, section, source_file, text, _distance}]}
similar: same shape as search (seeded by a text snippet)
synthesize: {groups: [{doc_id, source_file, hits, snippet}], summary?}
list_documents: {documents: [{doc_id, chunk_count}]}
delete_index: {} On failure: {success: False, error, error_type}.
Examples
await pdf_rag(operation="chunk", path="book.pdf", strategy="recursive", chunk_size=1000) {"success": true, "chunks": 42, "doc_id": "a1b2c3d4e5f6", "message": "Chunked book.pdf (300 pages) into 42 chunks with recursive strategy."}
await pdf_rag(operation="search", query="quarterly revenue") {"success": true, "results": [{...}], "message": "Found 3 results for 'quarterly revenue'."}
await pdf_rag(operation="similar", text="The sky was unusually clear that night.") {"success": true, "results": [{...}], "message": "Found 2 similar passages."}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to the PDF file. Required for chunk, index operations. | |
| text | No | Source text snippet for similar (query-by-example) operation. | |
| limit | No | Max search results. Default 10. | |
| query | No | Search query for search / synthesize operations. | |
| doc_id | No | Document ID for delete_index operation. | |
| overlap | No | Chunk overlap in characters. Default 200. | |
| strategy | No | Chunking strategy: recursive, fixed. Default recursive. | recursive |
| operation | Yes | ||
| chunk_size | No | Target chunk size in characters. Default 1000. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | No | Human-readable summary | |
| success | No | Whether the operation succeeded |