Abed Matini from Ogilvy presents a hybrid Retrieval-Augmented Generation (RAG) framework that combines local language models, structured document chunking, SQL-based retrieval, and live telemetry to build cost-effective, accurate FAQ chatbots while minimizing token consumption and hallucinations. The system leverages Python, FastAPI, PostgreSQL, and LangFuse for observability, emphasizing clean data preprocessing, precise retrieval methods, and security guardrails to ensure efficient, reliable, and secure chatbot interactions.
Abed Matini, a senior backend developer at Ogilvy, presents a comprehensive approach to building an efficient, cost-effective FAQ chatbot system that bypasses the typical multimodal token consumption issues seen in large language model (LLM) interactions. He highlights two main challenges: the token cost incurred when uploading documents before any user query and the complexity of managing multiple tools like vector databases and semantic search in production chatbots. To address these, Abed introduces a hybrid Retrieval-Augmented Generation (RAG) framework that leverages local processing, structured document chunking, and SQL-based retrieval, combined with live telemetry for observability.
The system architecture uses Python and FastAPI for the backend, React for the frontend, PostgreSQL as the vector database, and Docker for containerization, ensuring easy deployment and reproducibility. Abed emphasizes the use of local language models, such as Ollama’s Qwen 2.5, which run efficiently on CPUs without requiring GPUs, reducing operational costs. Documents are first converted to markdown using DocLink, then chunked strategically before embedding and storing in PostgreSQL. This preprocessing step allows for better control over data quality and chunking strategies, which is crucial for improving chatbot accuracy and reducing hallucinations.
Abed details four chunking strategies: heading-based, paragraph-based, fixed character length with overlap, and sentence-based chunking. Each method suits different document types and use cases, from structured FAQs to unorganized data or quick uploads like screenshots. He demonstrates how clean chunking, especially heading-based, improves answer relevance and traceability by linking responses directly to specific document sections. This structured approach contrasts with simply uploading entire documents, which often results in noisy, less accurate chatbot responses.
The retrieval mechanism combines semantic vector search with exact keyword matching (using BM25) to balance relevance and precision, especially important in domains like medical or product information where exact answers are critical. Abed also discusses the use of Python-based agents for specific functions, such as retrieving the current date, to avoid unnecessary LLM calls and reduce latency. This design choice enhances system speed and reliability while maintaining full control over function execution and minimizing hallucinations.
Finally, Abed highlights the integration of LangFuse for telemetry and observability, enabling monitoring of chat sessions, latency, and prompt injection attempts. He explains the implementation of guardrails in code to block unsafe or irrelevant queries before they reach the LLM, improving security and compliance. The entire system is open-source and designed for easy deployment on platforms like GitHub Codespaces. Abed concludes by encouraging collaboration and feedback to further enhance the framework, emphasizing that smaller, well-vetted models combined with structured data ingestion can deliver efficient, accurate, and safe chatbot experiences.