Share E-Book

RAG with Python Cookbook (Early Release) (Dominik Polzer) (Z-Library)

Author

Rating No ratings yet

Log in to rate

AI
Language English

As businesses race to unlock the full potential of large language models (LLMs), a critical challenge has emerged: How do you connect these tools to real-time, external data to solve real-world problems? Retrieval-augmented generation (RAG) is the answer. Packed with over 70 practical recipes, this go-to guide tackles a wide range of GenAI applications through structured hands-on learning. Author Dominik Polzer provides the tools you need to design, implement, and optimize RAG systems for your unique use cases.

Format EPUB
Size 7.1 MB
271
Views

AI Guide

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

Full assistant
AI guide
【One-Line Pitch】 A hands-on recipe collection for developers who need to connect large language models to real, messy company data—PDFs, Word files, spreadsheets, databases, audio, and images—and turn that data into working retrieval-augmented generation (RAG) systems in Python. Best for engineers and data practitioners who learn by building rather than by reading theory. 【Book Arc】 - **Opening (~0%–9%)**: Frames the core problem—most enterprise information is unstructured and locked in documents, while LLMs have limited context windows and slow, costly responses when prompts grow. Introduces RAG as the bridge between search engines and foundation models, and sketches the two-part architecture: an indexing/processing pipeline and a runtime query-and-answer loop. - **Early (~9%–34%)**: Builds the ingestion layer recipe by recipe. Covers loading Word files (with element-level partitioning), PDFs (text plus page metadata), and CSV/Excel files, presenting three distinct strategies for tabular data—row-to-text, whole-table-in-prompt, and text-to-SQL—with trade-offs for each. - **Middle (~34%–53%)**: Extends ingestion to databases and non-text modalities. Connects RAG to PostgreSQL via SQLAlchemy, transcribes audio with Whisper, and extracts text from images and scanned PDFs using OCR engines like Tesseract, contrasting self-hosted OCR with multimodal model approaches. - **Late (~53% onward)**: Excerpts thin out here; the visible material continues into multimodal extraction via foundation models, but later chapters on embeddings, vector stores, retrieval optimization, and LLM agents are not covered in the provided excerpts. 【Key Takeaways】 - **RAG exists because context windows are a bottleneck** (Opening): Even as model context sizes grow, stuffing huge prompts makes applications slow and expensive—RAG retrieves only the relevant chunks instead. This is the book's motivating argument. - **The pipeline has two halves: indexing and runtime** (Opening): Load → split → embed → store on one side; embed the question → similarity search → generate on the other. Understanding this split is the mental model for everything that follows. - **Ingestion is the hard, creative part** (Early): The book stresses that loading pipelines for mixed sources and modalities require real design work, not boilerplate—this is where most RAG projects succeed or fail. - **Document structure is retrieval signal** (Early): Partitioning Word files into typed elements (Title, NarrativeText, ListItem) lets you search chapter titles before drilling into content, improving retrieval precision. - **Tabular data needs a strategy choice, not a default** (Early): Row-to-text is simple but only answers few-row questions; whole-table-in-prompt is costly and weak on complex queries; text-to-SQL handles aggregations. Pick per use case. - **PostgreSQL can double as a vector store** (Middle): With the pgvector extension, the same database holding relational data can store embeddings and run similarity searches—useful when building web apps around RAG workflows. - **OCR vs. multimodal models is a real trade-off** (Middle): OCR engines are fast, cheap, and self-hostable but only work on text-heavy images; multimodal models are flexible via prompts but costlier. Match the tool to the image type. - **Metadata preservation matters throughout** (Early/Middle): Page numbers, file paths, and element categories are repeatedly emphasized—they enable filtering, citation, and smarter retrieval later. 【Reading Tips】 - **Deep-read the ingestion chapters (roughly the first half)**: This is the most concrete, excerpt-supported material and the part most teams underestimate. Skim the code listings but absorb the "Discussion" and "See also" notes—they carry the design judgment. - **Treat the three CSV/Excel options as a decision framework**: Before coding, decide which option fits your query patterns (few-row lookups vs. aggregations), then jump to the matching recipe. - **Watch for framework dependencies**: The book leans on LangChain and LlamaIndex functions; if you're not using those, translate the concepts rather than copying code. - **Note the Early Release caveat**: Content is raw and unedited, with placeholder links and incomplete cross-references—expect gaps and verify against current library APIs. - **Take away the architecture, not just snippets**: The lasting value is the load-split-embed-store / embed-search-generate loop and the trade-off reasoning around each stage. 【Coverage Limits】 The provided excerpts cover only the opening and ingestion-focused chapters (roughly the first half of the book). Later material on embeddings, vector stores, retrieval optimization, evaluation, and LLM agents—despite being promised in the subtitle—is not represented here, so this guide cannot assess those sections.

Passage locations

Excerpt 1
m/catalog/errata.csp?isbn=9798341600560 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. RAG with Python Cookbook , t...
View in text
Excerpt 2
cture can also optimize the retrieval step in an RAG system. For example, in a book with unrelated chapters, we might first find the best matching chapter ti...
View in text
Excerpt 3
the Excel file census-income.xlsx into a Pandas data frame. Once loaded, Example 1-4 applies the function create_text_description to each row of the data fra...
View in text
Excerpt 4
he Windows installer provided by the University of Mannheim. Once Tesseract is installed, we will install the required Python packages: pdf2image , pytessera...
View in text

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List