Saanvi666/Chatbot: The Tiny Flask Bot That Beats Complexity with CSVs and Cosine Similarity
A retrieval-based assistant for course FAQs, built from a hand-shaped knowledge base, a hidden chat history field, and just enough NLP math to feel smarter than it looks.
- This repo shows how far a chatbot can go when the real job is narrow and the knowledge base is curated by hand.
- Its core trick is lexical retrieval, not semantic understanding, which makes the system simple, fast, and predictable.
- The hidden chat field turns a stateless Flask form into a believable conversation without sessions or a database.
- The design is intentionally limited, but that limitation is also why it is easy to deploy, reason about, and maintain.
Why This Bot Is More Interesting Than It Looks
Most chatbots promise intelligence first and implementation second. Saanvi666/Chatbot does the opposite. It solves a narrow FAQ problem with a CSV file, CountVectorizer, cosine similarity, and a stateless Flask form.
That makes it feel almost old-fashioned, but in a useful way. You can read the whole system and understand where every answer comes from.
The Brain Is a CSV, Not a Model
The knowledge base lives in conv.csv. Instead of training a large model, the repo stores question and answer pairs in a simple table and leans on manual synonym clustering inside the question text.
That design choice matters. A cluster like hi hello hey gives the matcher more surface area, so a user can land on the right answer without any embeddings, vector database, or semantic index.
How the Matching Engine Chooses an Answer
The matching engine is classical NLP in its simplest useful form. The user query and the CSV questions are vectorized as token counts, then compared with cosine similarity to find the closest overlap.
The important part is not the math. It is the tradeoff. The bot rewards shared words, not shared meaning, so it works best when the CSV has been edited with the language real users are likely to type.
That is why the fallback matters too. If nothing clears the score threshold, the app returns a default message instead of pretending to understand.
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
vectorizer = CountVectorizer()
X = vectorizer.fit_transform([user_query] + list(df['question']))
scores = cosine_similarity(X[0:1], X[1:]).flatten()
best = scores.argmax()
if scores[best] > 0.10:
answer = df.iloc[best]['answer']
else:
answer = fallback_message
| Approach | How it answers | Setup cost | Strengths | Weaknesses | Best fit |
|---|---|---|---|---|---|
| Saanvi666/Chatbot | Matches the query against CSV question text with cosine similarity | Low | Transparent, fast, easy to edit | Weak on semantics and recall | Narrow FAQ workflows |
| LLM chatbot | Generates answers from a model or tool chain | High | Flexible, conversational, broad coverage | Cost, latency, and control concerns | Open-ended support and assistants |
| Static FAQ page | Users search or browse fixed answers | Very low | Simple, stable, cheap | No dialogue and weak query recovery | Tiny sites with obvious questions |
| Retrieval bot with embeddings | Compares queries with semantic vectors | Medium | Better synonym handling and recall | More moving parts and tuning | Larger FAQ sets with varied wording |
How the Chat Stays Alive Without Sessions
The hidden gem is the hidden input field. The template sends the entire chat history back to the server on each post, then appends the newest turn and renders the conversation again.
That is a clever stateless workaround. It keeps the app portable and easy to deploy, but it also means the conversation is only as trustworthy and scalable as the form payload carrying it.
What the Bot Gets Right, and What It Cannot Do
Its strengths are obvious once you accept the scope. It is fast, cheap, easy to understand, and good enough for a tightly bounded FAQ domain.
Its limits are just as clear. It cannot infer intent the way an LLM can, it cannot generalize well beyond the wording in conv.csv, and it cannot recover gracefully when the right synonym was never added by hand.
That is not a flaw if the use case is narrow enough. For a tutoring center, training institute, or service desk with repetitive questions, this is often the right trade.
| Question | This repo | Why it matters |
|---|---|---|
| Can it answer without modern AI? | Yes | It proves that useful chat UX does not require a model endpoint. |
| Does it remember the conversation? | Only through reposted form state | The experience feels continuous, but the state is still fragile. |
| Does it understand semantics? | No | It depends on shared words and manual CSV coverage. |
| Is it easy to modify? | Yes | Non-specialists can edit the question bank without retraining anything. |
Why This Matters for Small Teams
The real lesson is not that modern AI is unnecessary. It is that many business chat problems are smaller than the hype around them.
When the domain is narrow, the answer can be narrow too. A tiny Flask app, a CSV, and a little similarity math can be enough to deliver something that feels product-shaped without the overhead of a full AI stack.





