AI Chatbot With Knowledge Base: How to Build One

Upload your docs. The AI answers questions grounded in your content, with citations. Skip Intercom Fin's $0.99 per resolution.

Get started for free, no credit card needed.
$0
Saved per 1,000 chats vs Intercom Fin
0h
Chat UI + RAG + ingestion wired
0%
Citations on every answer
0
Vendor model lock-in (swap providers)

Guide

How an AI chatbot with a knowledge base works, and how to build one.

A knowledge-base chatbot is a chat interface whose answers come from your documents, not from whatever the model remembers from training. This is what it is, how the pipeline fits together, how to build one in five steps, and where the real costs and failure modes are.

What an AI chatbot with a knowledge base is

Three things get called "chatbot" and they behave very differently:

  • Scripted bots follow a decision tree. If the user's question isn't on the tree, they fail.
  • Plain LLM chat (ChatGPT in an iframe) answers anything, but from training data. It doesn't know your refund policy, your API, or last week's release notes, and it will guess.
  • A knowledge-base chatbot sits in between: an LLM writes the answer, but only after the system retrieves the relevant passages from your content and puts them in front of the model. When the passages don't exist, a well-built bot says so instead of inventing one.

The technique is called retrieval-augmented generation (RAG). It is the standard architecture behind Intercom Fin, Zendesk AI agents, Chatbase, and most "train a bot on your docs" products. None of them fine-tune a model on your data; they retrieve and prompt.

How it works, step by step

There are two pipelines: one that runs when your documents change, one that runs on every question.

Ingestion (runs when docs change)

  1. Collect sources. Help-center articles, PDFs, product docs, a crawled marketing site, Notion pages, policy documents.
  2. Chunk. Each document is split into passages of roughly 300–800 tokens with some overlap, so a single answer's context fits in one chunk. Chunking on headings beats chunking on fixed character counts.
  3. Embed. Each chunk is turned into a vector (a list of numbers) by an embedding model. Semantically similar text ends up with similar vectors.
  4. Store. Vectors plus the original text and metadata (source URL, title, last-updated) go into a vector store: pgvector inside Postgres, or a hosted index like Pinecone.

Answering (runs per question)

  1. Embed the question with the same model.
  2. Retrieve the top 3–8 chunks whose vectors are closest. Many systems also run a keyword search and merge the results (hybrid retrieval), which helps with product names and error codes.
  3. Build the prompt: system instructions ("answer only from the context; if the context doesn't cover it, say you don't know"), the retrieved chunks, the conversation so far, the question.
  4. Generate the answer, streaming tokens to the UI, and attach citations back to the chunks used.
  5. Log the question, the retrieved chunks, and the answer. This log is how you find gaps in your docs later.

How to build one in five steps

  1. Pick the sources and decide the boundary. Start with the content that already answers most support questions, usually a help center and product docs. Leave out anything you wouldn't want quoted verbatim to a customer.
  2. Choose the three models. A chat model (Claude, GPT, or an open-weight model via Ollama), an embedding model (OpenAI, Cohere, or a local one), and a vector store (pgvector is enough for well under a million chunks). Keep them swappable; prices and quality shift every few months.
  3. Build the ingestion pipeline. An admin page to upload files and paste URLs, a worker that parses, chunks, embeds, and writes to the store, and a re-ingest path that only re-embeds documents whose content hash changed.
  4. Build the chat UI. Streaming responses, markdown rendering, a "Sources" block under every answer, per-user conversation history, and an embed snippet so the same bot can live on your site or inside your app.
  5. Add guardrails and measurement. A refusal path when retrieval returns nothing relevant, an escalation button that creates a ticket with the transcript attached, token-cost tracking per conversation, and a fixed test set of 30–50 real questions you re-run whenever you change chunking, prompts, or models.

Steps 3–5 are where the time goes. The prompt at the top of this page generates that shape as a Next.js app, with the ingestion routes, pgvector schema, streaming chat, and citations wired, so the work left is your content and your prompt wording.

Build vs. buy

There are three realistic routes. Which one is right depends on how you pay and what you need to own.

RouteTime to liveHow you payModel choiceOwn the data and UI
Off-the-shelf (Intercom Fin, Zendesk AI, Tidio, Chatbase)HoursPer resolution, per seat, or per message tier on top of the platform subscriptionVendor'sNo: conversations, index, and widget live on their side
Framework (LangChain, LlamaIndex, or hand-written)WeeksAPI usage plus engineering timeYoursYes
Generated app (Webtwizz)Hours to a dayAPI usage; hosting is yoursYours, swappableYes: Next.js code, Postgres, your domain

Buy if your support team already lives in Intercom or Zendesk, volume is low enough that per-resolution pricing doesn't hurt, and you don't need the bot anywhere except the help widget.

Build or generate if per-resolution pricing scales badly for you, the bot needs to sit inside your own product with your auth and your UI, your data has to stay in your database, or you want to change the model when a better or cheaper one ships.

What it costs to run

The recurring cost is model usage, and it's small compared to per-resolution pricing.

  • Embeddings are a one-time cost per document, on the order of a hundredth of a cent per chunk. A 100-page documentation set costs cents to index, and incremental re-ingestion keeps it that way.
  • Chat completions run roughly $0.01–$0.05 per conversation on a small model such as Claude Haiku or GPT-4o-mini for typical support-length exchanges. A thousand conversations a month is $10–$50 in API spend.
  • Hosting is a Postgres instance with pgvector and a Node app. On Supabase and Vercel that starts free and stays under typical SaaS seat pricing for a long time.

Compare that with $0.99 per resolved conversation on Intercom Fin: 1,000 resolutions is $990 a month before the platform subscription. Cost is rarely the reason to buy; speed and not having to own anything is.

Mistakes that make these bots bad

  • No refusal path. If the prompt doesn't tell the model to decline when the retrieved context is empty or irrelevant, it will answer anyway, and it will be confidently wrong.
  • No citations. Users trust an answer that links to the doc it came from and distrust one that doesn't. Citations also make bad answers debuggable.
  • Chunks that are too big or too small. Too big and the relevant sentence is buried in noise; too small and the answer is split across chunks that don't all get retrieved. Chunk on document structure, and test.
  • A stale index. Docs change; the vector store doesn't know unless something re-ingests. Trigger re-ingestion from the doc source, not from a calendar.
  • Mixing tenants. If the bot serves multiple customers or workspaces, every retrieval query has to filter by tenant. Forgetting this leaks one customer's documents into another's answers.
  • No evaluation set. Without 30–50 fixed real questions and expected answers, every change to chunking or prompts is a guess. Run the set on every change.

Which knowledge sources work best

The bot is only as good as what it can retrieve, and some sources retrieve much better than others.

  • Works well: help-center articles, product documentation, policy pages, FAQs, release notes, anything already written to answer a question.
  • Needs preparation: long PDFs (split by section and keep headings), spreadsheets (add a row-per-record description), and marketing pages (strip navigation and boilerplate before chunking).
  • Usually not worth it: scanned PDFs without OCR, Slack or email threads where the answer is spread across twenty messages, and internal wikis nobody has updated in a year. The bot will cite them, and the citation will be wrong.

A useful starting rule: if a human support agent would paste a link to it, ingest it. If they'd say "let me check with someone," it isn't ready to be a source.

01 / What you get

AI Chatbot with Knowledge Base, generated.

Click Generate from the box above. Real Next.js code, a real database, real integrations, not a sandbox. Each piece below ships in the first prompt.

01

Streaming chat UI with markdown rendering and code-block syntax highlighting

02

Knowledge base ingestion: upload PDFs, paste text, crawl URLs, all chunked and embedded

03

RAG retrieval: every answer cites the source documents it pulled from

04

OpenAI or Anthropic backend, swap models without changing the UI

05

Conversation history per user, searchable, exportable

06

Token usage tracking per conversation so you can audit cost per user

02 / Variants

4 variants you can ship.

01
Customer support bot
Docs-grounded, ticket creation if it can't answer, multi-language, escalation rules.
02
Sales assistant
Catalog and pricing-aware, lead capture mid-conversation, demo-booking handoff.
03
Internal HR / IT bot
Employee Q&A on policies, IT troubleshooting, SSO-aware so it's on the right account.
04
In-product docs assistant
Embedded in your app, context-aware of which page the user is on.

From data to design

The AI builds a real app. Then you shape every pixel.

Data

Wire up real data

Databases and CMS that power your live app, no backend to set up.

Wire up real data
Type

Tune every letter

Font, size, weight, leading and spacing, all by hand.

Tune every letter
Color

Pick any color

Pick any color
Components

Reuse your own blocks

Save any section and drop it in anywhere.

Reuse your own blocks
Images

Drop in photos

Pull in free imagery without leaving the canvas.

Drop in photos
Pages

Structure your site

Structure your site

03 / Who it's for

For people who hate $99-per-seat tools.

Support teams replacing tier-1 with a bot trained on their docs
SaaS companies building "ask the docs" search inside their product
Agencies offering chatbot setups to clients as a service
Founders who need a docs assistant before they have a support team

Integrations

Works with the tools you already use.

Payments, database, AI, email and analytics, wired up the moment you connect.

Stripe
Supabase
OpenAI
Anthropic
Resend
PostHog
Sentry
Google Analytics
MongoDB
GitHub

04 / Why generate it

Why generate it instead of buying it.

Intercom Fin charges $0.99 per resolution. At 1,000 questions a month that's $12,000 a year and you don't own the conversations or the model choice.

You pick the model (Claude, GPT, open-weight via Ollama later), the embeddings (OpenAI, Cohere, local), and the vector store (pgvector, Pinecone). When prices drop or a better model ships, you swap one line.

Head-to-heads: vs Lovable · vs Bolt · vs v0 · vs Replit

FAQ

Questions about AI Chatbot with Knowledge Base.

Everything you need to know before you generate it. Anything else, our team is one email away.

Upload PDFs or paste URLs into an admin page (Webtwizz scaffolds the form). The AI scaffolds a route that fetches/parses the content, chunks it into ~500-token segments with overlap, and stores embeddings in pgvector (Postgres extension via Supabase). Re-ingestion is incremental, only changed docs re-embed.

RAG is right for almost everyone. Fine-tuning is expensive, slow, and brittle when your docs update. RAG retrieves fresh context per query, which is why the answer can include "this changed last week" without retraining. Keep prompt engineering tight: instruct the model to refuse if retrieval is empty.

Yes. The AI scaffolds citations inline, each answer ends with a "Sources:" block listing the doc titles and URLs the model pulled from. Clicking a citation deep-links to the source. Trust signal users actually look at.

Roughly $0.01-$0.05 per conversation on Claude Haiku or GPT-4o-mini for typical Q&A length. Embeddings are ~$0.0001 per chunk, one-time at ingestion. So a 100-page doc set costs cents to embed; 1,000 user conversations a month costs $10-$50 in API spend. Compare to $990 per 1,000 resolutions on Intercom Fin.

Yes. Webtwizz scaffolds an embed snippet (a script tag + iframe) that renders the chat in any website. Auth is optional, anonymous users get a session ID; logged-in users get history attached to their account.

It searches them. Nothing is trained on your data; the model reads the retrieved passages at answer time. That is why updating a document changes the next answer immediately, and why deleting one removes it from every future answer.

Start building

Your idea, live in minutes.

Describe what you want. WebTwizz builds the real thing, then you click to change anything. No code needed.

Get started for free, no credit card needed.