hum

Keeping a Local RAG Index Fresh: Incremental Updates Instead of Weekly Rebuilds

microai-one-local-llm
microai-one-local-llm· Trust Score 0
4 min read··Opinion

Why incremental updates matter

Most first attempts at a local RAG (retrieval-augmented generation) system follow the same pattern: collect a folder of PDFs and Word files, chunk everything, embed everything, and point a local model at the resulting vector index. It works on day one. Then the documents change. A policy is revised, a price list is replaced, a contract gets an amendment, and the assistant keeps quoting the old version with full confidence.

The obvious fix is to rebuild the whole index every night or every weekend. For a few hundred files that is fine. Once the library grows to thousands of documents, or once embedding runs on the same GPU that serves chat during office hours, full rebuilds become slow, noisy and easy to postpone. Postponed rebuilds are exactly how stale answers creep in.

An incremental update routine solves this: only documents that actually changed get re-chunked and re-embedded, and documents that were deleted get removed from the index.

What to track for every source file

You need a small manifest, which can be a SQLite table or even a CSV file, with one row per source document:

  • the file path or document ID,
  • a content hash (SHA-256 of the file bytes is enough),
  • the last modification time you saw,
  • the IDs of chunks you created from it,
  • the embedding model name and version used,
  • the date it was last indexed.

The hash is the important column. Modification times change when someone merely copies a folder; the hash only changes when content does.

The nightly routine

  1. Walk the document folders and compute a hash for every file.
  2. Compare against the manifest. New hash or new path means "changed or added"; a path in the manifest that no longer exists means "deleted".
  3. For deleted documents, remove their chunk IDs from the vector store and the manifest.
  4. For changed documents, delete their old chunks first, then chunk, embed and insert the new version. Deleting first matters: otherwise old and new paragraphs compete in retrieval.
  5. Update the manifest only after the insert succeeds, so a crash halfway leaves the document marked as "needs indexing" rather than silently half-done.
  6. Write a short log line: how many files were added, changed, deleted and skipped.

Run it outside working hours, or limit the embedding batch size so chat users barely notice.

When you still need a full rebuild

Incremental updates assume the chunking rules and the embedding model stay the same. If you switch embedding models, change chunk size or overlap, or add new metadata fields that retrieval depends on, vectors created under the old rules are not comparable with new ones. In that case build a fresh index side by side, test it with your question set, and switch over in one step. Record the embedding model version in the manifest precisely so you can tell when this situation applies.

Test with questions, not just counts

A log saying "37 documents updated" does not prove retrieval improved. Keep a small set of twenty or so real questions whose correct source you know, including a few about recently changed documents. After each update, run them and check that the top results point to the current version. Ten minutes a week with this list catches most problems before staff do.

Practical details that save time

  • Store the source path and page number with each chunk, so answers can cite where they came from.
  • Keep scanned PDFs in a separate queue; OCR quality varies and deserves a human spot check before indexing.
  • Exclude folders with credentials, personal data or drafts you do not want quoted. Retrieval cannot leak what was never indexed.
  • Keep the previous index snapshot for a few days so you can roll back if an update goes wrong.

If you are setting up a document assistant for the first time, our local RAG knowledge-base guide walks through the initial build with Ollama and an embedding model. More hands-on notes live in the local AI tutorials section of MicroAI One.

Summary

A local RAG system is only as trustworthy as its freshest document. Track hashes, delete before re-inserting, rebuild fully only when the rules change, and test with a fixed question set. None of this needs special software, just a manifest and the discipline to run it every night.

Sources

More to read

Comments

Sign in to comment