A hybrid Retrieval-Augmented Generation engine built from scratch in pure PHP — no Composer, no custom C extensions, no background daemons — designed to run on restrictive shared hosting (cPanel) with low cost and low resource use.
Constraints
Modern RAG stacks usually need heavy vector databases (Pinecone, Weaviate) and Python or Node frameworks that shared hosting will not run.
Memory and max_execution_time limits on commodity PHP hosting rule out long-running workers and large in-memory indexes.
Goal: semantic + lexical search that stays provider-agnostic and economical enough for low-budget production.
Lightweight vector store — SQLite (knowledge.sqlite) stores embeddings as binary blobs via pack('f*'); no external vector service.
Precomputed magnitudes — vector norms are calculated during async ingestion so chat requests skip thousands of real-time math ops.
API pool & failover — client supports Gemini, Cohere, Groq, and OpenAI with live key rotation and transparent retry on HTTP 429.
Idempotent sync + freshness check — Markdown corpus syncs into SQLite; if files change and the vector DB is stale, the system falls back to in-memory BM25 so the LLM never answers from outdated embeddings.
PocketRAG shows advanced generative AI can ship on legacy shared hosting: sub-second response generation, minimal CPU/RAM, and an immutable migration path between embedding models — a resilient design for constrained budgets.