How kazkozdev/production_rag_pipeline works
1. What this repository is
This is a Python 3.8+ library for retrieval-augmented generation, with a small CLI on top. Its main job is to turn a user query into a grounded, citation-ready prompt for a local or self-hosted LLM. The architecture is library-first: the CLI and macOS launcher are thin entry points around the same pipeline.
2. End-to-end data flow
The core flow is: query in → search engines return candidate URLs → irrelevant results are filtered before download → pages are fetched in parallel → main content is extracted and chunked → chunks are reranked → a final LLM prompt/context bundle is assembled. The output is not an answer; it is a structured prompt plus source references that the downstream LLM can use.
3. Search subsystem
production_rag_pipeline.search handles web discovery via Bing and DuckDuckGo, merges results from both engines, and applies language-aware filtering. The design uses multiple engines to balance coverage and resilience, and it can switch DuckDuckGo into news mode for news-like queries. This is the first major boundary where external data enters the system.
4. Fetch subsystem
production_rag_pipeline.fetch is responsible for HTTP retrieval, retries, timeouts, and parallel page downloading. The readme’s default behavior indicates a bounded worker pool and timeout-based fetch stage, which is important for diagramming because it separates “candidate selection” from “expensive network I/O.”
5. Extraction and normalization
production_rag_pipeline.extract converts raw HTML into usable content, parses publish dates, filters boilerplate/noise, and chunks text into smaller units. It prefers richer extraction when optional dependencies are present, but can fall back to BeautifulSoup-based parsing. This stage is where raw page content becomes structured, LLM-ready evidence.
6. Relevance scoring and reranking
production_rag_pipeline.rerank is the ranking brain of the repo. It combines lexical ranking (BM25), semantic similarity, answer-span detection, diversity control via MMR, and optional cross-encoder reranking. The readme also describes freshness penalties for news-like queries, so ranking is not purely semantic; it blends relevance, diversity, and recency signals.
7. Confidence and quality signals
production_rag_pipeline.confidence likely centralizes the scoring/quality signals used to adjust source confidence and freshness. In the architecture, this is a supporting subsystem rather than a standalone stage: it feeds ranking, source selection, and prompt warnings, especially for time-sensitive or low-quality results.
8. Prompt and context assembly
production_rag_pipeline.pipeline orchestrates the full sequence and produces the final context bundle, while production_rag_pipeline.prompts turns that bundle into the actual LLM prompt. The prompt includes instructions, current date/time, source numbering, citations, and quality/freshness notes. A key boundary here is that source renumbering and source-to-chunk mapping are preserved so citations in the prompt match real inputs.
9. Configuration and runtime state
production_rag_pipeline.config exposes RAGConfig, with configuration coming from dataclasses, YAML, or RAG_-prefixed environment variables. production_rag_pipeline.core holds runtime settings and optional dependency state, which lets the pipeline adapt based on what is installed at runtime. This makes configuration a first-class architectural boundary rather than a hardcoded constant set.
10. Graceful degradation
The package is intentionally designed to work in tiers. Without semantic models, it still runs with lexical methods; without trafilatura, it falls back to simpler extraction; without extra installs, the base library still produces usable prompts. That means the architecture should be drawn as optional capability layers around a stable core pipeline.
11. Interfaces and delivery
production_rag_pipeline.cli exposes the user-facing command-line interface, including search/read modes and config loading. run_llm_query.command is a convenience launcher for macOS that bootstraps a local virtual environment. CI and release workflows live under .github/workflows, and tests cover config, CLI, pipeline, and integration behavior, which suggests the repo is shipped as a standard Python package with automated verification and release automation.
Main entry points: pipeline.py Pipeline · rerank.py Rerank · config.py Config · core.py Runtime
Components 15
Entry points
User-facing launchers and package interface.
- Package · Library root for the retrieval-augmented generation toolkit.
src/production_rag_pipeline/__init__.py - CLI · User-facing command-line entry point for search and read workflows.
src/production_rag_pipeline/cli.py - Launcher · Convenience launcher that bootstraps a local environment on macOS.
run_llm_query.command - Readme · Documents the pipeline behavior, modes, and operational defaults.
README.md
Orchestration
End-to-end pipeline composition and prompt assembly.
Retrieval
Discovery, network fetch, and content normalization stages.
- Search · Runs web search across multiple engines and applies language-aware filtering.
src/production_rag_pipeline/search.py - Fetch · Retrieves candidate pages with retries, timeouts, and bounded parallelism.
src/production_rag_pipeline/fetch.py - Extract · Normalizes HTML into main content, dates, and text chunks.
src/production_rag_pipeline/extract.py
Ranking
Scoring, reranking, and confidence signals.
- Rerank · Combines lexical, semantic, diversity, and freshness signals.
src/production_rag_pipeline/rerank.py - Confidence · Derives source quality and freshness signals that inform ranking and warnings.
src/production_rag_pipeline/confidence.py
Support
Configuration and runtime capability state.
- Config · Loads RAGConfig from dataclasses, YAML, and environment variables.
src/production_rag_pipeline/config.py - Runtime · Holds optional dependency state and runtime capabilities.
src/production_rag_pipeline/core.py - Deps · Declared runtime dependencies and optional capability packages.
requirements.txt - Build · Project metadata, build configuration, and packaging settings.
pyproject.toml
Connections 23
- CLI → Pipeline: invokes · CLI hands user requests to the orchestrated pipeline.
- Launcher → CLI: launches · macOS launcher bootstraps and then calls the CLI entry point.
- Package → CLI: exposes · Package surface exposes the command-line interface.
- Package → Pipeline: exposes · Package surface exposes the main orchestration API.
- Pipeline → Search: searches · Pipeline begins by discovering candidate URLs.
- Search → Fetch: selects · Search results become the set of pages to retrieve.
- Fetch → Extract: downloads · Fetched HTML is passed into content extraction and normalization.
- Extract → Rerank: chunks · Extracted evidence is chunked and handed to the ranking stage.
- Rerank → Confidence: weights · Ranking incorporates confidence and freshness signals.
- Rerank → Pipeline: returns · Reranked evidence flows back into orchestration.
- Pipeline → Prompts: assembles · Pipeline converts selected evidence into a prompt bundle.
- Confidence → Prompts: annotates · Quality signals are reflected in prompt notes and warnings.
- Config → Pipeline: configures · Configuration drives pipeline behavior and defaults.
- Config → Search: tunes · Search behavior is controlled by configuration.
- Config → Fetch: tunes · Fetch timeouts and concurrency are configuration-driven.
- Config → Rerank: tunes · Ranking thresholds and model choices are configuration-driven.
- Runtime → Search: adapts · Available capabilities influence search behavior.
- Runtime → Extract: adapts · Optional extraction dependencies change normalization strategy.
- Runtime → Rerank: adapts · Optional semantic models and rerankers change ranking depth.
- Readme → CLI: documents · README describes the user-facing commands and modes.
- Readme → Pipeline: documents · README explains the end-to-end query-to-prompt flow.
- Deps → Runtime: declares · Dependencies define which optional capabilities are available.
- Build → Package: packages · Project metadata and packaging settings define the distributable library.