AI Hints
Home›RAG Tutorial›Order and Practice
RAG · Lesson 50 of 120

Practice: Ask the Help Centre

Ten questions.

⏱ 2 min read▶ Video at 49:47🎓 Free
Watch this lesson in the RAG courseWatch on YouTube ↗Full RAG course

Let's put the whole pipeline to work. We'll ask the help centre ten real customer questions, and look at every answer. Try predicting which ones will go wrong.

Practice: Ask the Help Centre
From the video: Practice: Ask the Help Centre
  • Whole pipeline
  • Ten questions
  • Spot the weak ones

Ten questions

We loop over ten questions, and ask for very short answers, so they fit on one line. Run it. Most questions get the right fact, and skateboards get I don't know, as they should. But one or two real questions also get I don't know, which usually means retrieval missed the page.

practice.pypython
from rag_kit import load_docs, make_chunks, Index
from llm import answer

index = Index(make_chunks(load_docs()))
questions = ["How much is UK delivery?", "Can I return a used bike?",
    "What does E05 mean?", "When is York open?", "How long is the warranty?",
    "Do you sell skateboards?", "How much is a Basic service?", "Can I pay monthly?",
    "Which frame size for 180 cm?", "Do you deliver to France?"]

for q in questions:
    a = answer(q + " Answer in under eight words.", [c for s, c in index.search(q)])
    print(f"{q:29} {a[:56]}")
Output
How much is UK delivery?      Standard UK delivery costs £4.99, or free over £50.
Can I return a used bike?     I don't know.
What does E05 mean?           The motor is overheating.
When is York open?            Monday to Saturday, 9am to 5:30pm. Closed Sunday.
How long is the warranty?     It varies by part (frames are lifetime).
Do you sell skateboards?      I don't know.
How much is a Basic service?  A Basic service costs £49.
Can I pay monthly?            I don't know.
Which frame size for 180 cm?  Large fits riders from 178 to 188 centimetres.
Do you deliver to France?     Yes, in 5 to 9 working days.
Also uses rag_kit.py
import warnings; warnings.filterwarnings("ignore")
from pathlib import Path
import numpy as np
from sentence_transformers import SentenceTransformer
import faiss  # after torch, so the two libraries load safely together
faiss.omp_set_num_threads(1)
from langchain_text_splitters import RecursiveCharacterTextSplitter

def load_docs(folder="data/rag/northwind"):
    return [{"source": p.name, "text": p.read_text()} for p in sorted(Path(folder).glob("*.md"))]

def make_chunks(docs, size=300, overlap=50):
    splitter = RecursiveCharacterTextSplitter(chunk_size=size, chunk_overlap=overlap)
    return [{"source": d["source"], "text": t.replace("\n", " ")}
            for d in docs for t in splitter.split_text(d["text"])]

embedder = SentenceTransformer("all-MiniLM-L6-v2", device="cpu")

def embed(texts):
    return embedder.encode(texts, normalize_embeddings=True)

class Index:
    def __init__(self, chunks):
        self.chunks = chunks
        self.vectors = embed([c["text"] for c in chunks])

    def search(self, query, k=3):
        scores = self.vectors @ embed([query])[0]
        top = np.argsort(-scores)[:k]
        return [(round(float(scores[i]), 2), self.chunks[i]) for i in top]
Also uses llm.py
from langchain.chat_models import init_chat_model

llm = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)

PROMPT = """Answer the question using only the context below.
If the answer is not in the context, say "I don't know".

Context:
{context}

Question: {question}"""

def answer(question, chunks):
    context = "\n\n".join(f"[{c['source']}] {c['text']}" for c in chunks)
    return llm.invoke(PROMPT.format(context=context, question=question)).text.strip()

Reading the results

Look for three things. Wrong facts, which usually mean the wrong chunk was retrieved. Missing answers, where the fact exists but wasn't found. And made up answers, where the model ignored the context.

keyvalue
Wrong factcheck retrieval
Missingfact not found
Made upmodel ignored context
Fixusually retrieval

Summary

Ask many real questions and read every answer. Most problems point back to retrieval. Next, the generation quiz.

Key takeaways
  • Ten questions
  • Read every answer
  • Find weak spots
Next up: Generation Quiz — test yourself