Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Multilingual RAG System (Bangla + English) using DeepSeek AI

A simple, robust Retrieval-Augmented Generation (RAG) system that answers Bangla and English queries using context retrieved from a Bangla PDF (HSC26 Bangla 1st Paper). Powered by DeepSeek via OpenRouter, FAISS for semantic chunk search, and MongoDB for storing chat history.

🎯 Ideal for building educational AI apps for students, educators, and researchers in Bangladesh.


🔧 Submission Requirements

✅ Source Code and README

  • ✅ Full source code is committed to this public repository
  • ✅ This README.md includes:
    • Setup guide
    • Tools, libraries used
    • Sample queries + outputs
    • API documentation
    • Evaluation matrix
    • Detailed answers to key technical questions

🧠 Assessment Answers

❓ What method or library did you use to extract the text, and why? Did you face any formatting challenges with the PDF content?

We used PyMuPDF (fitz) to extract Bangla text from the PDF. It provides:

  • Accurate text block recognition
  • Unicode-friendly output (crucial for Bangla script)
  • Faster and cleaner than PyPDF2 or pdfminer

Challenge: Some line breaks caused sentence splits — resolved with preprocessing.


❓ What chunking strategy did you choose? Why do you think it works well for semantic retrieval?

We used overlapping character-based chunking:

  • Each chunk is 1000 characters long
  • 200 characters overlap to preserve context across boundaries

✅ Works well because:

  • Keeps sentences mostly intact
  • Compatible with FAISS
  • Avoids truncation of meaningful content

❓ What embedding model did you use? Why did you choose it? How does it capture the meaning of the text?

We used sentence-transformers with a multilingual model:

  • Supports both English and Bangla
  • Captures sentence-level meaning
  • Produces dense embeddings for retrieval
  • Compatible with FAISS

❓ How are you comparing the query with your stored chunks? Why did you choose this similarity method and storage setup?

We use cosine similarity via FAISS:

  • Fast L2-based vector matching (IndexFlatL2)
  • Embedding vectors stored locally in vector_db/
  • Matches query → top chunks → passed to LLM

✅ This is efficient and well-optimized for similarity search.


❓ How do you ensure that the question and the document chunks are compared meaningfully? What would happen if the query is vague or missing context?

We embed both the question and chunks using the same model.

✅ Meaningful matching ensured because:

  • Chunk overlap keeps local context
  • FAISS returns top-K nearest vectors

⚠️ If a query is vague:

  • It may return irrelevant chunks
  • LLM may hallucinate or generate incorrect guesses
  • We recommend better chunking or query refinement to improve accuracy

❓ Do the results seem relevant? If not, what might improve them?

Yes, for direct textbook questions, results are highly accurate.

To improve:

  • Use sentence-aware chunking instead of character
  • Use cross-encoder re-ranking
  • Fine-tune embeddings on textbook data

⚙️ Tools, Libraries, and Packages Used

Purpose Library/Tool
Embeddings sentence-transformers, numpy
Vector Database faiss-cpu
PDF Reader PyMuPDF (fitz)
Chat Model (LLM) deepseek/deepseek-chat-v3-0324:free via OpenRouter
Backend Server FastAPI, uvicorn, pydantic
Database MongoDB, pymongo
Utilities dotenv, tqdm, httpx, openai >= 1.0.0

📁 Project Structure


multilingual-rag-system/
├── config.py
├── app.py
├── requirements.txt
├── .env
├── data/
│   └── HSC26-Bangla1st-Paper.pdf
├── vector\_db/
│   └── faiss\_index.index
├── models/
│   ├── preprocessor.py
│   ├── chunker.py
│   ├── vectorstore.py
│   └── rag\_pipeline.py
├── database/
│   └── chat\_history.py
├── rag\_env/


🧑‍💻 Installation Guide (Windows)

✅ Prerequisites

  • Python 3.8 or higher
  • MongoDB installed or MongoDB Atlas URI
  • Internet connection

1. Clone or Create Project

mkdir multilingual-rag-system && cd multilingual-rag-system
mkdir models database data vector_db
python -m venv rag_env
rag_env\Scripts\activate

2. Add Your PDF

Place your Bangla PDF in data/:

data/HSC26-Bangla1st-Paper.pdf

3. Create .env file

OPENROUTER_API_KEY=your_api_key_here
MONGO_URI=mongodb://localhost:27017

If using Atlas:

MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/

4. Create requirements.txt

langchain>=0.1.0
sentence-transformers>=2.2.2
faiss-cpu>=1.7.4
transformers>=4.30.0
PyMuPDF>=1.23.0
fastapi>=0.100.0
uvicorn[standard]>=0.22.0
pydantic>=2.0.0
pymongo>=4.4.0
openai>=1.0.0
httpx>=0.24.0
python-dotenv>=1.0.0
numpy>=1.24.0
tqdm>=4.65.0
pip install -r requirements.txt

5. Install MongoDB (If needed)

Download from: https://www.mongodb.com/try/download/community Install with “Run as a Service” enabled.

Then start:

net start MongoDB

6. Run the App

python app.py

On first run:

  • PDF is processed
  • Embeddings generated and stored in FAISS
  • DeepSeek LLM initialized
  • Server starts at http://localhost:8000

📡 API Documentation

➤ GET /

"Multilingual RAG System with DeepSeek v3 is running! 🚀"

➤ POST /ask

Input:

{
  "question": "অনুপমের ভাষায় সুপুরুষ কাকে বলা হয়েছে?",
  "session_id": "test123"
}

Output:

{
  "answer": "শুম্ভুনাথ"
}

📊 Sample Questions & Output

🔎 Question (Bangla) ✅ Answer
অনুপমের ভাষায় সুপুরুষ কাকে বলা হয়েছে? শুম্ভুনাথ
কাকে অনুপমের ভাগ্য দেবতা বলে উল্লেখ করা হয়েছে? মামাকে
বিয়ের সময় কল্যাণীর প্রকৃত বয়স কত ছিল? ১৫ বছর
🔎 Question (English) ✅ Answer
Who is referred to as the lucky god of Anupam? His uncle

📈 Evaluation Matrix

Metric Method Result
Groundedness Retrieved chunk contains answer ✅ Yes
Relevance Cosine similarity in FAISS ✅ Yes
Response Time ~1s with cached model/embeddings ✅ Good
Accuracy Manually verified 5+ QA pairs ✅ High

💬 Example Usage in Python

import requests

res = requests.post("http://localhost:8000/ask", json={
    "question": "অনুপমের ভাষায় সুপুরুষ কাকে বলা হয়েছে?",
    "session_id": "bangla_test"
})

print("Answer:", res.json()["answer"])

🧯 Troubleshooting

  • MongoDB not running → net start MongoDB
  • FAISS file missing → re-run app to regenerate
  • .env variables not loading → check file path and variable names
  • PDF not found → ensure correct filename and location in data/

📜 License

This project is licensed under the MIT License


🙌 Acknowledgements


✅ You're all set!

This system is now fully configured and production-ready for:

  • Bangla/English QA on textbook content
  • Integration into apps, chatbots, or dashboards

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages