Skip to content

Rupendra0/Cosdata-Hack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart FAQ Assistant

AI-powered FAQ search system using Cosdata OSS vector database - Built for Cosdata Hackathon 2025

🎯 Project Overview

Smart FAQ Assistant helps small businesses automate customer support by providing semantic search capabilities over their FAQ database. Instead of keyword matching, it uses vector similarity search powered by Cosdata OSS to understand the meaning of customer questions.

✨ Features

  • πŸ“ Easy FAQ Management - Add individual FAQs or bulk upload
  • πŸ” Semantic Search - Search by meaning, not just keywords
  • 🎨 Modern UI - Clean, responsive React interface
  • ⚑ Fast Performance - Powered by Cosdata OSS vector search
  • πŸ“Š Categorization - Organize FAQs by category (General, Technical, Billing, Product)
  • 🎯 Similarity Scores - See how well each result matches your query

πŸ—οΈ Tech Stack

Frontend:

  • React 18
  • Vite
  • CSS3

Backend:

  • Node.js
  • Express.js
  • Cosdata OSS (Vector Database)

πŸ“‹ Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn
  • Docker Desktop (for running Cosdata)
  • Windows PowerShell

πŸš€ Quick Start

1. Set Up Cosdata OSS with Docker

Pull and Run Cosdata:

# Pull the image
docker pull cosdataio/cosdata:latest

# Run the container
docker run -d --name cosdata-server -p 8443:8443 -p 50051:50051 cosdataio/cosdata:latest


# Verify it's running
docker ps

# NOTE: This Cosdata image may not expose /health (it can return 404).
# Instead, create a session and then call an authenticated endpoint.
curl -sS -X POST http://localhost:8443/auth/create-session \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":""}'

βœ… You should see a JSON response containing an access_token.

πŸ“– Detailed setup: See COSDATA_SETUP.md

2. Install Dependencies

# Install backend dependencies
cd backend
npm install

# Frontend already has dependencies installed

3. Configure Environment

The .env file is already created with default settings:

PORT=5050
COSDATA_API_URL=http://localhost:8443

If needed, you can also set Cosdata credentials (local Docker commonly uses an empty admin key):

COSDATA_USERNAME=admin
COSDATA_PASSWORD=

Optional: Add Hugging Face API key for better rate limits (free):

HUGGINGFACE_API_KEY=your_key_from_https://huggingface.co/settings/tokens

4. Run the Application

Terminal 1 - Backend:

cd backend
npm run dev
# Server runs on http://localhost:5050

Terminal 2 - Frontend:

cd frontend
npm run dev
# App runs on http://localhost:5173

5. Try It Out! πŸŽ‰

  1. Open http://localhost:5173 in your browser
  2. Click "Load Sample FAQs" to add demo data (5 FAQs)
  3. Try semantic search:
    • "How do I get my money back?" β†’ Finds refund policy
    • "Can't login" β†’ Finds password reset
    • "When are you open?" β†’ Finds business hours
  4. Watch semantic search in action - it understands meaning, not just keywords!

πŸ“ Project Structure

smart-faq-assistant/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ faqRoutes.js      # FAQ CRUD endpoints
β”‚   β”‚   └── searchRoutes.js   # Search endpoint
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── cosdataService.js # Cosdata integration
β”‚   β”œβ”€β”€ server.js             # Express server
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ FAQUpload.jsx    # FAQ upload form
β”‚   β”‚   β”‚   β”œβ”€β”€ SearchBox.jsx    # Search interface
β”‚   β”‚   β”‚   └── ResultsList.jsx  # Search results
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   └── App.css
β”‚   └── package.json
└── README.md

πŸ”Œ API Endpoints

FAQ Management

  • GET /api/faq - Get all FAQs
  • POST /api/faq - Add single FAQ
  • POST /api/faq/bulk - Bulk upload FAQs
  • DELETE /api/faq/:id - Delete FAQ

Search

  • POST /api/search - Semantic search
    {
      "query": "How do I reset my password?",
      "topK": 5
    }

πŸŽ“ How It Works

  1. FAQ Upload: Questions and answers are converted to 384-dimensional vector embeddings using Hugging Face's BAAI/bge-small-en-v1.5 model (FREE!)
  2. Vector Storage: Embeddings stored in Cosdata OSS vector database with metadata (answer, category, timestamp)
  3. Semantic Search: User queries are converted to vectors and matched using cosine similarity in Cosdata
  4. Ranked Results: Most relevant FAQs returned with similarity scores

Why It's Better Than Keyword Search:

  • Understands "refund" = "money back" = "get my cash returned"
  • Matches "can't sign in" with "reset password"
  • No need for exact keyword matches!

πŸ†“ Free Embeddings Setup

This project uses 100% FREE embedding generation:

Hugging Face Inference API (No credit card required!)

  • Model: BAAI/bge-small-en-v1.5
  • Dimensions: 384
  • Rate Limit: ~1000 requests/hour without API key
  • With free API key: Much higher limits

Get Your Free API Key (Optional but Recommended):

  1. Sign up at https://huggingface.co (free)
  2. Go to https://huggingface.co/settings/tokens
  3. Create a new token (Read access is enough)
  4. Add to backend/.env: HUGGINGFACE_API_KEY=your_token_here

πŸ”§ Customization

Use Different Embedding Model

Edit backend/services/cosdataService.js:

// Change the model
this.embeddingModel = 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2'; // For multilingual support
// or
this.embeddingModel = 'BAAI/bge-small-en-v1.5'; // Higher quality, still free

// Update dimension if needed
this.dimension = 384; // or 768, 1024 depending on model

Add More FAQ Categories

Edit frontend/src/components/FAQUpload.jsx:

<select id="category" ...>
  <option value="general">General</option>
  <option value="technical">Technical</option>
  <option value="billing">Billing</option>
  <option value="product">Product</option>
  <option value="shipping">Shipping</option>  {/* Add your category */}
</select>

🚧 Next Steps / Improvements

  • βœ… Integrate Cosdata OSS vector database
  • βœ… Use free Hugging Face embeddings
  • βœ… Semantic search functionality
  • Add authentication for multi-business support
  • Persist FAQs to PostgreSQL/MongoDB
  • Add analytics dashboard (search trends, popular questions)
  • Deploy to cloud (Vercel + Railway/Render)
  • Add file upload for bulk FAQ import (CSV/JSON)
  • Implement caching for faster searches
  • Add multilingual support

πŸ› Troubleshooting

Cosdata not running?

# Check if container is running
docker ps

# Check logs
docker logs cosdata-server

# Restart container
docker restart cosdata-server

Backend won't start?

  • Check if port 5050 is available: netstat -an | findstr 5050
  • Ensure Cosdata is running: curl http://localhost:8443/health
  • Check backend logs for errors

Search returns empty results?

  • Make sure you've added FAQs first (click "Load Sample FAQs")
  • Check backend console for embedding errors
  • Verify Cosdata connection in backend logs
  • Try restarting backend server

Hugging Face rate limit errors?

Frontend shows connection error?

  • Ensure backend is running on port 5050
  • Check browser console for CORS errors
  • Verify http://localhost:5050/health returns OK

🎯 Business Value

  • Reduce Support Tickets: Customers find answers instantly
  • 24/7 Availability: No human agent needed
  • Scalable: Handles thousands of FAQs efficiently
  • Cost Savings: Reduce support team workload by 60-70%

πŸ“ License

MIT License - Built for Cosdata Hackathon 2025

πŸ™ Acknowledgments

  • Cosdata for the amazing OSS vector database
  • Vite for blazing fast development
  • React for the UI framework

πŸ“§ Contact

Built by [Your Name] for Cosdata Hackathon 2025


⭐ Don't forget to star the Cosdata repo!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors