RAG support agent
2025 · POSIMYTH
The support team answered the same product questions again and again, and the answers already existed in our documentation. Sending all of it to an LLM wasn't possible: it was far too large for a context window. The real problem was picking the 3 to 5 pages that matter for each question.
building the knowledge base
- A custom scraper pulls each doc page's title, headings, paragraphs, lists and code, with fallback selectors for different layouts.
- The text is cleaned, split into 350-word chunks with a 50-word overlap, embedded with Sentence-Transformers and stored in SQLite.
- The final knowledge base: ~920 pages, 1,041 chunks.
answering
- On startup, the API loads every embedding into a FAISS index once.
- A question is normalised and embedded, and top-k search finds the 5 closest pages by meaning, so it matches the right guide without the exact keywords.
- GPT-4 answers from those pages only, and every reply comes back with its sources.
built around it
- A chat API that a website widget can call, with users, sessions and logs.
- A ticket endpoint that fetches a helpdesk ticket, finds the docs and drafts a reply. The reply can go in as an internal note for an agent to review, or straight to the customer.
- A CPU-only Docker image, deployed on Railway.
what I learned
Retrieval quality decides answer quality. Structured scraping, overlapping chunks, building the index once and capping the context were the biggest wins across about six versions.
Python · Requests · Selectolax · BeautifulSoup · Sentence-Transformers · FAISS · SQLite · OpenAI GPT-4 · FastAPI · Docker