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.

7 min read • View on GitHub • More from Saanvi666

A small storefront counter where a CSV sheet sits beside a simple scoring dial and a modest chatbot mechanism, while a student asks a question from a phone in the background. The scene explains that the bot is powered by a hand-edited question bank and lexical matching rather than an LLM.
The surprise is not that it answers questions. It is that the whole experience comes from a CSV file, a scoring step, and a few lines of Flask.
Key Takeaways

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.

The answer path is plain enough to explain on one slide. Query in, token counts out, similarity scores ranked, threshold checked, fallback if needed.

A close-up of a chat window stitched together from hidden paper tabs and a ribbon that carries the previous conversation back to the server. The image explains how a stateless form becomes a continuous chat experience.
The clever part is not the response loop. It is that the loop survives without sessions, a database, or frontend state management.

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
ApproachHow it answersSetup costStrengthsWeaknessesBest fit
Saanvi666/ChatbotMatches the query against CSV question text with cosine similarityLowTransparent, fast, easy to editWeak on semantics and recallNarrow FAQ workflows
LLM chatbotGenerates answers from a model or tool chainHighFlexible, conversational, broad coverageCost, latency, and control concernsOpen-ended support and assistants
Static FAQ pageUsers search or browse fixed answersVery lowSimple, stable, cheapNo dialogue and weak query recoveryTiny sites with obvious questions
Retrieval bot with embeddingsCompares queries with semantic vectorsMediumBetter synonym handling and recallMore moving parts and tuningLarger 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.

A WSJ-style hedcut portrait of the repository owner, rendered from a verified GitHub avatar. It provides a human anchor for the project while keeping the article conservative about identity.

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.

QuestionThis repoWhy it matters
Can it answer without modern AI?YesIt proves that useful chat UX does not require a model endpoint.
Does it remember the conversation?Only through reposted form stateThe experience feels continuous, but the state is still fragile.
Does it understand semantics?NoIt depends on shared words and manual CSV coverage.
Is it easy to modify?YesNon-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.