loading your 360 experience

Last updated: Thursday, September 5, 2024

How We Built a Production Ready AI Chatbot in 5 Days

Towasin Khan

Towasin Khan

Strategist at DigiRib

A step by step technical breakdown of how we train custom LLMs, build Supabase vector pipelines, and deploy web ready chatbots that qualify leads and answer support questions 24/7.

Summarize this article withChatGPTorClaudePerplexityGemini
How We Built a Production Ready AI Chatbot in 5 Days

Building an artificial intelligence chatbot for a business often results in a generic tool that provides inaccurate answers. At DigiRib we set a challenge for our team: we wanted to build and deploy a production ready chatbot in exactly five days. This chatbot had to ingest client documents, perform real-time vector searches, qualify leads, and sync data directly to a CRM system. We wanted to prove that a rapid timeline does not require compromising on security, speed, or accuracy. The following is a detailed breakdown of how we achieved this goal.

Many businesses make the mistake of using out-of-the-shelf chatbot builders without proper data pipelines. This leads to hallucinations where the AI invents answers. For B2B applications, this is a critical risk. If a chatbot gives incorrect pricing or false promises, it damages trust. Our approach relies on Retrieval-Augmented Generation (RAG) backed by a PostgreSQL database and pgvector, ensuring that every answer is grounded in verified documentation.

Day 1 Context Ingestion and Data Structuring

The performance of any chatbot depends on the quality of the data it receives. If you feed the system unstructured web pages or noisy documents it will return incorrect answers. On the first day we focused entirely on data extraction and preparation. We built a script using Node.js to scrape the public knowledge base, support documents, and product listings of the client.

Our script traversed the sitemaps, downloaded the raw HTML, and stripped away all boilerplate elements. We removed navigation menus, footers, script tags, and styling sheets. This left us with clean, raw text. We then converted this text into structured markdown format. Markdown is highly efficient because it preserves document hierarchy (such as headings and lists) without adding unnecessary tags that consume token limits.

Once the markdown was ready we applied a recursive character splitting strategy. We divided the text into chunks of approximately one thousand characters each. We configured the splitter to allow an overlap of two hundred characters between chunks. This overlap ensures that context is not lost at the boundaries of the split text. We also appended metadata to each chunk, recording the source URL and the document category. This metadata is essential for citation and verification during the generation phase.

We encountered several challenges during the data cleaning phase. Many HTML pages contained duplicate information, broken links, or non-standard symbols. Our Node.js script used regular expressions to identify and remove duplicate sections. We also sanitized the text by replacing special characters with standard equivalents. This preparation reduced the overall token volume by thirty percent, saving database storage space and lowering subsequent API costs during chatbot runtime operations.

Day 2 Supabase Vector Store and pgvector Setup

On the second day we designed the database architecture to store and search the structured text chunks. We chose a Supabase instance running PostgreSQL. PostgreSQL is highly reliable and supports the pgvector extension. This extension allows us to store vector embeddings and perform similarity searches directly inside the database using SQL queries.

We created a table named document sections. This table stores the raw text content, the document path metadata, and a vector column of fifteen hundred and thirty-six dimensions. We generated these vector embeddings using the text-embedding-3-small model from OpenAI. This model converts raw text chunks into numerical vectors that represent the semantic meaning of the words. If two text chunks discuss similar topics their vector representations will be close to each other in the vector space.

To make searches fast at scale we built a Hierarchical Navigable Small World (HNSW) index on the vector column. We configured the index to use cosine distance as the similarity metric. Cosine distance measures the angle between two vectors, making it highly effective for text similarity searches regardless of document length. This database setup allowed us to query millions of text chunks in milliseconds, providing the foundation for real-time responses.

We tuned the HNSW index parameters to balance search speed and accuracy. We set the construction parameter to sixty-four and the search parameter to forty. These configurations ensured that queries returned the most relevant chunks with minimal latency. We also built automated SQL triggers to update the index whenever new document sections were added to the table.

Day 3 RAG Pipeline and Prompt Engineering

Retrieval Augmented Generation is the process of retrieving relevant documents and passing them to the language model to generate an answer. On the third day we built the core pipeline using Supabase Edge Functions. When a user sends a message to the chatbot, the system generates a vector representation of that message and queries the database for the most similar text chunks.

The edge function retrieves the top three matching text chunks based on cosine similarity score. We set a minimum similarity threshold of zero-point-seven to ensure that irrelevant documents are ignored. The function then constructs a prompt context block containing the retrieved text chunks and the user query. This context is passed to the Gemini model along with system instructions.

Prompt engineering was critical to prevent the model from inventing information. We designed the system instructions to force the chatbot to answer questions using only the provided context. If the answer cannot be found in the retrieved documents, the chatbot is instructed to say that it does not know the answer. This constraint is essential for business applications where incorrect product details or policies can damage reputation. We also instructed the model to format its response in clean markdown and cite the source URLs from the metadata.

Retrieval Augmented Generation and Prompt Engineering

Day 4 Live Booking and CRM Sync via n8n

A chatbot should do more than just answer questions. It must guide users toward business outcomes. On the fourth day we focused on automating lead qualification and data synchronization. We built an automation workflow using n8n to connect the chatbot with the client CRM and booking systems.

During a conversation the chatbot monitors user inputs. If a user expresses interest in booking a consultation or purchasing a product, the chatbot asks for their name and email address. Once this contact information is gathered, the chatbot sends a payload to an n8n webhook. The workflow parses the payload, validates the email format, and checks if the lead already exists in the CRM database.

If the lead is new, the workflow creates a record in the CRM and assigns it to a sales representative. If the lead is already registered, the workflow appends a note about the conversation. The n8n workflow then generates a dynamic booking link. The chatbot presents this link to the user, allowing them to schedule a meeting directly. This automated flow operates twenty-four hours a day, converting website visitors into qualified appointments without manual intervention.

We built error handling into the n8n workflow to ensure data reliability. If the CRM API returns an error the workflow automatically retries the request after a short delay. If the retry fails, the system sends an email notification to the sales team with the lead details. This precaution prevents data loss and ensures that no qualified prospects are missed due to technical glitches.

Day 5 Web UI Deployment and Testing

The final day was dedicated to building the user interface and conducting rigorous testing. We created a modern React widget that floats in the corner of the client website. We used Tailwind CSS for styling and Framer Motion to create smooth transitions when opening and closing the chat interface.

We optimized performance by caching vector query results for common questions. This reduced API latency and lowered operational costs. We then conducted automated testing to evaluate the chatbot accuracy under various scenarios. We created a test suite of fifty standard customer questions and verified that the chatbot returned accurate answers and cited the correct documents. We also measured system latency, ensuring that responses were generated in less than two seconds.

By the end of the fifth day the chatbot went live on the website. Within four hours of deployment it captured and qualified its first lead, scheduling an appointment for the sales team. This project demonstrates that custom artificial intelligence solutions can be designed, built, and launched rapidly when using a structured, system-based engineering approach.

Measuring Chatbot Performance

An automated system is only useful if it delivers measurable value. In the weeks following the deployment, we closely monitored key performance indicators (KPIs). We tracked metrics such as first-response latency, conversion-to-booking rate, user rating scores, and API token usage.

Our initial findings showed that ninety-two percent of customer queries were resolved without human intervention. The cost per customer interaction dropped by eighty-four percent compared to manual support. More importantly, the sales team reported that leads captured by the chatbot had a forty percent higher close rate, as they had already been vetted and educated by the AI during the initial conversation.

Security Privacy and Compliance

Handling customer information requires strict compliance with data privacy regulations. During the development of the chatbot, we implemented several security protocols. All data transmitted between the frontend widget, the edge functions, and the database is encrypted using TLS 1.3.

Furthermore, we designed a compliance filter that runs on both incoming user queries and outgoing AI responses. This filter automatically detects and redacts personal identifiable information (PII) such as credit card numbers or government IDs. By keeping data processing within our private Supabase instance, we guarantee that customer information is never shared with third-party model providers for training purposes.

The Future of Conversational AI for B2B

Conversational interfaces are rapidly moving from simple text boxes to rich, interactive agents. In the near future, B2B chatbots will not only answer questions but perform complex multi-step tasks such as generating invoices, comparing plans dynamically, and running backend diagnostic tests on behalf of the customer.

By building our AI chatbot on a flexible relational database and open-source workflows, we ensure that our client can easily integrate these future features. The investment made in Day 1 and Day 2 sets a foundation that will support their business growth for years to come. Rapid deployment does not have to mean short-term thinking.

Serious about growing your business? Let's talk.

Your website is your biggest growth lever — are you getting the most out of it? Schedule a strategy call to uncover conversion roadblocks and explore high-impact improvements.

Book a Call →

Related Posts

Continue reading with these related articles.