๐ง DJ-Rag-Pipeline
Production RAG Pipeline โ PDFs โ Pinecone โ LLM โ Ragas (Sub-10s E2E)
One-command production RAG API for any PDF documents. Built on Clean Layered Architecture (SOLID Principles) with built-in Arize Phoenix Observability & OpenInference tracing.
๐ Key Features
| Feature | Status | Description |
|---|---|---|
| Clean SOLID Architecture | โ Layered | Protocol-driven domain, adapters, and services with 100% dependency injection testability. |
| Phoenix Observability | ๐ญ Built-in UI | Live tracing dashboard at http://localhost:6006 with OpenInference conventions. |
| PDF Processing | โ Docling | High-accuracy incremental PDF-to-Markdown conversion. |
| Smart Chunking | โ 2-Stage | Markdown header splitting + recursive token character splitting. |
| Pinecone Records API | โ Server-side | Integrated embedding schema, hybrid search, and batch upserting. |
| Grounded LLM Generation | โ Strict Context | Zero hallucination prompt design with mandatory source citations. |
| Ragas Quality Evaluation | ๐ฏ Automated | 5 metrics (context_precision, recall, relevance, faithfulness, relevancy) with nested span tracing. |
| FastAPI + UV | โก High Performance | Clean modular endpoints with UV package management on Python 3.13. |
๐ฆ Install & Run (60 seconds)
# 1. Install
pip install dj-rag
# 2. Create project
dj-rag init my_rag_project
# 3. Setup & run
cd my_rag_project
# Edit .env with your credentials
uv sync
uv run uvicorn main:app --reload --port 8000
- API Swagger Docs:
http://localhost:8000/docs๐ - Phoenix Tracing UI:
http://localhost:6006๐ฅ
๐๏ธ Project Structure (Clean Layered Architecture)
dj-rag init sets up the following SOLID architecture:
my_rag_project/
โโโ main.py # ๐ FastAPI entrypoint & lifespan management (~75 lines)
โโโ pyproject.toml
โโโ env_example.txt
โโโ src/
โโโ domain/ # ๐๏ธ Layer 1: Contracts & Models (Zero external deps)
โ โโโ contracts.py # Protocols: BaseRetriever, BaseChatbot, BaseEvaluator, BaseDocConverter
โ โโโ base_models.py # Unified DTOs: DocumentChunk, RetrievalResult, PipelineResult
โโโ infrastructure/ # ๐ Layer 2: Vendor Adapters
โ โโโ vector_stores/ # PineconeRetriever (implements BaseRetriever)
โ โโโ llm/ # RAGChatbot (implements BaseChatbot)
โ โโโ evaluators/ # RagasEvaluator with OTel spans (implements BaseEvaluator)
โ โโโ doc_parsers/ # DoclingPDFConverter (implements BaseDocConverter)
โโโ services/ # โ๏ธ Layer 3: Application Workflows
โ โโโ rag_service.py # Coordinates Query -> Retrieve -> Generate
โ โโโ ingestion_service.py # Coordinates PDF Convert -> Chunk -> Batch Upsert
โ โโโ check_pincone_index.py # Pinecone index inspection & chunk statistics
โโโ api/ # ๐ Layer 4: HTTP Transport
โ โโโ routes/v1.py # Route handlers: /chat, /evaluate-ragas, /full-pipeline
โ โโโ dependencies.py # FastAPI dependency injection providers (Depends())
โโโ core/ # ๐งฉ Cross-cutting concerns (config.py, tracing.py)
โโโ embeddings/ # โก Cached global embedding manager
โโโ data/ # ๐ PDF storage (data_source/) and Markdown (markdown_data_sources/)
๐ญ Arize Phoenix Observability (http://localhost:6006)
Whenever your server starts, an in-process Arize Phoenix UI launches automatically:
- Dashboard URL:
http://localhost:6006/ - Collector Endpoint:
http://localhost:6006/v1/traces - Tracing Conventions: OpenInference (
CHAIN,LLM,EVALUATOR) - Self-Tracing Muted: Phoenix's internal
/graphqlserver polling is suppressed to keep traces and console logs clean. - Bulk Ingestion Suppression: Bulk embedding calls during
/full-pipelineare muted viasuppress_tracing()to avoid trace flooding.
๐ What You Can Check on the Dashboard
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ARIZE PHOENIX DASHBOARD (http://localhost:6006) โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๐ Traces โ Chronological list of every /chat & /evaluate requestโ
โ ๐ Spans โ Search & filter by kind: LLM, CHAIN, EVALUATOR โ
โ ๐ฏ Evaluations โ Quality metrics: Faithfulness, Precision, Recall โ
โ โก Latency & $ โ Token usage, estimated cost, and latency percentiles โ
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Trace Waterfall Breakdown:
/chatExecution Tree:โผ rag_chat_generation (CHAIN) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ [482ms] โ โโ Input: User query + retrieved document contexts โ โโ Output: Generated grounded answer โ โโโบ ChatOpenAI / Groq (LLM) โโโโโโโโโโโโโโโโโโโโโโโโโโโโ [465ms] โโ Model: openai/gpt-oss-120b | Temperature: 0.1 โโ Tokens: Prompt: 1,240 | Completion: 85 | Total: 1,325 โโ System Prompt: Strict "context-only" instructions/evaluate-ragasExecution Tree:โผ ragas_evaluation (EVALUATOR) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ [3.1s] โ Attributes: eval.context_precision: 1.0 | eval.faithfulness: 0.95 | ... โ โโโบ ragas_context_precision (EVALUATOR) โโโโโโโโโโโโโโโโโ [620ms] -> LLM prompt & score โโโบ ragas_context_recall (EVALUATOR) โโโโโโโโโโโโโโโโโโโโ [580ms] -> LLM prompt & score โโโบ ragas_context_relevance (EVALUATOR) โโโโโโโโโโโโโโโโโ [510ms] -> LLM prompt & score โโโบ ragas_faithfulness (EVALUATOR) โโโโโโโโโโโโโโโโโโโโโโ [710ms] -> Hallucination detection โโโบ ragas_answer_relevancy (EVALUATOR) โโโโโโโโโโโโโโโโโโ [680ms] -> Answer relevancy
๐ ๏ธ Debugging Workflows:
- Detecting Hallucinations: When
faithfulness < 0.90, expandragas_faithfulness$\rightarrow$ inspect the judge LLM's explanation of ungrounded statements. - Verifying Retrieval: Inspect the
rag_chat_generationspan input to verify chunk rank order. - Tracking Costs & Latency: Monitor token usage, cost estimations, and $p50/p90/p99$ latencies.
๐ฏ Upload & Query PDFs (API-First)
1. Upload + Index PDFs (One Command)
curl -X POST "http://localhost:8000/full-pipeline" \
-F "files=@yoga-guide.pdf" \
-F "files=@asana-manual.pdf"
2. Query Instantly!
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{"query": "What are the primary benefits of pranayama?", "top_k": 5}'
Response:
{
"success": true,
"data": {
"answer": "Based on the provided context: Pranayama improves lung capacity and calms the nervous system... [yoga-guide.md | Chunk: 2]",
"sources": [
{
"id": "yoga-guide_2",
"text": "Pranayama practices improve respiratory stamina...",
"source": "yoga-guide.md",
"score": 0.912
}
],
"retrieval_metrics": {
"retrieved_count": 5,
"latency_seconds": 0.234,
"avg_score": 0.891
}
}
}
3. Evaluate Answer Quality (Ragas)
curl -X POST "http://localhost:8000/evaluate-ragas" \
-H "Content-Type: application/json" \
-d '{
"question": "What are the primary benefits of pranayama?",
"answer": "Pranayama improves lung capacity and calms the nervous system.",
"contexts": ["Pranayama practices improve respiratory stamina and regulate stress."]
}'
๐ API Endpoints
| Endpoint | Method | Purpose | Latency |
|---|---|---|---|
/chat |
POST |
Core RAG (Retrieve $\rightarrow$ Generate) | ~500ms โก |
/full-pipeline |
POST |
PDFs $\rightarrow$ Markdown $\rightarrow$ Pinecone | ~30s ๐ญ |
/evaluate-ragas |
POST |
5 Ragas Quality Metrics | ~3s ๐ฏ |
/index-status |
GET |
Vector Store Health & Chunk Counts | ~50ms ๐ |
/health |
GET |
API Status & Version | ~5ms โ |
โ๏ธ Environment Configuration (.env)
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_index_name
PINECONE_INDEX_HOST=
PINECONE_NAMESPACE=__default__
PINECONE_TEXT_FIELD=text
PINECONE_EMBED_MODEL=llama-text-embed-v2
EMBEDDING_MODEL=nomic-ai/nomic-embed-text-v1.5
MAX_CHUNK_SIZE=1500
CHUNK_OVERLAP=400
LLM_MODEL=openai/gpt-oss-120b
LLM_BASE_URL=https://api.groq.com/openai/v1
LLM_PROVIDER=openai
LLM_MAX_TOKENS=16384
LLM_API_KEY=your_llm_api_key
PHONIEX_PORT=6006
PHONIEX_HOST=0.0.0.0
PHOENIX_ENABLE_AUTH=false
๐ Production Targets
| Metric | Target | Description |
|---|---|---|
| Retrieval Latency | < 500ms |
Vector search duration in Pinecone |
| Context Precision | > 0.90 |
Most relevant chunks prioritized first |
| Faithfulness | > 0.90 |
Zero hallucination score against retrieved docs |
| Answer Relevancy | > 0.85 |
Response directness to user's question |
๐ License
Distributed under the MIT License.
Made with โค๏ธ by DJ ๐ง
Metadata
Release files for dj-rag 2.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dj_rag-2.0.4.tar.gz | 33.2 kB | Without provenance | Details for dj_rag-2.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dj_rag-2.0.4-py3-none-any.whl | Python 3 | none | any | Details for dj_rag-2.0.4-py3-none-any.whl |
Total release size: 82.0 kB
Release files / dj_rag-2.0.4.tar.gz
| Download URL | dj_rag-2.0.4.tar.gz |
|---|---|
| Size | 33.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d41bd510bd253b6b41e70df45d677cce855cf4bc4cb91224ea09ab92d68a057a
|
|
BLAKE2b-256 checksum How to use checksums |
814d566b92c0b39b040c9f8dd53e440468c64281c0a7526458c8372052b7dc77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Release files / dj_rag-2.0.4-py3-none-any.whl
| Download URL | dj_rag-2.0.4-py3-none-any.whl |
|---|---|
| Size | 48.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63fec607348d4c36c818e6ec6062462c67b5aa7c768ac34bb030dcc6e4d79dbc
|
|
BLAKE2b-256 checksum How to use checksums |
48fda8b2d6e2e97438ffacbd91a881d17c0304578c7c9ba9a14b8376d2c213b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Security for dj-rag 2.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.