Adding AI Q&A to a Docusaurus Knowledge Base with RAG and SSE Streaming
This walkthrough surfaces the exact Nginx, streaming, and chunking pitfalls that turn a weekend RAG project into a multi-week debugging session. The concrete fixes—disabling proxy buffering, using `@microsoft/fetch-event-source` for POST-based SSE, and parsing Markdown via AST instead of regex—are directly portable to any developer adding AI search to a documentation site.
A Docusaurus-based knowledge site replaces its plain-text Algolia search with a conversational AI Q&A feature. The implementation is a full-stack RAG pipeline: Markdown documents are parsed into an AST, chunked by heading structure, and embedded into a ChromaDB vector store using Alibaba's text-embedding-3 model. A lightweight Hono backend handles queries by retrieving relevant chunks, assembling a strict anti-hallucination prompt, and streaming DeepSeek's response back to the frontend.
The streaming architecture uses Server-Sent Events (SSE) with a critical Nginx configuration detail: `proxy_buffering` must be disabled, or the stream freezes. The frontend uses the `@microsoft/fetch-event-source` library instead of the native `EventSource` to support POST requests and custom headers, avoiding compatibility issues with WeChat's built-in browser. An incremental ingestion strategy, driven by Git diffs in GitHub Actions, ensures only changed documents are re-embedded.
A basic evaluation loop is also in place: a golden dataset of question-answer pairs is used to score model responses via LLM-as-a-judge, and all Q&A logs are stored for manual sampling. The project identifies recall failure as the root cause of most incorrect answers, pointing toward future upgrades like hybrid search and re-ranking.
Treating a personal knowledge base as an AI Agent training ground is a pragmatic on-ramp: the single-user, low-QPS constraints eliminate distributed-systems complexity and let a developer focus purely on the RAG data flow.
The choice of Hono over Express for a 12-15kb framework that runs across Node.js, Bun, and Deno signals a growing preference for Web Standard API-native tooling in the JavaScript ecosystem, even for small projects.
Using LLM-as-a-judge with a hand-labeled golden dataset is a low-effort evaluation strategy that catches regressions without building a full observability stack, but its reliability depends entirely on the quality of the scoring prompt.
The project's explicit admission that it's 'Naive RAG' and that pure vector search misses specific proper nouns is a useful counterpoint to overhyped RAG demos—hybrid BM25+vector search is framed as the necessary next step, not an optional enhancement.