The Short Version: Six Steps in Plain English
You do not retrain a model on your data. You give an existing model a searchable library of your own content and instruct it to answer only from what it finds there. That approach is called retrieval-augmented generation, or RAG, and it is how we build custom AI chatbots trained on business data.
- Gather the content that holds the answers. FAQs, policies, product information, help articles, price lists and the questions customers actually send you.
- Clean it up. Remove outdated pages, resolve contradictions so each question has one answer, and fill obvious gaps. The chatbot can only be as accurate as this material.
- Split it into short passages. Each passage should cover one idea, so the right one can be found and quoted.
- Index the passages by meaning. An embedding model turns each passage into a list of numbers that captures what it means, and a vector database stores them so a question can find the passages closest to it.
- Answer only from what is retrieved. When a question arrives, the system finds the most relevant passages and gives them to the language model with instructions to answer from them alone, and to say so when the answer is not there.
- Test, add a hand-over to a person, then launch. Try it on real customer questions, including awkward ones, connect it to your website or WhatsApp, and review the questions it could not answer so the content keeps improving.
The rest of this guide covers the same steps in technical detail, with a working Python example.
Why Training on Your Own Data Matters
A standard LLM like GPT-4 or Claude knows an enormous amount about the world. But it knows nothing about your business. It does not know your pricing, your return policy, or which products are in stock. It also does not know who your customers are or how your internal processes work. When you deploy a generic chatbot on your website and a customer asks "what is your refund policy for international orders?", the LLM does one of two things. It either makes something up (hallucinate) or gives a generic non-answer.
Training your chatbot on your own business data solves this problem at the root. It means the chatbot has access to the actual answers: your refund policy document, your product specifications, your onboarding guide, and your service terms. It can then draw on them accurately to answer questions. This is what separates a genuinely useful business AI from a toy. The same approach works for staff: a chatbot on company data such as HR policies, IT guides or sales playbooks lets people find answers without digging through shared drives, as long as it respects the same access permissions as the documents themselves.
RAG Explained for Business Owners
Retrieval-Augmented Generation (RAG) is the dominant architecture for grounding LLM chatbots in specific data. Here is the intuition. Instead of retraining the model on your data (which is expensive and slow), you give it access to a searchable database of your documents. When a user asks a question, the system retrieves the most relevant pieces of your content. It passes them to the LLM as context, alongside the user's question. The LLM then generates an answer based on the retrieved content: not on its general training.
Think of it like asking a new employee to answer customer questions from memory. Compare that with giving them a well-organised knowledge base they can search before responding. The second approach is far more reliable and far more accurate.
Fine-Tuning vs RAG: When to Use Each
| Factor | Fine-Tuning | RAG |
|---|---|---|
| Cost to implement | Higher: labelled examples, training runs and retraining | Lower: mostly data preparation and engineering |
| Data required | Thousands of labelled examples | Any structured text documents |
| Update when data changes | Must retrain (slow & expensive) | Update documents instantly |
| Hallucination risk | Moderate | Low (answers grounded in retrieved text) |
| Best for | Tone/style changes, specialised tasks | Knowledge-based Q&A, document queries |
| Recommended for most businesses? | Rarely | Yes |
When weighing RAG vs fine-tuning for business AI, start with how often your information changes. Prices, policies and stock levels change all the time, and RAG picks up an edited document as soon as it is re-indexed, while a fine-tuned model has to be retrained. Fine-tuning earns its place when you need a fixed tone or output format, and the two can be combined.
Step-by-Step: The Technical Detail
Step 1: Prepare Your Data
Collect all the content your chatbot needs to know. This typically includes: product documentation, FAQs, service policies, pricing guides, knowledge base articles, support ticket histories, and any other written knowledge about your business. The quality of this data is the single biggest factor in chatbot performance. Remove outdated content, ensure factual accuracy, and standardise formatting where possible.
Common data sources and how to extract them:
- PDFs: Use PyMuPDF or pdfplumber to extract text
- Website content: Use BeautifulSoup or Playwright to scrape pages
- Word documents: Use python-docx to extract text
- CRM knowledge base: Export via API or CSV
- Product catalogue: Export from e-commerce platform as JSON/CSV
Step 2: Chunk Your Text
LLMs have context window limits. You cannot feed an entire document to the model. You need to split your text into chunks small enough to fit within the context window while remaining semantically meaningful. A good default is 500–800 tokens per chunk with a 50–100 token overlap between adjacent chunks to maintain continuity.
Step 3: Create Embeddings
An embedding is a numerical vector representation of a piece of text. Semantically similar texts produce similar vectors. You use an embedding model to convert each text chunk into a vector. OpenAI's text-embedding-3-small is the most cost-effective option for most businesses. text-embedding-3-large gives better quality for complex domains.
Step 4: Store in a Vector Database
Vector databases are designed to store and search embeddings efficiently. The most common choices are Chroma (free, self-hosted), Pinecone (managed cloud service), and pgvector (PostgreSQL extension). Store each chunk alongside its embedding and metadata (source document, page number, section heading).
Step 5: Build the Retrieval Layer
When a user asks a question, embed their query using the same model you used for your documents. Then perform a similarity search in the vector database to retrieve the top K most relevant chunks (typically 3–5). These chunks become the "context" you pass to the LLM.
Step 6: Wrap with an LLM
Combine the retrieved context chunks with the user's question in a prompt. Then send it to an LLM to generate the final response. Your system prompt should instruct the model to answer only from the provided context. It should also say "I don't have information on that" if the context does not contain an answer, rather than hallucinating.
Python Code Example: Full RAG Pipeline
Here is a complete, working Python example using OpenAI embeddings and ChromaDB as the vector store:
import openai
import chromadb
from chromadb.utils import embedding_functions
# Initialise OpenAI client
client = openai.OpenAI(api_key="your-api-key")
# Initialise ChromaDB
chroma_client = chromadb.Client()
openai_ef = embedding_functions.OpenAIEmbeddingFunction(
api_key="your-api-key",
model_name="text-embedding-3-small"
)
# Create or load collection
collection = chroma_client.get_or_create_collection(
name="business_knowledge",
embedding_function=openai_ef
)
# Step 1: Ingest your documents (run once)
def ingest_documents(documents: list[dict]):
"""
documents: [{"id": "doc1", "text": "...", "source": "policy.pdf"}]
"""
texts = [d["text"] for d in documents]
ids = [d["id"] for d in documents]
metadatas = [{"source": d["source"]} for d in documents]
collection.add(
documents=texts,
ids=ids,
metadatas=metadatas
)
print(f"Ingested {len(documents)} document chunks")
# Step 2: Query the chatbot
def chat(user_question: str, top_k: int = 4) -> str:
# Retrieve relevant chunks
results = collection.query(
query_texts=[user_question],
n_results=top_k
)
context_chunks = results["documents"][0]
context = "\n\n---\n\n".join(context_chunks)
# Build prompt
system_prompt = """You are a helpful customer support assistant for our business.
Answer questions ONLY based on the context provided below.
If the context does not contain the answer, say: 'I don't have that information:
please contact our support team.'
Never make up information."""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {user_question}"}
]
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
temperature=0.2, # Low temperature for factual responses
max_tokens=500
)
return response.choices[0].message.content
# Example usage
sample_docs = [
{
"id": "policy_001",
"text": "Our refund policy allows returns within 30 days of purchase for all products in original condition. International orders may take 7-14 days for the refund to appear.",
"source": "refund_policy.pdf"
},
{
"id": "shipping_001",
"text": "Standard shipping takes 3-5 business days. Express shipping (1-2 days) costs £8.99. Free shipping on orders over £50.",
"source": "shipping_policy.pdf"
}
]
ingest_documents(sample_docs)
answer = chat("What is your refund policy for international orders?")
print(answer)
Data Quality Requirements
The quality of your chatbot's responses is directly proportional to the quality of your source data. Before ingesting content into your vector database, audit it against these requirements:
Data Preparation Checklist
- ✓ All content is accurate and up-to-date
- ✓ Contradictory information has been resolved (only one answer per question)
- ✓ PDFs and documents are readable (not scanned images)
- ✓ Headers and structure are preserved in extraction
- ✓ Pricing and dates have been verified for accuracy
- ✓ Legal disclaimers and restricted content are flagged
- ✓ Duplicate content has been removed or deduplicated
- ✓ Content is chunked at logical boundaries (not mid-sentence)
Testing Your Chatbot
Before deploying to production, conduct structured testing across three dimensions:
- Coverage testing: Ask 50+ representative questions that the chatbot should be able to answer. Measure what percentage it gets right.
- Edge case testing: Ask questions that are outside the knowledge base. Verify it returns a graceful "I don't know" rather than hallucinating.
- Adversarial testing: Try to make the chatbot go off-script, reveal system prompts, or say something inappropriate. Verify guardrails hold.
Deployment and Integration
Once your RAG pipeline is tested and working, wrap it in an API (FastAPI or Flask) and integrate it with your front-end. Common deployment architectures include:
- Web widget: Embed a JavaScript chat widget on your website that calls your API
- WhatsApp: Use the WhatsApp Business API webhook to receive messages and respond via your RAG chatbot
- Slack/Teams: Build a Slack app or Teams bot that routes messages through the same pipeline
- Email: Parse incoming support emails and generate draft responses using the RAG pipeline
Want Us to Build Your Custom AI Chatbot?
SpiderHunts Technologies builds RAG chatbots trained on your business data. We handle data preparation, indexing, the retrieval pipeline, API development and website or WhatsApp integration, and every build gets a written quote with scope and exclusions agreed up front. See our AI chatbot development service for how a project runs.
Get a Free Quote