File size: 2,659 Bytes
7e18ceb
 
 
 
 
 
 
 
 
5b40291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a431950
5b40291
 
 
 
 
 
 
 
 
 
 
 
 
a431950
 
5b40291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e18ceb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
license: apache-2.0
emoji: 🧠
sdk: docker
colorFrom: blue
colorTo: purple
thumbnail: >-
  https://cdn-uploads.huggingface.co/production/uploads/68734d5a2ae5ca930a3d195a/71R1ZoEhLA6neM5WSpxt4.png
---
# 🧠 Notionhive AI Chatbot

A FastAPI-based intelligent FAQ chatbot powered by Google Gemini and LangChain, designed to answer questions based on Notionhive's official FAQs and website: [notionhive.com](https://notionhive.com).

---

## πŸš€ Features

* Semantic search using Sentence Transformers & Chroma DB
* Gemini AI (gemini-2.0-flash) for accurate response generation
* CSV-based FAQ management (upload, add, delete, view)
* RESTful API built with FastAPI
* Prompt structure enforcing Notionhive's tone and boundaries
* CORS enabled for frontend integration

---

## πŸ“ Project Structure

```
.
β”œβ”€β”€ main.py                  # FastAPI app initialization
β”œβ”€β”€ faq_routes.py           # All chatbot + FAQ management API endpoints
β”œβ”€β”€ faq_services.py         # Vector store logic, Gemini model setup
β”œβ”€β”€ chatbot_prompt.py       # Prompt template for Gemini responses
β”œβ”€β”€ faqs.csv                # Stored FAQs (question/answer pairs)
└── README.md
```

---

## 🍞 Requirements

* Python 3.9+
* Google API Key for Gemini
* `sentence-transformers`
* `langchain`
* `chromadb`
* `fastapi`, `uvicorn`
* `python-dotenv`, `pandas`

Install dependencies:

```bash
pip install -r requirements.txt
```

---

## πŸ” Environment Setup

Create a `.env` file in your root directory with the following:

```env
GOOGLE_API_KEY=your_google_api_key_here
```

---

## πŸ’  Usage

Run the API server locally:

```bash
uvicorn main:app --reload
```

Access endpoints:

* `POST /ask` β€” Ask a question
* `POST /add_faq` β€” Add a new FAQ
* `POST /upload_faqs_csv` β€” Upload bulk FAQs from CSV
* `DELETE /delete_faq` β€” Delete FAQ by content
* `DELETE /deleted/{faq_id}` β€” Delete FAQ by ID
* `DELETE /delete/destroyall` β€” Delete all FAQs
* `GET /get_faqs` β€” View all FAQs
* `POST /retrain` β€” Reload vector DB

---

## πŸ€– Chatbot Behavior

* Introduces itself as **Noah**, Notionhive’s AI Assistant.
* Answers based on FAQs and content from [notionhive.com](https://notionhive.com).
* Uses web search *only if* FAQ-based answers aren’t available and question is general or critical.
* Will never generate fabricated or speculative responses.

---

## πŸ“Œ Notes

* All FAQs are stored in `faqs.csv`. Updating this file retrains the vector search index.
* Currently single-tenant; for multi-tenant expansion, isolate CSV and vector store per tenant ID.

---

## πŸ‘¨β€πŸ’Ό Credits

Developed by the Notionhive AI team.