MrOwaisAbdullah avatar

rag-pipeline-builder

Complete RAG (Retrieval-Augmented Generation) pipeline implementation with document ingestion, vecto

by MrOwaisAbdullah|Open Source

RAG Pipeline Builder Skill

A comprehensive Claude Agent skill for building production-ready Retrieval-Augmented Generation (RAG) systems with FastAPI backends, OpenAI embeddings, and Qdrant vector storage.

๐Ÿš€ Quick Start

1. Prerequisites

# Install Python 3.11+
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r templates/requirements.txt

2. Environment Setup

# Copy environment template
cp templates/env-example .env

# Edit with your values
# OPENAI_API_KEY=your_key_here
# QDRANT_URL=http://localhost:6333

3. Start Vector Database

# Using Docker (recommended)
docker run -p 6333:6333 qdrant/qdrant:latest

# Or use the provided docker-compose
docker-compose -f templates/docker-compose.yml up -d qdrant

4. Ingest Documents

# Ingest markdown files from a directory
python scripts/ingest_documents.py docs/ --openai-key $OPENAI_API_KEY

5. Test the System

# Run test suite
python scripts/test_rag.py --openai-key $OPENAI_API_KEY

# Or test custom queries
python scripts/test_rag.py --queries "What is RAG?" "How does chunking work?"

6. Start API Server

# Start FastAPI server
uvicorn templates.fastapi-endpoint-template:app --reload

# Or use Docker Compose
docker-compose -f templates/docker-compose.yml up

๐Ÿ“ Project Structure

rag-pipeline-builder/
โ”œโ”€โ”€ SKILL.md                           # Main skill documentation
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ chunking_example.py            # Advanced document chunking
โ”‚   โ”œโ”€โ”€ ingest_documents.py            # Document ingestion pipeline
โ”‚   โ””โ”€โ”€ test_rag.py                   # Comprehensive testing suite
โ”œโ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ fastapi-endpoint-template.py   # Production FastAPI endpoints
โ”‚   โ”œโ”€โ”€ env-example                    # Environment configuration
โ”‚   โ”œโ”€โ”€ requirements.txt               # Python dependencies
โ”‚   โ”œโ”€โ”€ docker-compose.yml             # Docker deployment
โ”‚   โ””โ”€โ”€ Dockerfile                    # Container build file
โ””โ”€โ”€ README.md                          # This file

๐ŸŽฏ Core Features

Document Chunking

  • Intelligent chunking that preserves document structure
  • Markdown-aware splitting to protect code blocks
  • Configurable chunk sizes and overlap
  • Metadata extraction for better retrieval

Vector Storage

  • Qdrant integration for high-performance vector search
  • Optimized collection setup with proper indexing
  • Batch processing for efficient ingestion
  • Filtering support for targeted searches

FastAPI Endpoints

  • Streaming chat with real-time responses
  • Health checks and monitoring
  • Error handling and logging
  • CORS support for web applications

Testing & Quality

  • Automated testing with performance metrics
  • Relevance evaluation using LLM judgments
  • Benchmarking for latency and throughput
  • Quality metrics tracking

๐Ÿ”ง Configuration

Environment Variables

VariableDefaultDescription
OPENAI_API_KEYRequiredOpenAI API key
QDRANT_URLhttp://localhost:6333Qdrant instance URL
QDRANT_API_KEYOptionalQdrant API key
CHUNK_SIZE1000Token count per chunk
CHUNK_OVERLAP200Overlap between chunks
TOP_K_CHUNKS5Chunks to retrieve
SIMILARITY_THRESHOLD0.7Minimum similarity score

RAG Pipeline Settings

# Customize chunking strategy
chunker = IntelligentChunker(
    chunk_size=1000,    # Target tokens per chunk
    overlap=200,        # Overlap between chunks
)

# Configure retrieval
results = await search_relevant_chunks(
    query_embedding,
    top_k=5,                    # Number of results
    similarity_threshold=0.7,    # Minimum score
    filters={"file_name": "guide.md"}  # Optional filters
)

๐Ÿ“Š Performance Metrics

Expected Performance

  • Embedding latency: ~50ms per batch of 100 texts
  • Retrieval latency: < 500ms for top 5 results
  • Generation latency: ~1s to first token
  • Streaming latency: < 100ms per token

Quality Benchmarks

  • Precision@5: > 80% for relevant documents
  • Relevance scores: > 0.7 for good queries
  • Groundedness: > 90% claims supported by context

๐Ÿงช Testing

Running Tests

# Basic test suite
python scripts/test_rag.py

# With relevance evaluation
python scripts/test_rag.py --evaluate

# Custom queries
python scripts/test_rag.py --queries "Your question here"

# Performance testing
python scripts/test_rag.py --queries $(printf "Question %d\n" {1..100})

Test Results Analysis

The test script provides comprehensive metrics:

๐Ÿ“Š TEST RESULTS ANALYSIS
==================================================
๐Ÿ“ˆ Total queries: 5

โฑ๏ธ  Time Metrics:
  Avg retrieval time: 0.234s
  Avg generation time: 1.456s
  Avg total time: 1.690s

๐Ÿ” Retrieval Metrics:
  Avg chunks retrieved: 4.2
  Chunk range: 3 - 5

๐ŸŽฏ Relevance Metrics:
  Avg relevance score: 0.842
  Score range: 0.734 - 0.923

๐Ÿณ Docker Deployment

Development

# Start all services
docker-compose -f templates/docker-compose.yml up

# Background mode
docker-compose -f templates/docker-compose.yml up -d

# View logs
docker-compose -f templates/docker-compose.yml logs -f rag-api

Production

# Build and deploy
docker-compose -f templates/docker-compose.yml -f docker-compose.prod.yml up -d

# Scale API
docker-compose -f templates/docker-compose.yml up -d --scale rag-api=3

๐Ÿšจ Common Issues & Solutions

IssueCauseSolution
Low relevance scoresPoor chunking strategyAdjust CHUNK_SIZE and CHUNK_OVERLAP
Slow retrievalToo many vectorsAdd filters, reduce TOP_K_CHUNKS
API rate limitsToo many OpenAI callsUse batching, increase RATE_LIMIT_DELAY
Memory errorsLarge documentsIncrease CHUNK_SIZE, reduce batch size
Connection errorsQdrant not runningCheck QDRANT_URL, start Qdrant service

๐Ÿ” API Usage

Chat Endpoint (Streaming)

curl -X POST "http://localhost:8000/api/v1/chat" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "What is RAG?",
    "top_k": 5,
    "similarity_threshold": 0.7
  }'

Search Endpoint

curl -X GET "http://localhost:8000/api/v1/search?query=chunking&top_k=3"

Health Check

curl -X GET "http://localhost:8000/health"

๐Ÿ“š Integration with Other Skills

This skill works seamlessly with other Claude Agent Skills:

  • ๐Ÿ“– book-structure-generator: Generate book structures and ingest them
  • โœ๏ธ content-writer: Create content and immediately make it searchable
  • ๐Ÿš€ deployment-engineer: Deploy the complete RAG system to production

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

This skill is part of the Claude Agent Skills framework and follows the same licensing terms.

๐Ÿ”— Additional Resources

rag-pipeline-builder - AI Agent Skill for Claude Code & Cursor | Agent Skills