# Building RAG for a personal blog: four pitfalls exposed by small corpora

Date: 2026-10-06
Category: Technology
Tags: RAG, Retrieval, Blogs, Evaluation
Summary: Building RAG over a hundred-plus articles, the results depend mainly not on the embedding model: corpus cleaning, chunk granularity, date metadata, and refusal design are the four things that truly hold back performance.

My blog exports to about 310,000 characters of plain text, over a hundred articles. For RAG (retrieval-augmented generation) at this scale, I initially thought I was using a sledgehammer to crack a nut: the corpus is so small, why not just retrieve a few articles and stuff them into the context?

When the first version ran, the top results were the archive page, "About Me," and three paginated pages of the same article. The model wasn't wrong; what I fed it was.

## Thirty percent of the crawled corpus wasn't articles

I was pretty happy when I got over 180 URLs from the sitemap, but only when I actually cleaned them did I see what was in there: tag pages, category pages, pagination, archive pages, and fixed pages like "About" and "Friends' Links." The body selector was also lazy—I just used body, so navigation, copyright notices, and related reading all went into the corpus.

The most typical case was searching for "cache"—almost every article matched. The reason wasn't complicated: every article had a line at the bottom saying "Related reading: add a timestamp to the cache key." That sentence itself isn't wrong; it just shouldn't be treated as article content.

Later I changed it to only take the article container, removing nav, footer, aside, script, style, and blocks with related or pagination in their class names. URLs were also normalized: strip query strings, strip trailing slashes, deduplicate by the canonical tag in the page, and exclude things like /page/2 directly. The 180-plus addresses ended up as about 120 articles of body text.

```python
from bs4 import BeautifulSoup

def clean(html):
    soup = BeautifulSoup(html, 'html.parser')
    for tag in soup.select('nav, footer, aside, script, style, .related, .pagination'):
        tag.decompose()
    article = soup.select_one('article') or soup.select_one('.post-content')
    if not article:
        return ''
    return article.get_text(separator=' ').strip()
```

This cleaning function is crude, but it makes "what counts as an article" explicit. My current judgment is: the first step of small-corpus RAG isn't picking an embedding model, but translating the site structure into a clean article list. If the list isn't clean, tuning any parameter afterward is just guessing.

By the way, here's a phenomenon I didn't understand at first. Why do archive and tag pages always rank near the top? They pile up lots of titles, with short sentences and dense keywords, so their similarity to a short query is naturally high; body text that explains something clearly often needs several paragraphs of setup, so it's less "like" the query. This isn't model bias; it's that the corpus contains things that shouldn't participate in retrieval at all.

As for pages like "About" and "Friends' Links," I don't think they're entirely worthless. If you want the assistant to answer "who are you, what have you done," they're actually necessary—but they should go into a separate small corpus, not be mixed with articles and retrieved as body text.

## Chunk on headings, and after recall hand the whole article to the model

The first version chunked by fixed character count, 600 characters per chunk with 100 characters of overlap. When it ran, there were piles of problems: code blocks cut in half, lists cut in half, an argument under one h2 split across two chunks—retrieval hit the first half, but the model got half a sentence. Worse, the chunks had no heading information, so the model didn't know what the passage was about.

I changed it to split by h2, then by paragraph if too long, each chunk about 400 to 800 characters, with code blocks kept whole and not split. Each chunk is prefixed with a line "article title > h2 title"; embedding uses this prefix plus the body, and display shows only the body. Does this prefix help? My sense is yes—especially since many h2s in the blog are just "Problem," "Approach," "Result," and without the article title you can't tell them apart at all. How fine-grained to make it is still undecided; currently only down to h2, since going deeper gets too noisy.

Why 400 to 800 characters instead of smaller? If chunks are too small, an argument gets broken up and a hit chunk is meaningless on its own; if too large, recalling eight at once fills the context, and similarity gets diluted by irrelevant paragraphs. This range is where I stopped after trying several versions—no theoretical basis.

Another thing that differed from my expectation was recall granularity. At first I had the model read only the recalled chunks, and the answers often lacked context. Later I changed to two steps: first recall top 8 by chunk, deduplicate to get 3 articles, then send the whole article—or the section containing that h2—to the model. An article averages over 2,000 characters, roughly 1,800 tokens; three articles are over 5,000 tokens, plus the question, well within budget. This is the advantage of a small corpus: retrieval only needs to find the articles; reading is left to the model. The chunk isn't the unit of the answer—the article is.

Retrieval itself doesn't use a vector database either. A few hundred chunks are stored in sqlite; at startup the embeddings are read into memory, normalized, and cosine similarity is computed by brute force—tens of milliseconds per query.

```python
import numpy as np

def search(query_vec, top_k=8):
    # chunk_matrix 已归一化
    scores = chunk_matrix @ query_vec
    idx = np.argsort(scores)[-top_k:][::-1]
    return [(chunk_ids[i], float(scores[i])) for i in idx]
```

This approach has a clear boundary: when chunks grow to tens or hundreds of thousands, brute force goes from tens of milliseconds to non-negligible latency, and the matrix may not fit in memory—that's when index structures come into play. At the scale of a personal blog, adding a vector database mainly just adds a dependency for yourself.

## Dates and "no answer" are trickier than similarity

A blog is different from documentation: it has time. I wrote some things early on that I no longer agree with, and later revised them in articles, but the old articles are still there. Retrieval recalls old and new together, and the model answers from a mix. Once I asked "should the cache key include a timestamp," and it cited two articles at once with contradictory conclusions.

The solution isn't to delete old articles, but to tag each chunk with published_at and updated_at, note in the prompt "this was published in 2021 and may be outdated," and slightly downweight articles older than two years when ranking. The downweight can't be large—if it is, old articles never surface. Some old articles are the only source; discarding them loses information. Downweighting acknowledges they may be outdated, not that they never said it.

Trickier than dates is "no answer." I hand-wrote thirty questions, eight of which the blog never covered, such as "how do you do multi-tenant isolation." The first version answered all of them, even cobbling together a passage from unrelated articles. I tried tuning the similarity threshold, but it didn't work well—there was always a passage with decent similarity, and raising the threshold cut off the ones that should be answered too.

Later I changed to two stages: first have the model look at the list of article titles and summaries to judge whether any article is relevant; if not, refuse directly; only if so, proceed to chunk retrieval. This change was much more noticeable than swapping the embedding model. Among the twenty-odd answerable questions, hitting the correct article went from single digits to over half; for the no-answer ones, it went from answering all to refusing most. The numbers aren't rigorous and the sample is small, but the direction is clear.

Writing these thirty questions took more time than I expected. Answerable questions need to cover different sections and difficulties, and if you're not careful you copy the original keywords straight into the question, which makes the measured recall inflated; refusal questions can't be made up casually either—they need to sound plausible but genuinely not be covered by the blog. The eight no-answer ones are my estimated proportion, not a statistic; I only need them to expose errors like "the model making things up," not to serve as a benchmark.

## Technology choices for a small corpus: brute force if you can, skip the framework

I tried building the pipeline out fully: parsing, chunking, embedding, vector database, retrieval, reranking, generation, with configuration at every step. By the end I found that at the scale of a personal blog, the complexity mainly came from what I added myself.

Now the pipeline has only four steps: cleaned articles stored as JSON, chunked by h2, embeddings stored in sqlite, brute-force top k at query time. The embedding model is local bge-m3 (a multilingual embedding model); a few hundred chunks are computed in one go, and rerunning with a different model is no big deal. No incremental indexing, no caching, because a full recompute takes only a few minutes—writing incremental logic for a few-minute task costs more in maintenance than the time it saves.

The value of a framework lies in multi-person collaboration and frequent changes—a blog maintained by one person has neither. I know some people disagree with this, but if your corpus is only a few hundred posts, get it working first before talking architecture; the cost of rework is lower than adopting a framework from the start.

This setup isn't elegant, but it lets me quickly verify "whether the problem lies in the corpus." To judge whether a small-corpus RAG is worth continuing to tune, I now look at two things first: whether the number of cleaned articles is significantly lower than the number scraped, and whether unanswerable questions can be rejected. If neither holds, switching to a larger embedding model is basically a wasted swap.

What I want to do next isn't switch models, but complete each article's "updated on" and "errata," then rerun those thirty questions.

Further reading: [Several questions to tell whether someone has done RAG](/2025/01/21/llmlarge-model-ai-interview-rag-vector-search-alignment-evaluation-hal/), [Whether RAG is done well is mostly determined by chunking and context layout](/2025/10/15/rag-system-ai-interview-retrievalrerankingcontext-constructiongenerati/)
