Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

RAG-Project

📑 Explainer Deck (RAG Project)

Explainer Deck is a highly responsive and resource-efficient Retrieval-Augmented Generation (RAG) platform designed to analyze long-form documents such as technical manuals, research papers, reports, and financial statements.

The platform retrieves relevant information from indexed documents and generates precise, context-grounded answers while minimizing hallucinations.

Powered by a Node.js/TypeScript backend, the application leverages the low-latency inference capabilities of the Groq Cloud API to deliver fast and context-aware responses to user queries.


🏗️ Architecture Blueprint

The project is designed to run alongside other applications, such as EduMind, within a shared cloud environment such as an AWS EC2 instance.

Nginx acts as the reverse proxy and handles path-based routing, while PM2 manages the Explainer Deck backend process.

       [ Public Web Traffic: Port 80 ]
                      │
                      ▼
             ┌─────────────────┐
             │   Nginx Proxy   │
             └────────┬────────┘
                      │
       ┌──────────────┴──────────────┐
       │                             │
       ▼ /                           ▼ /explainer/
┌──────────────┐           ┌─────────────────────────┐
│   EduMind    │           │     Explainer Deck      │
│ (Python App) │           │  (Node.js/TypeScript)   │
│  Port 8000   │           │       Port 5001         │
└──────────────┘           └────────────┬────────────┘
                                       │
                                       ▼
                              [ Managed by PM2 ]
                              [ Executed via tsx ]
                                       │
                                       ▼
                          ┌─────────────────────────┐
                          │  apps/backend/src/...   │
                          └────────────┬────────────┘
                                       │
                    ┌──────────────────┴──────────────────┐
                    │                                     │
                    ▼                                     ▼
        ┌───────────────────────┐             ┌───────────────────────┐
        │   Vector Store / DB   │             │    Groq Cloud API     │
        │ (Document Embeddings) │             │  (Fast LLM Inference) │
        └───────────────────────┘             └───────────────────────┘

⚙️ Infrastructure Components

🌐 Nginx

Nginx acts as the main ingress router and reverse proxy for applications running on the server.

The routing structure is:

/             → EduMind (Port 8000)
/explainer/   → Explainer Deck (Port 5001)

This architecture allows multiple applications to run on the same AWS EC2 instance while remaining accessible through separate URL paths.


🔄 PM2

PM2 is used as the production process manager for the Explainer Deck backend.

It provides:

  • 24/7 background process execution
  • Automatic application restart after crashes
  • Process monitoring
  • Log management
  • Server reboot persistence

⚡ TypeScript Runtime (tsx)

The backend is executed directly using tsx.

This avoids requiring a separate TypeScript compilation step during application startup and provides a lightweight development and deployment workflow.

In the current deployment environment, using tsx with PM2 helped significantly reduce the observed memory footprint compared with the previous execution setup.


📁 Project Structure

RAG-Project/
│
├── apps/
│   └── backend/
│       ├── src/
│       │   ├── index.ts
│       │   └── ...
│       │
│       ├── .env
│       └── package.json
│
├── package.json
└── README.md

The exact project structure may vary depending on additional frontend, shared package, or infrastructure components.


🚀 Deployment & Local Operation

Prerequisites

Before running the application, make sure the following tools are installed:

  • Node.js v18 or higher
  • npm
  • PM2
  • tsx
  • Nginx (for production reverse-proxy deployment)

Install PM2 globally:

npm install -g pm2

Install tsx globally:

npm install -g tsx

🔐 Environment Configuration

Create an .env file inside the backend directory:

apps/backend/.env

Example configuration:

PORT=5001

GROQ_API_KEY=your_secret_groq_api_token

# Add database configuration here
# DATABASE_URL=your_database_url

# Add vector database configuration here
# VECTOR_DB_API_KEY=your_vector_database_key

# Add embedding provider configuration here
# EMBEDDING_API_KEY=your_embedding_api_key

⚠️ Never commit your .env file or API keys to GitHub.

Add .env to your .gitignore file:

.env
node_modules/
dist/

▶️ Starting the Application

Navigate to the project root:

cd /home/ubuntu/RAG-Project

Start the Explainer Deck backend using PM2 and tsx:

PORT=5001 pm2 start tsx --name "explainer-deck" -- apps/backend/src/index.ts

Check whether the application is running:

pm2 status

Save the PM2 process configuration:

pm2 save

To configure PM2 to automatically start applications after a server reboot:

pm2 startup

Run the command generated by PM2, then save the process list again:

pm2 save

🛠️ Diagnostics & Maintenance

Check Application Status

pm2 status

This displays:

  • Application status
  • Process ID
  • CPU usage
  • Memory usage
  • Restart count
  • Uptime

View Application Logs

View live logs for Explainer Deck:

pm2 logs explainer-deck

View recent log lines:

pm2 logs explainer-deck --lines 100

Restart the Application

pm2 restart explainer-deck

Stop the Application

pm2 stop explainer-deck

Delete the PM2 Process

pm2 delete explainer-deck

🌐 Nginx Configuration

The production environment uses Nginx to route incoming requests between applications.

Example routing configuration:

server {
    listen 80;
    server_name _;

    location / {
        proxy_pass http://127.0.0.1:8000;

        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /explainer/ {
        proxy_pass http://127.0.0.1:5001/;

        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

After modifying the Nginx configuration, test it:

sudo nginx -t

If the configuration is valid, reload Nginx:

sudo systemctl reload nginx

Check Nginx status:

sudo systemctl status nginx

🔄 Application Request Flow

The basic RAG request flow is:

User
  │
  ▼
Explainer Deck Interface
  │
  ▼
Nginx Reverse Proxy
  │
  ▼
Node.js / TypeScript Backend
  │
  ▼
User Query Processing
  │
  ▼
Vector Store Search
  │
  ▼
Relevant Document Chunks
  │
  ▼
Context Construction
  │
  ▼
Groq Cloud API
  │
  ▼
Context-Grounded Response
  │
  ▼
User

✨ Core Features

  • 📄 Long-form document analysis
  • 🔍 Semantic document retrieval
  • 🧠 Retrieval-Augmented Generation (RAG)
  • 💬 Context-aware question answering
  • ⚡ Low-latency LLM inference using Groq
  • 🧩 Semantic document chunking
  • 📚 Context-grounded answer generation
  • 🏷️ Document metadata tracking
  • 🔎 Relevant context retrieval
  • 🚀 Lightweight TypeScript execution using tsx
  • 🔄 Production process management using PM2
  • 🌐 Nginx path-based reverse proxy routing
  • ☁️ Cloud deployment support
  • 🖥️ Multi-application deployment architecture

🎯 Target Users

Explainer Deck is designed for:

  • Research analysts
  • Students and researchers
  • Technical developers
  • Financial analysts
  • Information workers
  • Professionals working with large document collections

The platform is particularly useful when users need to quickly retrieve and understand information contained within large or complex documents.


🛡️ Security Recommendations

For production deployments:

  • Never expose API keys in source code.
  • Keep .env files outside version control.
  • Restrict unnecessary EC2 inbound ports.
  • Expose applications through Nginx instead of directly exposing backend ports.
  • Configure HTTPS using SSL/TLS.
  • Regularly update Node.js dependencies.
  • Monitor PM2 logs for unexpected errors.
  • Rotate API credentials periodically.

📊 Production Stack

Component Technology
Backend Node.js / TypeScript
TypeScript Runtime tsx
AI Inference Groq Cloud API
Architecture Retrieval-Augmented Generation (RAG)
Document Retrieval Vector Store
Process Manager PM2
Reverse Proxy Nginx
Cloud Infrastructure AWS EC2
Explainer Deck Port 5001
EduMind Port 8000

🔮 Future Improvements

Potential future enhancements include:

  • Multi-document conversational sessions
  • Advanced document citation support
  • Source-level answer references
  • Streaming AI responses
  • User authentication
  • Conversation history
  • Document management dashboard
  • Improved embedding and reranking pipelines
  • Hybrid semantic and keyword search
  • HTTPS/SSL production configuration
  • Docker-based deployment
  • CI/CD deployment pipeline
  • Horizontal scaling support

📌 Project Goal

The goal of Explainer Deck is to provide a fast, scalable, and resource-efficient platform for extracting meaningful insights from complex documents.

By combining semantic document retrieval with high-speed LLM inference, the system aims to provide reliable, context-grounded responses while minimizing hallucinations and reducing the time required to manually search through large documents.


📄 License

This project is intended for educational, research, and development purposes.


👨‍💻 Author

Abhishek Pandey

Developer and AI enthusiast focused on building practical AI-powered applications, Retrieval-Augmented Generation systems, and scalable cloud-deployed software solutions.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages