gen_ai_rag_langchain

Gen AI RAG LangChain

A comprehensive Python project for building Retrieval-Augmented Generation (RAG) systems using LangChain.

Features

Quick Start

Prerequisites

Installation

  1. Clone the repository:
    git clone https://github.com/shyenuganti/gen_ai_rag_langchain.git
    cd gen_ai_rag_langchain
    
  2. Set up the environment: ```bash

    If using direnv

    direnv allow

Otherwise, set up manually

export PYTHONPATH=โ€${PWD}/src:${PYTHONPATH}โ€


3. Install dependencies with UV:
```bash
uv venv
uv pip install -e ".[dev,test,docs]"
  1. Copy environment file:
    cp .env.example .env
    # Edit .env with your configuration
    
  2. Install pre-commit hooks:
    uv run pre-commit install
    

Usage

Command Line Interface

# Process a query
gen-ai-rag query "What is artificial intelligence?"

# Start the API server
gen-ai-rag server --host 0.0.0.0 --port 8000

# Health check
gen-ai-rag health

Python API

from gen_ai_rag_langchain.core import RAGSystem
from gen_ai_rag_langchain.config import get_config

# Initialize the system
config = get_config()
rag_system = RAGSystem(config.__dict__)

# Process a query
result = rag_system.process_query("What is machine learning?")
print(result["response"])

REST API

Start the server:

uv run python -m gen_ai_rag_langchain.api

Then make requests:

# Health check
curl http://localhost:8000/health

# Process a query
curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{"query": "What is deep learning?"}'

Development

Running Tests

# All tests
uv run pytest

# Unit tests only
uv run pytest tests/unit/ -m "unit"

# Integration tests
uv run pytest tests/integration/ -m "integration"

# Functional tests
uv run pytest tests/functional/ -m "functional"

# With coverage
uv run pytest --cov=src/gen_ai_rag_langchain --cov-report=html

Code Quality

# Format code
uv run black src/ tests/
uv run isort src/ tests/

# Lint code
uv run flake8 src/ tests/
uv run mypy src/

# Security scan
uv run bandit -r src/
uv run safety check

Documentation

# Serve documentation locally
uv run mkdocs serve

# Build documentation
uv run mkdocs build

Deployment

Docker

# Build and run with Docker Compose
docker-compose up --build

# Or build manually
docker build -t gen-ai-rag-langchain .
docker run -p 8000:8000 gen-ai-rag-langchain

AWS ECS

  1. Configure AWS credentials and update deployment/task-definition.json
  2. Run the deployment script:
    ./deployment/deploy.sh
    

GitHub Actions

The project includes a complete CI/CD pipeline that:

Project Structure

gen_ai_rag_langchain/
โ”œโ”€โ”€ src/gen_ai_rag_langchain/     # Main package
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ core.py                   # Core RAG functionality
โ”‚   โ”œโ”€โ”€ config.py                 # Configuration management
โ”‚   โ”œโ”€โ”€ api.py                    # FastAPI web application
โ”‚   โ””โ”€โ”€ cli.py                    # Command line interface
โ”œโ”€โ”€ tests/                        # Test suite
โ”‚   โ”œโ”€โ”€ unit/                     # Unit tests
โ”‚   โ”œโ”€โ”€ integration/              # Integration tests
โ”‚   โ””โ”€โ”€ functional/               # Functional tests
โ”œโ”€โ”€ deployment/                   # Deployment configurations
โ”‚   โ”œโ”€โ”€ task-definition.json      # ECS task definition
โ”‚   โ””โ”€โ”€ deploy.sh                 # Deployment script
โ”œโ”€โ”€ docs/                         # Documentation
โ”œโ”€โ”€ .github/workflows/            # GitHub Actions
โ”œโ”€โ”€ pyproject.toml               # Project configuration
โ”œโ”€โ”€ Dockerfile                   # Container configuration
โ”œโ”€โ”€ docker-compose.yml           # Local development
โ””โ”€โ”€ mkdocs.yml                   # Documentation configuration

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Run the test suite: uv run pytest
  5. Commit your changes: git commit -am 'Add feature'
  6. Push to the branch: git push origin feature-name
  7. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

๐ŸŽฏ Project Summary

This project provides a complete, production-ready foundation for building RAG (Retrieval-Augmented Generation) applications with modern Python tooling, comprehensive testing, and deployment automation.

โœ… Features Implemented

๐Ÿš€ Modern Python Setup

๐Ÿ”ง Development Environment

๐Ÿงช Comprehensive Testing Suite

๐Ÿ”’ Code Quality & Security

๐Ÿณ Containerization & Local Development

โ˜๏ธ Cloud Deployment (AWS ECS)

๐Ÿ”„ CI/CD Pipeline (GitHub Actions)

๐Ÿ“š Documentation System

๐Ÿ–ฅ๏ธ Application Architecture

๐Ÿ› ๏ธ Developer Experience

๐Ÿ› ๏ธ Make Commands Reference

The project includes a comprehensive Makefile with commands for all development tasks:

Setup & Installation

make help              # Show all available commands
make setup             # Complete project setup (recommended first step)
make install           # Install project dependencies only
make install-dev       # Install with development dependencies
make dev-setup         # Complete development environment setup

Code Quality

make format            # Format code with black and isort
make format-check      # Check formatting without changes
make lint              # Run flake8 linting
make type-check        # Run mypy type checking
make security-check    # Run bandit and safety security checks
make check-all         # Run all quality checks

Testing

make test              # Run all tests
make test-unit         # Run unit tests only
make test-integration  # Run integration tests only
make test-functional   # Run functional tests only
make test-watch        # Run tests in watch mode
make coverage          # Generate HTML coverage report
make coverage-xml      # Generate XML coverage report
make ci-test          # Run tests with CI configuration

Development Server

make serve             # Start development server with auto-reload
make serve-prod        # Start production server
make cli-health        # Test CLI health check
make cli-query QUERY="your question"  # Test CLI query

Documentation

make docs              # Build documentation
make docs-serve        # Serve documentation locally (http://localhost:8000)
make docs-clean        # Clean documentation build files

Docker & Containers

make docker-build      # Build Docker image
make docker-run        # Run Docker container
make docker-compose-up # Start all services with docker-compose
make docker-compose-down # Stop docker-compose services
make docker-clean      # Clean Docker artifacts

Building & Packaging

make build             # Build Python package
make build-clean       # Clean build artifacts
make version           # Show current version

Cloud Deployment

make deploy            # Deploy to AWS ECS

Maintenance

make clean             # Clean all build artifacts and caches
make check-deps        # Check for outdated dependencies
make install-uv        # Install UV package manager

Examples & Help

make example-api       # Show API usage examples
make example-cli       # Show CLI usage examples

๐Ÿ”ง Key Tools & Technologies

Core Technologies

Development Environment

Code Quality Tools

Testing & Coverage

Documentation

Cloud & Deployment

Monitoring & Logging

Configuration & Environment

Acknowledgments