A RAG pipeline is a search engine with a language model bolted on the end, and a new benchmark of a zero-framework build shows how far plain Node.js 22 and a single SQLite file can take it. The test indexed 38 technical posts as 360 chunks in a 3.43 MB database and scored three retrieval methods on 25 questions.
The headline result: hybrid search matched pure vector search at 100% recall, and local retrieval took just over a millisecond.
Why most bad RAG answers start at retrieval
Retrieval-augmented generation searches your own documents first, then places the best passages in the prompt beside the user’s question. A model that never saw your runbooks or last month’s articles can then answer from text you control instead of guessing from its training data.
When the search step returns weak or irrelevant passages, even the strongest frontier model can only guess or refuse. When it returns the right paragraphs, a small model answers cleanly. So most debugging effort belongs on retrieval, not on the system prompt.

What the build uses
The RAG pipeline has no third-party packages. Node 22 ships the node:sqlite module, SQLite includes FTS5 for BM25 keyword ranking, and OpenAI’s text-embedding-3-small turns each chunk into 1,536 numbers. Everything lives in one portable file you can copy or inspect with the sqlite3 command line.
Some design choices are worth copying:
- Vectors are stored as raw binary blobs. Each takes 6,144 bytes, while a JSON version runs roughly 16 to 20 KB per chunk.
- Every chunk gets its document title and section heading prepended before embedding, so a chunk starting “Enable this option” still knows what it describes.
- The embedding model name and dimension count are saved in a meta table and checked at startup, because vectors from different models can’t be compared.
- Bulk writes run inside one transaction, which stops SQLite from syncing the disk on every insert.
Ingestion and querying run separately. Documents are hashed with SHA-256, so a sync only re-embeds files that changed. Embedding all 360 chunks (70,859 tokens) took 2,326 ms across six batched requests of 64 chunks.

Vector search, keyword search and Reciprocal Rank Fusion
Scanning all 360 vectors takes a median of 0.55 ms, which is why an approximate nearest-neighbor index isn’t needed at this size. Scaling that linearly, 10,000 chunks would scan in about 15 ms.
Vectors handle paraphrases well but stumble on exact tokens such as error codes, CLI flags or version strings. BM25 catches those. Raw user input must never go straight into an FTS5 query, since characters like a hyphen or colon are operators. The build strips each question down to quoted tokens joined with OR. Also, BM25 scores are negative, so the best matches sort ascending.
To merge the two ranked lists, the build uses Reciprocal Rank Fusion. Each chunk earns 1 / (60 + rank) from every list it appears in. Adding raw scores wouldn’t work because cosine similarities sit between roughly 0.35 and 0.85 while BM25 scores are unbounded.
The benchmark numbers
Dense search and hybrid RRF both reached 100% Recall@1, Recall@3 and Recall@5, with a mean reciprocal rank (MRR) of 1.000. BM25 alone hit 92% at Recall@1 because two of 25 queries put the expected post second, giving an MRR of 0.960. It still reached 100% at Recall@3 and Recall@5.
Recall@5 alone would have hidden that gap, which is why MRR belongs next to it. Local latency was 0.55 ms for dense search and 1.31 ms for hybrid. The embedding API call adds roughly 80 to 250 ms in a live request.
The corpus is a best case: 38 clean, clearly titled English posts. Messier collections full of codes like ECONNRESET or SQLITE_BUSY are where the keyword half of the hybrid should matter more.
Grounding and abstention
Retrieval returns its top four chunks even for an unrelated question, so the prompt has to force discipline. Each factual statement must cite a chunk ID such as agent-prompt-caching#0, and the model must reply with a fixed phrase when the passages lack evidence.
In the test, gpt-4.1-mini answered a prompt-caching question using 980 tokens in total. One answer was cut off mid-sentence because completions were capped at 220 tokens, so checking finish_reason for “length” is a must. A question about Redis Cluster gossip ports, which the corpus never covers, got a 7-token refusal. Even so, 955 input tokens went to four irrelevant chunks, so a similarity threshold before the model call would save money.
How to debug and when to skip RAG
Log the question, the sanitized FTS query, the top 20 dense and BM25 hits with scores, the fused chunks, token usage and finish_reason. Then ask one question: did the right chunk reach the prompt? If not, fix ingestion, chunking or ranking. If so, read the exact context the model saw.
Common bugs include orphaned chunks from deleted files, chunks missing their heading, and raising k from 4 to 20 until tangential text drowns the answer. Keep k at 4 to 6.
RAG isn’t always the answer. The whole test corpus is 70,859 tokens, and models accept 128,000 to 1,000,000 tokens per request with prompt caching that discounts repeated prefixes by 50% to 90%. A handbook under roughly 50,000 tokens that changes rarely can simply go in the prompt. Code search is usually better served by ripgrep, and counting or filtering questions belong in SQL.
Next steps for builders
To keep a RAG pipeline honest, start with a golden set of 20 to 50 questions plus 5 to 10 out-of-scope ones that must trigger abstention, and rerun it after every chunking or weighting change. Cache the 25 query embeddings and the three retrievers can be rescored in milliseconds at no API cost.
Consider moving off brute-force scanning once a scan passes roughly 50 ms, typically tens of thousands of chunks, or when several servers need to write to one index. The same hybrid design carries over to Postgres with pgvector.
Source: flaviocopes.com