# πΎ Bengali Farmer Assistant Chatbot
This project is a **context-aware Bengali question-answering system** for farmers. It uses **multilingual semantic search** (via the E5 embedding model), **MongoDB vector search**, and **Gemini LLM** to respond to agricultural queries with precise, context-driven answers.
---
## π Features
- π§ **Semantic Search** using `intfloat/multilingual-e5-base`
- π¬ **Query Understanding** in Bengali (or other supported languages)
- π **MongoDB Vector Search** for paragraph retrieval
- π€ **Response Generation** using Google's Gemini API
- π **Text Ingestion Pipeline** that splits, embeds, and stores agricultural content
- π Interactive command-line chatbot
---
## βοΈ Technologies Used
- Python 3.11+
- HuggingFace Transformers
- PyTorch
- MongoDB Atlas (with vector search index)
- Gemini API (Google's Generative Language Model)
- dotenv (for secure key management)
---
## π Project Structure
```plaintext
BanglaBot/
βββ .env # Environment variables
βββ rice.txt # Input Bengali agricultural text
βββ bot.py # Main chatbot loop
βββ embed.py # Embedding and MongoDB storage logic
βββ search.py # Semantic search using MongoDB
βββ README.md # Project documentation
```
---
## π Work Procedure & Flow
### πΉ Step 1: Text Ingestion and Embedding
1. Read a Bengali text document (`rice.txt`).
2. Split it into paragraphs using regex.
3. Use `intfloat/multilingual-e5-base` model to generate embeddings (mean-pooled CLS vectors).
4. Store each paragraph and its vector in MongoDB with the following structure:
```json
{
"text": "বΰ§ΰ¦ΰ¦€ΰ¦²ΰ¦Ύ ঀΰ§ΰ¦°ΰ¦Ώ ΰ¦ΰ¦°ΰ¦Ύΰ¦° ΰ¦ΰ¦¨ΰ§ΰ¦―...",
"embedding": [0.123, -0.456, ...]
}
```
---
### πΉ Step 2: MongoDB Vector Search Setup
1. Use MongoDB Atlas with **Vector Search** enabled.
2. Create a vector index (`embedding_knn_index`) with:
- Field: `embedding`
- Similarity: `cosine`
- Dimensions: `768`
- Type: `knnVector`
---
### πΉ Ste β¦