
In this article
Time to assemble everything into something colleagues can use: a simple web page where anyone types a question about company policy and gets an answer with sources.
Advertisement
The pieces
- Documents: export policies as .txt (or extract PDF text) into a
policiesfolder. - Index: chunking + BM25 from Lessons 3–4, with your measured threshold.
- Agent: the search + calculator tools from Lesson 5.
- Guardrails: turn cap, cost cap and logging from Lesson 6.
- Web page: a tiny Flask app.
The web app
pip install flask
from flask import Flask, request, render_template_string
app = Flask(__name__)
PAGE = """<!doctype html><title>Policy helper</title>
<form method=post><input name=q size=60 autofocus placeholder="Ask about leave, travel, expenses...">
<button>Ask</button></form>{% if a %}<h3>{{ q }}</h3><p style="white-space:pre-wrap">{{ a }}</p>{% endif %}"""
@app.route("/", methods=["GET", "POST"])
def home():
q = request.form.get("q", "").strip()
a = run_agent(q) if q else "" # the guarded loop from Lesson 6
return render_template_string(PAGE, q=q, a=a)
app.run(port=8000)
Before you share it
- Run your test set from Lesson 4 — every answerable question should cite the right document, every unanswerable one should say “I don’t know”.
- Ask three colleagues to try to break it, including asking about things that aren’t in the policies.
- Agree who updates the documents and how often the index is rebuilt.
- Keep it on your internal network; never expose the API key in the page.
Where to go next
- Swap BM25 for hybrid search and compare on the same test set.
- Add a “Was this helpful?” button and log it.
- Index Excel files by turning each row into a sentence (“Employee grade L3: daily allowance ₹2,500 in metro cities”).
Congratulations — you have built the core of most “chat with your documents” products, and you understand exactly what happens inside them.
✨ Ask AI about this article
Stuck on a step? Ask a question and the AI answers using this article.
Free · AI can be wrong