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.
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
- Python 3.8+
- Ollama installed and running
- Create a model from the backend/model directory
- Run the model with Ollama
- OpenAI API key
- Node.js 16+ and npm/yarn
- Modern web browser
git clone <repository-url>
cd flask_rlpt-
Create and Activate Virtual Environment:
cd backend python -m venv venv # On Windows: venv\Scripts\activate # On Unix/MacOS: source venv/bin/activate
-
Install Python Dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.envfile 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"
-
Initialize Placeholder Mapping: Ensure
backend/placeholder_mapping.jsonexists with initial structure:{ "PERSON_NAME": {}, "EMAIL": {}, "PHONE_NUMBER": {}, "ADDRESS": {}, "URL_PERSONAL": {}, "ID_NUM": {}, "USERNAME": {} } -
Ingest Sample Data:
python ingest_data.py
-
Install Node.js Dependencies:
cd ../frontend npm install # or if using yarn: yarn install
-
Configure Environment Variables: Create a
.envfile in the frontend directory:VITE_API_URL=http://localhost:5001
# From the backend directory
python app.pyThe backend server will start on http://localhost:5001
# From the frontend directory
npm run dev
# or if using yarn:
yarn devThe frontend development server will start on http://localhost:5173
The backend exposes the following endpoints:
GET /health- Health checkPOST /sanitize- Sanitize input textPOST /recover- Recover PII from textPOST /query- Query the RAG system with RLPT protectionPOST /embed_text- Add new text to vector database
For detailed API documentation, refer to the backend README.md.
- 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
- Built with React + Vite
- Uses modern React features and hooks
- ESLint configured for code quality
- Hot Module Replacement (HMR) enabled
- 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
-
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
-
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