8000 GitHub - Aloulou-ahmed/dsi_rag Β· GitHub
[go: up one dir, main page]

Skip to content
Aloulou-ahmedPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

πŸ₯ DSI-RAG - Decoy-based Secure Intelligence RAG

Secure RAG system with PII anonymization and decoy generation for medical data protection

Python FastAPI Groq


🎯 Overview

DSI-RAG is an advanced RAG (Retrieval-Augmented Generation) system designed to protect sensitive medical data using:

  • 🎭 PII Anonymization: Dual-layer detection (Presidio + GLiNER)
  • 🎲 Decoy Generation: Creates fake chunks to protect real data
  • πŸ” Secure Vault: Local storage for PII mappings and labels
  • πŸ’Ύ Vector Store: Cloud-simulated storage (ChromaDB)
  • πŸ”“ De-anonymization: Restores PII in final answers

πŸ—οΈ Architecture

INGESTION PIPELINE
------------------
Document β†’ Extract β†’ Anonymize (Presidio + GLiNER) β†’ Chunk
                ↓
            Vault (PII Mapping)
                ↓
    Generate Decoys (Groq) β†’ Mix Real + Decoys β†’ Embed β†’ Vector Store

QUERY PIPELINE
--------------
Question β†’ Semantic Search β†’ Filter Decoys (Vault) β†’ Generate Answer (Groq)
                                ↓
                        De-anonymize β†’ Final Answer

✨ Features

Security

  • βœ… Dual PII Detection: Presidio (regex) + GLiNER (ML-based)
  • βœ… Decoy Protection: Fake chunks mixed with real data
  • βœ… Local Vault: Trusted zone for sensitive mappings
  • βœ… Zero-knowledge Vector Store: No labels exposed

Performance

  • ⚑ Fast Generation: Groq API for decoys and answers
  • πŸ”„ Parallel Processing: Multi-threaded decoy generation
  • πŸ“Š Performance Metrics: Built-in timing indicators

Developer Experience

  • 🐍 Modern Python: Type hints, async/await
  • πŸ“ Comprehensive Logging: Debug-friendly
  • πŸ§ͺ Test Pipeline: End-to-end testing script
  • πŸ“š Full Documentation: Multiple guides

πŸš€ Quick Start

1. Prerequisites

2. Installation

# Clone the repository
git clone https://github.com/Aloulou-ahmed/dsi_rag.git
cd dsi_rag

# Create virtual environment
python -m venv venv
.\venv\Scripts\activate  # Windows
# source venv/bin/activate  # Linux/Mac

# Install dependencies
pip install -r requirements.txt

# Download spaCy model
python -m spacy download en_core_web_lg

3. Configuration

# Copy environment template
copy .env.example .env  # Windows
# cp .env.example .env  # Linux/Mac

# Edit .env and add your Groq API key
# Get your key at: https://console.groq.com
GROQ_API_KEY=your_actual_key_here

4. Verify Setup

python verify_setup.py

5. Test the System

python test_pipeline.py Patient.pdf

πŸ“Š Performance

Tested on Patient.pdf (2524 characters):

Stage Time %
Extraction 0.16s 0.6%
Anonymization 19.19s 73.8%
Chunking 0.00s 0.0%
Decoys (Groq) 4.35s 16.8%
Vault Storage 0.09s 0.3%
Embedding 0.65s 2.5%
Retrieval 0.03s 0.1%
Answer (Groq) 1.51s 5.8%
TOTAL 26.0s 100%

πŸ”§ API Endpoints

Upload Document

POST /documents/upload
Content-Type: multipart/form-data

Response:
{
  "doc_id": "abc123",
  "pii_count": 41,
  "total_chunks": 14,
  "real_chunks": 7,
  "decoy_chunks": 7,
  "processing_time": 26.0
}

Query Document

POST /chat
Content-Type: application/json

{
  "doc_id": "abc123",
  "question": "What is the diagnosis?"
}

Response:
{
  "answer": "The patient has been diagnosed with...",
  "sources": [...],
  "retrieved_total": 8,
  "decoys_filtered": 7
}

Health Check

GET /health

πŸ“ Project Structure

backend/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/              # API endpoints
β”‚   β”œβ”€β”€ core/             # Core business logic
β”‚   β”‚   β”œβ”€β”€ anonymizer.py       # PII detection
β”‚   β”‚   β”œβ”€β”€ decoy_generator.py  # Groq-based decoys
β”‚   β”‚   β”œβ”€β”€ rag_chain.py        # Answer generation
β”‚   β”‚   β”œβ”€β”€ retriever.py        # Filtered retrieval
β”‚   β”‚   β”œβ”€β”€ vector_store.py     # ChromaDB interface
β”‚   β”‚   └── vault.py            # Secure storage
β”‚   β”œβ”€β”€ models/           # Pydantic models
β”‚   β”œβ”€β”€ utils/            # Utilities
β”‚   β”œβ”€β”€ config.py         # Configuration
β”‚   └── main.py           # FastAPI app
β”œβ”€β”€ data/                 # Data storage (gitignored)
β”œβ”€β”€ test_pipeline.py      # E2E test script
β”œβ”€β”€ verify_setup.py       # Setup verification
└── requirements.txt      # Dependencies

πŸ“š Documentation


πŸ” Security Considerations

⚠️ Before Production

  1. Encrypt Vault: Use SQLCipher
  2. Add Authentication: JWT or API keys
  3. Enable HTTPS: Reverse proxy with SSL
  4. Validate Uploads: File type, size limits
  5. Rate Limiting: Prevent abuse

See ANALYSE_RAG_BACKEND.md for security details.


πŸ§ͺ Testing

# Full pipeline test
python test_pipeline.py your_document.pdf

# Verify installation
python verify_setup.py

# Run API server
uvicorn app.main:app --reload

# API documentation
http://localhost:8000/docs

πŸ› οΈ Technology Stack

  • FastAPI - REST API framework
  • Groq API - LLM inference (decoys + answers)
  • Presidio - PII detection (regex)
  • GLiNER - PII detection (ML)
  • ChromaDB - Vector database
  • Sentence Transformers - Embeddings
  • LangChain - Text processing

πŸ“ˆ Roadmap

  • πŸ” Vault encryption (SQLCipher)
  • πŸ”‘ JWT authentication
  • πŸ§ͺ Unit tests (pytest)
  • 🐳 Docker deployment
  • πŸ“Š Monitoring dashboard
  • 🌐 Multi-language support

🀝 Contributing

Contributions are welcome! Please:

  1. Read the documentation
  2. Follow existing code style
  3. Add tests for new features
  4. Update documentation

πŸ“„ License

Proprietary - Internal use only


πŸ‘₯ Authors

  • Project Lead: Medical AI Security Team
  • RAG Architecture: DSI Team
  • Version 2.0: Groq API Integration

πŸ†˜ Support

For issues or questions:

  1. Check INSTALLATION_GUIDE.md
  2. Review PROBLEMS_SUMMARY.md
  3. Examine logs in data/logs/
  4. Create an issue on GitHub

πŸ™ Acknowledgments

Built with ❀️ to protect sensitive medical data

Version: 2.0
Status: Production Ready (with security hardening)
Last Updated: January 2026

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0