Skip to content

OpenVanguard/Solace-AI-RAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Solace AI RAG πŸ€–πŸ’™

Python FastAPI MongoDB OpenAI License

Intelligent RAG-powered chatbot for NGOs and social organizations to provide instant, context-aware assistance about donations, events, feedback, and community activities.

Solace AI RAG transforms your organization's data into an intelligent conversational assistant that helps visitors get instant answers about your work, impact, and ways to contribute.

🌟 Features

🧠 Intelligent RAG System

  • Vector Search: Semantic similarity using sentence transformers
  • Context-Aware Responses: GPT-powered responses based on your actual data
  • Multi-Source Integration: Donations, events, feedback, and posts in one system
  • Real-time Updates: Automatic knowledge base refresh when data changes

πŸš€ Production-Ready API

  • RESTful Endpoints: Easy integration with any website or application
  • High Performance: FAISS vector database for lightning-fast searches
  • Scalable Architecture: Handles multiple concurrent users
  • Comprehensive Monitoring: Health checks, analytics, and performance metrics

πŸ›‘οΈ Enterprise Security

  • API Authentication: Secure API key-based access control
  • Rate Limiting: Prevents abuse and ensures fair usage
  • Input Validation: Protects against malicious inputs
  • CORS Support: Configurable cross-origin resource sharing

πŸ“Š Analytics & Insights

  • Usage Tracking: Monitor chat interactions and user engagement
  • Performance Metrics: Response times and system health monitoring
  • Data Statistics: Real-time insights into your organization's data

🎯 Use Cases

  • Donor Support: "How can I donate?" "What projects need funding?"
  • Event Information: "What events are happening this month?" "Where is the next meetup?"
  • Impact Stories: "What has our organization achieved?" "Show me recent feedback"
  • Volunteer Coordination: "How can I help?" "What volunteer opportunities are available?"

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   FastAPI        β”‚    β”‚   MongoDB       β”‚
β”‚   (React)       │◄──►│   RAG Server     │◄──►│   Atlas         β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   OpenAI GPT     β”‚
                       β”‚   + Vector DB    β”‚
                       β”‚   (FAISS)        β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.10
  • MongoDB Atlas account
  • OpenAI API key

1. Clone Repository

git clone https://github.com/OpenVanguard/Solace-AI-RAG.git
cd Solace-AI-RAG

2. Setup Environment

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

3. Configure Environment Variables

Create .env file:

MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/
DB_NAME=your_ngo_database
OPENAI_API_KEY=sk-your-openai-api-key-here
API_SECRET_KEY=your-secret-api-key
ENVIRONMENT=development

4. Run the Server

# Development
python main.py

# Production
uvicorn main:app --host 0.0.0.0 --port 8000

Your API will be available at http://localhost:8000

5. Test the API

curl -X POST "http://localhost:8000/chat" \
     -H "Content-Type: application/json" \
     -d '{"message":"How many donations have we received?"}'

πŸ“š API Documentation

Endpoints

Method Endpoint Description
POST /chat Send message to chatbot
GET /health Health check
GET /stats Database statistics
POST /refresh Refresh knowledge base

Chat Endpoint

Request:

{
    "message": "How can I donate to your organization?",
    "user_id": "user123",
    "session_id": "session456"
}

Response:

{
    "response": "You can donate through our website...",
    "relevant_documents": [
        {
            "document": {
                "text": "Donation - Donor: John Doe, Amount: β‚Ή500",
                "type": "donation",
                "id": "doc123"
            },
            "score": 0.95
        }
    ],
    "query": "How can I donate to your organization?",
    "session_id": "session456",
    "timestamp": "2025-01-27T10:30:00"
}

πŸ”§ Integration Examples

JavaScript/Web

async function askChatbot(message) {
    const response = await fetch('/api/chat', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ message })
    });
    
    const data = await response.json();
    return data.response;
}

React

const [response, setResponse] = useState('');

const sendMessage = async (message) => {
    const result = await fetch('/api/chat', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ message })
    });
    
    const data = await result.json();
    setResponse(data.response);
};

Python

import requests

def chat_with_bot(message):
    response = requests.post('http://localhost:8000/chat', 
        json={'message': message}
    )
    return response.json()['response']

πŸ“ Project Structure

Solace-AI-RAG/
β”œβ”€β”€ main.py                 # FastAPI application
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ .env.example            # Environment variables template
β”œβ”€β”€ Dockerfile              # Docker configuration
β”œβ”€β”€ docker-compose.yml      # Docker Compose setup
β”œβ”€β”€ README.md               # This file       
└── tests/                  # Test files
    β”œβ”€β”€ test_api.py         # API tests
    └── test_chatbot.py     # Chatbot tests

🐳 Docker Deployment

πŸ”§ Build & Run

Option 1: Using Docker Compose

# Build and run
docker-compose up --build -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

Option 2: Manual Docker Build

# Build image
docker build -t solace-ai-rag .

# Run container
docker run -d \
    --name solace-ai-rag \
    -p 8000:8000 \
    --env-file .env \
    solace-ai-rag

The API will be available at http://localhost:8000

☁️ Cloud Deployment - DigitalOcean/AWS/GCP

See deployment guide for detailed instructions.

πŸ“Š Database Schema

Your MongoDB collections should follow this structure:

Donations Collection

{
    "_id": "ObjectId",
    "fullName": "Donor Name",
    "amount": 1000,
    "status": "completed",
    "orderId": "order_123",
    "createdAt": "ISO Date"
}

Events Collection

{
    "_id": "ObjectId",
    "title": "Event Title",
    "description": "Event Description",
    "date": "2025-05-27",
    "time": "19:29",
    "location": "City Name",
    "participants": [],
    "createdAt": "ISO Date"
}

Feedback Collection

{
    "_id": "ObjectId",
    "message": "User feedback message",
    "createdAt": "ISO Date"
}

Posts Collection

{
    "_id": "ObjectId",
    "content": "Post content",
    "fullName": "Author Name",
    "status": "published",
    "createdAt": "ISO Date"
}

πŸ§ͺ Testing

# Install test dependencies
pip install pytest pytest-asyncio httpx

# Run tests
pytest

# Run with coverage
pytest --cov=main --cov-report=html

πŸ“ˆ Performance

  • Response Time: < 2 seconds average
  • Concurrent Users: 100+ simultaneous connections
  • Throughput: 1000+ requests/minute
  • Knowledge Base: Supports 10K+ documents efficiently

πŸ”’ Security

  • βœ… API key authentication
  • βœ… Rate limiting (10 requests/minute)
  • βœ… Input validation and sanitization
  • βœ… CORS protection
  • βœ… SQL injection prevention
  • βœ… XSS protection

🀝 Contributing

We welcome contributions! Please see our Contributing Guide.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“Š Stats

GitHub stars GitHub forks GitHub issues GitHub pull requests


Built with ❀️ by OpenVanguard

Empowering NGOs with AI-driven solutions for better community engagement

⭐ Star this repo | πŸ› Report Bug | πŸ’‘ Request Feature

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages