AI chatbots are everywhere—but most enterprise teams hesitate to use generic LLM-powered bots because of accuracy, hallucination, and data-sensitivity issues.
So instead of relying entirely on a model like Gemini or GPT, I built a custom AI chatbot architecture using:
.NET Core API
ML.NET for embeddings
Google Gemini AI for natural-language generation
Cosine similarity for intent matching
This architecture ensures the bot answers strictly from internal knowledge, making it ideal for enterprise, education, ERP systems, CRM, HR, and support bots.
In this article, I’ll walk you through the entire system—from intent storage to embedding generation, similarity scoring, prompt engineering, and final answer generation.
💡 Why Not Use LLM Directly?
Businesses want:
❌ No hallucinations
❌ No internet-based answers
❌ No inconsistent responses
❌ No exposure of internal data
LLMs are powerful but unpredictable. For enterprise applications, we need:
✔ Controlled outputs
✔ Zero hallucinations
✔ Responses only from internal data
✔ Easy updates to knowledge base
✔ Security and traceability
This custom AI chatbot provides exactly that.
🧱 System Architecture Overview
Here is the simplified end-to-end workflow:
+-------------------------+
| User Asks a Question |
+-----------+-------------+
|
v
+------------------------------+
| Convert Question to Embedding|
| (ML.NET FeaturizeText) |
+-----------+------------------+
|
v
+-------------------------------------+
| Compare with Stored Intent Vectors |
| (Cosine Similarity Matching) |
+---------------+---------------------+
|
v
+--------------------------------------+
| Pick Top 3–4 Relevant Answers |
| Build Context Block |
+------------------+-------------------+
|
v
+--------------------------------------------------+
| Send Context + Question to Gemini (Strict Prompt)|
| LLM Generates Final Natural-Language Answer |
+---------------------+----------------------------+
|
v
+------------------------------+
| Return Answer to Client |
+------------------------------+
🗂️ Step 1. Storing Intents in the Database
Each knowledge item (intent) contains:
QuestionText
AnswerText
EmbeddingJson (vector representation)
This creates a structured knowledge base that does not depend on the LLM.
Example DB structure
CREATE TABLE ChatIntents (
Id NVARCHAR(200) PRIMARY KEY,
QuestionText NVARCHAR(MAX),
AnswerText NVARCHAR(MAX),
EmbeddingJson NVARCHAR(MAX)
);
Join the conversation! Your thoughts help the community grow.