RAG-SOP / README.md
romizone's picture
Upload folder using huggingface_hub
7a9123e verified

A newer version of the Gradio SDK is available: 6.12.0

Upgrade
metadata
title: RAG SOP Perusahaan
emoji: ๐Ÿ“‹
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 5.9.1
app_file: app.py
pinned: true

๐Ÿ“‹ RAG SOP Assistant

Intelligent Q&A System for Corporate Standard Operating Procedures

Release HF Space License Python


An AI-powered smart Q&A system that enables employees to ask questions about company procedures in natural language and receive accurate answers directly from official SOP documents.

๐Ÿš€ Try Live Demo ยท ๐Ÿ“– Documentation ยท ๐Ÿ› Report Bug


๐ŸŽฏ About

RAG SOP Assistant is an enterprise-ready, AI-powered knowledge management system designed to revolutionize how organizations interact with their Standard Operating Procedure (SOP) documents.

Built on top of the Retrieval-Augmented Generation (RAG) architecture, this system transforms static, hard-to-navigate SOP files into a dynamic, conversational knowledge base. Employees can simply type a question in natural language โ€” just like chatting with a colleague โ€” and receive accurate, context-aware answers sourced directly from official company documents.

Under the hood, the system leverages multilingual sentence embeddings to understand the semantic meaning behind every question, performs vector similarity search across all indexed documents using ChromaDB, and then passes the most relevant context to DeepSeek V3 LLM to generate a clear, well-structured answer in Indonesian.

๐Ÿงฉ Core Concepts

What is RAG? Retrieval-Augmented Generation is an AI pattern that enhances LLM responses by first retrieving relevant information from a knowledge base, then using that context to generate grounded, factual answers โ€” eliminating hallucination and ensuring accuracy.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐Ÿ“ Query โ”‚ โ”€โ”€โ–ถ โ”‚ ๐Ÿ” Search โ”‚ โ”€โ”€โ–ถ โ”‚ ๐Ÿ“„ Docs  โ”‚ โ”€โ”€โ–ถ โ”‚ ๐Ÿง  LLM   โ”‚
โ”‚          โ”‚     โ”‚ (Vectors) โ”‚     โ”‚ (Context)โ”‚     โ”‚ (Answer) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ก Why This Matters

Every organization maintains dozens โ€” sometimes hundreds โ€” of SOP documents covering everything from employee onboarding to emergency protocols. These documents are critical for compliance, consistency, and operational excellence. Yet in practice, they often collect dust in shared drives, rarely read, and hard to search.

RAG SOP Assistant solves this by making SOPs instantly accessible through conversation:

Problem Solution
๐Ÿ“š SOP documents are scattered across drives and hard to find ๐Ÿ” AI-powered semantic search across all documents at once
โฐ New employees spend weeks learning procedures manually ๐Ÿ’ฌ Instant answers through natural language Q&A
๐Ÿ”„ Critical information is buried deep inside long documents ๐Ÿ“Š Intelligent chunking & retrieval surfaces the right section
๐Ÿ“ž HR/Admin teams waste hours answering repetitive questions ๐Ÿค– AI assistant handles FAQs 24/7 with zero fatigue
๐Ÿ”Ž Keyword search fails when you don't know the exact term ๐Ÿง  Semantic understanding matches meaning, not just words
๐Ÿ“‹ Compliance audits require quick access to procedures โšก Instant lookup with source document references

๐Ÿข Use Cases

  • ๐Ÿง‘โ€๐Ÿ’ผ HR & People Ops โ€” Employee onboarding, leave policies, benefits, disciplinary procedures
  • ๐Ÿญ Operations โ€” Warehouse safety, equipment handling, quality control processes
  • ๐Ÿ’ฐ Finance & Procurement โ€” Purchase approval workflows, expense policies, vendor management
  • ๐Ÿ›ก๏ธ Compliance โ€” Regulatory procedures, audit checklists, emergency response protocols
  • ๐ŸŽ“ Training โ€” Quick reference for trainees, refresher on procedures, knowledge assessment

โœจ Key Features

Feature Description
๐Ÿ’ฌ AI Chat Natural language Q&A โ€” ask anything about your company SOPs
๐Ÿ“ค Multi-Format Upload Supports PDF, Word (.docx), and plain TXT documents
๐Ÿง  Semantic Search Meaning-based retrieval powered by multilingual embeddings
โœ‚๏ธ Smart Chunking Sentence-boundary aware splitting โ€” never cuts mid-word
๐Ÿ“Š Database Management Real-time stats, document list, and one-click database clear
๐Ÿ“„ Auto-Index on Startup Default SOP documents are automatically indexed when the app starts
๐Ÿ”’ Thread-Safe Lock-based concurrency control for safe multi-user access
๐Ÿ›ก๏ธ XSS Protected All user inputs & filenames are HTML-escaped
๐Ÿšซ Error Sanitization Sensitive information (API keys) never leaks in error messages
๐Ÿ“ Input Validation Questions capped at 1000 chars, file uploads capped at 50MB
๐ŸŽจ Premium UI Polished interface with custom CSS, gradient headers, and animations
๐Ÿ” Source Attribution Every answer includes references to the source SOP document

๐Ÿ—๏ธ Architecture & Tech Stack

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   ๐Ÿ‘ค User                        โ”‚
โ”‚              (Browser / Gradio UI)               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              ๐ŸŽจ Gradio 5.9.1                     โ”‚
โ”‚         (Premium UI + 3 Tab Interface)           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ๐Ÿ’ฌ Chat    โ”‚  ๐Ÿ“ค Upload    โ”‚  ๐Ÿ“Š Database      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚              โ”‚                 โ”‚
       โ–ผ              โ–ผ                 โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐Ÿง  DeepSeek โ”‚ โ”‚ โœ‚๏ธ Chunker โ”‚  โ”‚ ๐Ÿ“Š ChromaDB  โ”‚
โ”‚   V3 (LLM)  โ”‚ โ”‚ (Sentence โ”‚  โ”‚  (Stats &    โ”‚
โ”‚             โ”‚ โ”‚  Boundary) โ”‚  โ”‚   Manage)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚ ๐Ÿ”ฎ E5-Small   โ”‚
              โ”‚  (Embedding)  โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚ ๐Ÿ’พ ChromaDB   โ”‚
              โ”‚ (Vector Store)โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”ง Technology Stack

Layer Technology Purpose
๐ŸŽจ Frontend Gradio 5.9.1 UI Framework + Custom CSS
๐Ÿง  LLM DeepSeek-V3 Indonesian language answer generation
๐Ÿ”ฎ Embedding intfloat/multilingual-e5-small Multilingual text vector representation
๐Ÿ’พ Vector DB ChromaDB Vector storage & similarity search
๐Ÿ“„ PDF Parser PyMuPDF Text extraction from PDF files
๐Ÿ“ DOCX Parser python-docx Text extraction from Word documents

๐Ÿš€ Quick Start

Option 1: Hugging Face Spaces (Recommended)

Zero setup! Run it instantly in the cloud.

  1. Fork this Space to your HF account
  2. Add Secret: DEEPSEEK_API_KEY in Settings
  3. Wait for the build to complete (~3-5 minutes)
  4. Upload SOP documents and start asking questions!

Option 2: Local Development

# 1. Clone the repository
git clone https://github.com/romizone/RAGSOP.git
cd RAGSOP

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set your API key
export DEEPSEEK_API_KEY="your-api-key-here"

# 4. Run the application
python app.py

Open http://localhost:7860 in your browser.


๐Ÿ“– How It Works

1๏ธโƒฃ Upload & Chunking

๐Ÿ“„ SOP Document  โ†’  โœ‚๏ธ Sentence-Boundary Chunking  โ†’  ~500 char chunks

PDF/DOCX/TXT files are split into ~500 character text chunks with intelligent sentence-boundary splitting (never cuts mid-word).

2๏ธโƒฃ Embedding & Storage

๐Ÿ“ Text Chunks  โ†’  ๐Ÿ”ฎ E5-Small Embedding  โ†’  ๐Ÿ’พ ChromaDB (Cosine Similarity)

Each chunk is converted into a 384-dimensional vector and stored in ChromaDB for fast similarity search.

3๏ธโƒฃ Query & Retrieval

โ“ Question  โ†’  ๐Ÿ” Semantic Search (Top 5)  โ†’  ๐Ÿง  DeepSeek V3  โ†’  ๐Ÿ’ฌ Answer

The user's question is matched against the most relevant chunks, then the LLM generates an accurate answer based on the retrieved context.


๐Ÿ”’ Security

Feature Implementation
๐Ÿ›ก๏ธ XSS Prevention All inputs/outputs escaped via html.escape()
๐Ÿ” API Key Protection Stored as environment variable (HF Secrets)
๐Ÿšซ Error Sanitization Error messages never expose sensitive information
๐Ÿ“ Input Validation Questions capped at 1000 chars, files capped at 50MB
๐Ÿ”’ Thread Safety threading.Lock for safe concurrent access

๐Ÿ“ Project Structure

RAGSOP/
โ”œโ”€โ”€ ๐Ÿ“„ app.py              # Main application (Gradio + RAG pipeline)
โ”œโ”€โ”€ ๐Ÿ“‹ requirements.txt    # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“– README.md           # Documentation (this file)
โ”œโ”€โ”€ ๐Ÿšซ .gitignore          # Git ignore rules
โ””โ”€โ”€ ๐Ÿ“‚ SOP/                # Default SOP documents (auto-indexed)
    โ”œโ”€โ”€ Kumpulan_SOP_Perusahaan.pdf
    โ”œโ”€โ”€ Pelatihan staf_8.pdf
    โ”œโ”€โ”€ Penggunaan teknologi_7.pdf
    โ”œโ”€โ”€ Penyimpanan dan pemeliharaan_4.pdf
    โ””โ”€โ”€ SOP darurat_5.pdf

๐Ÿ“Š Performance

Metric Value
โฑ๏ธ Startup Time ~30-60s (includes model loading)
๐Ÿ“„ Default SOP Files 5 documents, ~256 chunks
๐Ÿ”ฎ Embedding Model Size ~470MB
๐Ÿ’ฌ Query Response Time ~3-5s per question
๐Ÿ’พ Hardware CPU Basic (2 vCPU, 16GB RAM)

๐Ÿ—บ๏ธ Roadmap

  • v1.0 โ€” Core RAG + Premium UI + Auto-indexing
  • v1.1 โ€” Persistent storage (data survives restart)
  • v1.2 โ€” Multi-language support (EN/ID)
  • v1.3 โ€” Document version tracking
  • v2.0 โ€” Authentication + multi-tenant support

๐Ÿค Contributing

Contributions are welcome! Feel free to open an Issue or submit a Pull Request.


๐Ÿ‘จโ€๐Ÿ’ป Author

Romi Nur Ismanto


Built with โค๏ธ using ChromaDB ยท DeepSeek ยท Multilingual E5 ยท Gradio

Star