Skip to content

vinhnt21/RLPT_Framework_Prototype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RLPT Framework Prototype

This project is a full-stack implementation of the RLPT (RAG Local Placeholder Tagging) framework, consisting of a Flask backend and React frontend. The system demonstrates how to protect sensitive data in Retrieval Augmented Generation (RAG) workflows by identifying PII using a local LLM, sanitizing inputs by replacing PII with placeholders, and recovering the original PII in the final output.

Project Structure

flask_rlpt/
├── backend/                 # Flask backend application
│   ├── app.py              # Main Flask application
│   ├── config.py           # Configuration loader
│   ├── requirements.txt    # Python dependencies
│   ├── data/              # Sample data for vector DB
│   ├── vector_store/      # ChromaDB persistence directory
│   ├── model/             # Model directory
│   ├── rlpt/              # Core RLPT logic
│   └── README.md          # Backend documentation
│
├── frontend/               # React frontend application
│   ├── src/               # Source code
│   ├── public/            # Static assets
│   ├── package.json       # Node.js dependencies
│   └── README.md          # Frontend documentation
│
└── README.md              # This file

Prerequisites

Backend Requirements

  • Python 3.8+
  • Ollama installed and running
    • Create a model from the backend/model directory
    • Run the model with Ollama
  • OpenAI API key

Frontend Requirements

  • Node.js 16+ and npm/yarn
  • Modern web browser

Setup Instructions

1. Clone the Repository

git clone <repository-url>
cd flask_rlpt

2. Backend Setup

  1. Create and Activate Virtual Environment:

    cd backend
    python -m venv venv
    # On Windows:
    venv\Scripts\activate
    # On Unix/MacOS:
    source venv/bin/activate
  2. Install Python Dependencies:

    pip install -r requirements.txt
  3. Configure Environment Variables: Create a .env file in the backend directory:

    OPENAI_API_KEY="your_openai_api_key_here"
    OLLAMA_BASE_URL="http://localhost:11434"
    LOCAL_NER_MODEL_NAME="DebertaV3_For_NER"
    RAG_EMBEDDING_MODEL_NAME="text-embedding-3-small"
    RAG_GENERATIVE_MODEL_NAME="gpt-4.1-mini-2025-04-14"
    CHROMA_DB_PATH="./vector_store"
    PLACEHOLDER_MAPPING_FILE="./placeholder_mapping.json"
    SAMPLE_DOCUMENTS_PATH="./data/sample_documents.txt"
  4. Initialize Placeholder Mapping: Ensure backend/placeholder_mapping.json exists with initial structure:

    {
        "PERSON_NAME": {},
        "EMAIL": {},
        "PHONE_NUMBER": {},
        "ADDRESS": {},
        "URL_PERSONAL": {},
        "ID_NUM": {},
        "USERNAME": {}
    }
  5. Ingest Sample Data:

    python ingest_data.py

3. Frontend Setup

  1. Install Node.js Dependencies:

    cd ../frontend
    npm install
    # or if using yarn:
    yarn install
  2. Configure Environment Variables: Create a .env file in the frontend directory:

    VITE_API_URL=http://localhost:5001

Running the Application

1. Start the Backend Server

# From the backend directory
python app.py

The backend server will start on http://localhost:5001

2. Start the Frontend Development Server

# From the frontend directory
npm run dev
# or if using yarn:
yarn dev

The frontend development server will start on http://localhost:5173

API Endpoints

The backend exposes the following endpoints:

  • GET /health - Health check
  • POST /sanitize - Sanitize input text
  • POST /recover - Recover PII from text
  • POST /query - Query the RAG system with RLPT protection
  • POST /embed_text - Add new text to vector database

For detailed API documentation, refer to the backend README.md.

Development

Backend Development

  • The backend uses Flask for the API server
  • Core RLPT logic is in the backend/rlpt/ directory
  • Vector store uses ChromaDB
  • Local LLM (Ollama) handles PII detection

Frontend Development

  • Built with React + Vite
  • Uses modern React features and hooks
  • ESLint configured for code quality
  • Hot Module Replacement (HMR) enabled

Notes

  • The backend must be running for the frontend to function properly
  • Ensure Ollama is running with the correct model before starting the backend
  • The system uses placeholder mapping to protect PII throughout the RAG pipeline
  • Both frontend and backend have their own detailed README files for specific documentation

Troubleshooting

  1. Backend Issues:

    • Check if Ollama is running and accessible
    • Verify OpenAI API key is valid
    • Ensure all environment variables are set correctly
    • Check vector store permissions
  2. Frontend Issues:

    • Clear browser cache if UI is not updating
    • Check browser console for errors
    • Verify backend API URL in frontend environment variables
    • Ensure all dependencies are installed

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published