Skip to content

ChengYuChuan/adaptive-intelligence-pipeline

Repository files navigation

Adaptive Intelligence Pipeline (AIP)

A production-ready, switchable-component AI information integration system with RAG (Retrieval-Augmented Generation) capabilities for enterprise document Q&A.

Python FastAPI License


🎯 Project Overview

AIP is designed to solve two core enterprise needs:

  1. Information Integration Pipeline: Aggregate data from multiple sources (arXiv, NewsAPI), analyze with LLM, and deliver reports to various destinations (Email, Notion, Slack)

  2. Enterprise Document Q&A (RAG): Upload internal documents and ask questions with source citations - perfect for company policies, technical docs, and knowledge bases

Key Features

Feature Description
πŸ”Œ Switchable Components Swap LLM/Source/Output providers via environment variables
πŸ” RAG System Upload documents, ask questions, get answers with citations
🏒 Enterprise Ready AWS Bedrock & Azure support for data privacy
πŸ“Š Multi-format Support PDF, Word, Markdown document processing

πŸ—οΈ Architecture

                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚            FastAPI                  β”‚
                         β”‚         (REST API Layer)            β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                          β”‚                          β”‚
              β–Ό                          β–Ό                          β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚    Pipeline     β”‚      β”‚   RAG Service   β”‚      β”‚    Document     β”‚
     β”‚    Service      β”‚      β”‚   (Q&A)         β”‚      β”‚   Processor     β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                        β”‚                        β”‚
              β–Ό                        β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            Adapter Layer                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  LLM Adapter  β”‚  β”‚Source Adapter β”‚  β”‚Output Adapter β”‚  β”‚Vector Store   β”‚ β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚  β”‚ β€’ Claude API  β”‚  β”‚ β€’ arXiv       β”‚  β”‚ β€’ Console     β”‚  β”‚ β€’ Chroma      β”‚ β”‚
β”‚  β”‚ β€’ AWS Bedrock β”‚  β”‚ β€’ NewsAPI     β”‚  β”‚ β€’ Notion      β”‚  β”‚ β€’ PgVector    β”‚ β”‚
β”‚  β”‚ β€’ Azure OpenAIβ”‚  β”‚ β€’ Internal DB β”‚  β”‚ β€’ Email       β”‚  β”‚ β€’ Azure AI    β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                          β”‚
β”‚  β”‚   Embedding   β”‚                                                          β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€                                                          β”‚
β”‚  β”‚ β€’ OpenAI      β”‚                                                          β”‚
β”‚  β”‚ β€’ Bedrock     β”‚                                                          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Design Principles:

  • Dependency Inversion: All adapters implement abstract interfaces
  • Factory Pattern: Runtime provider selection via configuration
  • Single Responsibility: Each adapter handles one specific task

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • uv (recommended) or pip
  • API Keys: Anthropic (Claude) and/or OpenAI

Installation

# Clone repository
git clone https://github.com/ChengYuChuan/adaptive-intelligence-pipeline.git
cd adaptive-intelligence-pipeline

# Install with uv (recommended)
uv sync

# Or with pip
pip install -r requirements.txt

Configuration

# Copy example environment file
cp .env.example .env

# Edit .env with your API keys

Minimum configuration:

# LLM
LLM_PROVIDER=claude
ANTHROPIC_API_KEY=sk-ant-api03-xxxxx

# RAG (for document Q&A)
EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-xxxxx
VECTORSTORE_PROVIDER=chroma

Run the Server

# With uv
uv run uvicorn app.main:app --reload

# Or directly
uvicorn app.main:app --reload

Open http://localhost:8000/docs for the Swagger UI.


πŸ“– Usage Guide

1. Pipeline: Information Integration

Fetch data from sources, analyze with LLM, and output reports.

# Academic paper tracking
curl -X POST "http://localhost:8000/pipeline/run" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "machine learning transformers",
    "template": "academic",
    "max_results": 10,
    "date_range": "last_week"
  }'

# Financial news analysis
curl -X POST "http://localhost:8000/pipeline/run" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "TSMC NVIDIA semiconductor",
    "template": "financial",
    "max_results": 20,
    "date_range": "today"
  }'

2. RAG: Document Q&A

Upload documents and ask questions with source citations.

Step 1: Upload Documents

# Upload a PDF
curl -X POST "http://localhost:8000/documents/upload" \
  -F "file=@company_policy.pdf" \
  -F "tags=policy,hr" \
  -F "description=Employee handbook 2024" \
  -F "collection_name=default"

# Upload Markdown
curl -X POST "http://localhost:8000/documents/upload" \
  -F "file=@technical_guide.md" \
  -F "tags=technical,engineering" \
  -F "collection_name=default"

Step 2: Ask Questions

curl -X POST "http://localhost:8000/ask" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What is the remote work policy?",
    "collection_name": "default",
    "top_k": 5,
    "include_sources": true
  }'

Response:

{
  "question": "What is the remote work policy?",
  "answer": "According to the Employee Handbook, employees may work remotely up to 3 days per week with manager approval...",
  "sources": [
    {
      "filename": "company_policy.pdf",
      "content_preview": "Remote Work Guidelines: Employees may...",
      "relevance_score": 0.89,
      "page_number": 15
    }
  ],
  "retrieval_time_ms": 150,
  "generation_time_ms": 2500
}

Step 3: Manage Collections

# List collections
curl http://localhost:8000/rag/collections

# Get collection stats
curl http://localhost:8000/rag/collections/default/stats

# Delete collection
curl -X DELETE http://localhost:8000/rag/collections/default

πŸ”§ Configuration Reference

Provider Options

Category Options Default
LLM claude, bedrock, azure claude
Source arxiv, newsapi, internal arxiv
Output console, notion, email, slack console
Vector Store chroma, pgvector, azure chroma
Embedding openai, bedrock, local openai

Full .env Example

# ===== LLM Settings =====
LLM_PROVIDER=claude
ANTHROPIC_API_KEY=sk-ant-xxxxx
CLAUDE_MODEL=claude-sonnet-4-20250514

# AWS Bedrock (alternative)
# LLM_PROVIDER=bedrock
# AWS_REGION=us-west-2
# AWS_ACCESS_KEY_ID=xxxxx
# AWS_SECRET_ACCESS_KEY=xxxxx

# ===== Source Settings =====
SOURCE_PROVIDER=arxiv
NEWSAPI_KEY=xxxxx  # For financial analysis

# ===== Output Settings =====
OUTPUT_PROVIDER=console
# Email settings
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password
EMAIL_FROM=your-email@gmail.com
EMAIL_TO=recipient@example.com

# ===== RAG Settings =====
VECTORSTORE_PROVIDER=chroma
CHROMA_PERSIST_DIR=./data/vectorstore

EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-xxxxx
OPENAI_EMBEDDING_MODEL=text-embedding-3-small

# Document Processing
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
MAX_FILE_SIZE_MB=50

# ===== General =====
DEBUG=true
LOG_LEVEL=INFO

πŸ“Š API Endpoints

System

Method Endpoint Description
GET / API information
GET /health Health check with provider info
GET /config Current configuration

Pipeline

Method Endpoint Description
POST /pipeline/run Execute data pipeline

RAG

Method Endpoint Description
POST /documents/upload Upload document for processing
POST /ask Ask question about documents
GET /rag/health RAG system health
GET /rag/collections List all collections
GET /rag/collections/{name}/stats Collection statistics
DELETE /rag/collections/{name} Delete collection

πŸ“ Project Structure

adaptive-intelligence-pipeline/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py                    # FastAPI application
β”‚   β”œβ”€β”€ config.py                  # Environment settings
β”‚   β”‚
β”‚   β”œβ”€β”€ adapters/                  # Switchable components
β”‚   β”‚   β”œβ”€β”€ llm/                   # LLM providers
β”‚   β”‚   β”‚   β”œβ”€β”€ base.py
β”‚   β”‚   β”‚   β”œβ”€β”€ claude_api.py      # βœ… Implemented
β”‚   β”‚   β”‚   └── bedrock.py         # βœ… Implemented
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ source/                # Data sources
β”‚   β”‚   β”‚   β”œβ”€β”€ base.py
β”‚   β”‚   β”‚   β”œβ”€β”€ arxiv.py           # βœ… Implemented
β”‚   β”‚   β”‚   └── newsapi.py         # βœ… Implemented
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ output/                # Output destinations
β”‚   β”‚   β”‚   β”œβ”€β”€ base.py
β”‚   β”‚   β”‚   β”œβ”€β”€ console.py         # βœ… Implemented
β”‚   β”‚   β”‚   β”œβ”€β”€ notion.py          # βœ… Implemented
β”‚   β”‚   β”‚   └── email.py           # βœ… Implemented
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ vectorstore/           # Vector databases
β”‚   β”‚   β”‚   β”œβ”€β”€ base.py
β”‚   β”‚   β”‚   β”œβ”€β”€ chroma.py          # βœ… Implemented
β”‚   β”‚   β”‚   └── pgvector.py        # πŸ“… Week 4
β”‚   β”‚   β”‚
β”‚   β”‚   └── embedding/             # Embedding services
β”‚   β”‚       β”œβ”€β”€ base.py
β”‚   β”‚       └── openai.py          # βœ… Implemented
β”‚   β”‚
β”‚   β”œβ”€β”€ services/                  # Business logic
β”‚   β”‚   β”œβ”€β”€ pipeline.py            # Data pipeline orchestration
β”‚   β”‚   β”œβ”€β”€ document_processor.py  # Document parsing & chunking
β”‚   β”‚   └── rag.py                 # RAG Q&A service
β”‚   β”‚
β”‚   β”œβ”€β”€ schemas/                   # Pydantic models
β”‚   β”‚   β”œβ”€β”€ pipeline.py
β”‚   β”‚   β”œβ”€β”€ document.py
β”‚   β”‚   └── rag.py
β”‚   β”‚
β”‚   └── prompts/                   # LLM prompt templates
β”‚       β”œβ”€β”€ academic_summary.py
β”‚       └── financial_analysis.py
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ documents/                 # Uploaded documents
β”‚   └── vectorstore/               # Chroma persistence
β”‚
β”œβ”€β”€ tests/
β”œβ”€β”€ .github/workflows/ci.yml
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ pyproject.toml
└── README.md

πŸ› οΈ Tech Stack

Core

  • Framework: FastAPI 0.115+
  • Package Manager: uv (recommended) / pip
  • Validation: Pydantic 2.10+

LLM & AI

  • Claude: anthropic 0.39+
  • AWS Bedrock: boto3 1.35+
  • OpenAI Embedding: openai 1.12+

RAG

  • Vector Store: chromadb 0.4+
  • PDF Parsing: PyMuPDF 1.23+
  • Word Parsing: python-docx 1.1+
  • Tokenization: tiktoken 0.5+

Data Sources

  • arXiv: arxiv 2.1+
  • News: newsapi-python 0.2+

Output

  • Email: aiosmtplib 3.0+
  • HTTP Client: httpx 0.27+

πŸ“ˆ Development Roadmap

Completed

  • Week 1: Core Architecture

    • FastAPI + Adapter Pattern
    • Claude API LLM adapter
    • arXiv source adapter
    • Console & Notion output adapters
  • Week 2: Enterprise Adapters

    • AWS Bedrock LLM adapter
    • NewsAPI source adapter
    • Email output adapter
  • Week 3: RAG System

    • Chroma vector store adapter
    • OpenAI embedding adapter
    • Document processing (PDF/Word/Markdown)
    • Question answering with citations
    • Collection management APIs

In Progress

  • Week 4: Production Ready + Basic Monitoring
    • PostgreSQL + pgvector adapter (AWS RDS / Azure)
    • Bedrock Titan Embedding adapter
    • Structured logging (JSON format)
    • /metrics endpoint (Prometheus format)
    • Basic monitoring dashboard

Planned

  • Week 5+: Advanced Operations
    • Full Prometheus + Grafana deployment
    • Distributed tracing (OpenTelemetry)
    • Alert configuration
    • Cost monitoring dashboard
    • n8n/Airflow scheduling integration
    • Web dashboard UI

πŸ” Security Considerations

Data Privacy by Provider

Provider Data Location Best For
Claude API Anthropic servers Development, demos
AWS Bedrock Your AWS account Enterprise, regulated industries
Azure OpenAI Your Azure tenant Enterprise, Azure ecosystem

API Key Security

  • βœ… Use .env files (never commit to git)
  • βœ… Use AWS Secrets Manager / Azure Key Vault in production
  • βœ… Rotate credentials regularly
  • βœ… Use IAM roles instead of access keys when possible

πŸ§ͺ Testing

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=app --cov-report=html

# Run specific tests
uv run pytest app/tests/test_rag.py -v

🐳 Docker Deployment

# Build and run
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit changes: git commit -m 'Add my feature'
  4. Push to branch: git push origin feature/my-feature
  5. Open a Pull Request

πŸ“„ License

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


πŸ‘€ Author

Yu-Chuan (Louis) Cheng

  • MSc Scientific Computing, Heidelberg University
  • Specialization: Machine Learning & Generative AI
  • GitHub: @ChengYuChuan
  • LinkedIn: Yu-Chuan Cheng

πŸ™ Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages