Grav AI Chatbot: Production-Grade RAG Plugin for Grav CMS

grav-cms php rag sqlite llm web-components

A battle-tested Grav CMS AI Chatbot plugin featuring local SQLite RAG vector search, multi-provider failover, and paranoid prompt-injection guardrails so your site never starts hallucinating discounts.

The Backstory: AI on Flat-File CMS Without the Drama

Most chatbots force you into choosing between a clunky third-party iframe widget that tracks your visitors, or spinning up a multi-gigabyte Python microservice just to answer basic questions about your portfolio.

I wanted something lean, self-hosted, and deeply integrated into Grav CMS. Enter grav-ai-chatbot: a native PHP plugin that turns your markdown content into a localized vector knowledge base using lightweight SQLite RAG, streaming crisp responses right through custom Web Components.

Grav AI Chatbot Architecture


Architectural Highlights

  • Local SQLite Vector RAG: Pre-indexes all published pages into sqlite-vec embeddings for zero-latency retrieval without external vector DB subscriptions.
  • Multi-Provider Failover: Cascades gracefully across Groq, Google Gemini, OpenAI, OpenRouter, and local Ollama instances when rate limits hit.
  • Paranoid Guardrails: Multi-stage regex sanitization, canary tokens, and prompt injection filters stop malicious system prompt jailbreaks dead in their tracks.
  • Zero-Dependency Web Components: Fluid chat drawer built with modern browser custom elements, custom markdown rendering, and accessible keyboard navigation.
  • Admin2 Deep Integration: Fully configurable through Grav's Admin panel with real-time token tracking and index management.

Quick Start

# Clone directly into your Grav plugins directory
git clone https://github.com/milkboyinchina/grav-ai-chatbot.git user/plugins/ai-chatbot

# Rebuild your vector index via CLI
php bin/plugin ai-chatbot index:rebuild

Explore the code on GitHub: milkboyinchina/grav-ai-chatbot.

Previous Post