📝 RAG_for_Terry.mdv4.6.2 · 2026-10-28

RAG for Terry: what it is, how it copes with changing documents, and how we plan to use it for the mentok store

Part 1: What RAG means and why it exists

RAG stands for Retrieval-Augmented Generation. Before an AI answers a question, the system first looks up the relevant passages in your own documents, then the AI writes its answer from what was found. It's an open-book exam instead of answering from memory.

The purpose is to let an AI answer from your material, such as a company's policies or manuals, which it never saw in training. It also stops the AI from inventing plausible-sounding answers, and it costs far less than retraining the AI whenever your documents change.

To make the lookup work, each document is cut into small pieces called chunks. Each chunk is turned into a list of numbers capturing its meaning, called an embedding (re-doing this is "reembedding"). That lets the system find chunks about the same topic as a question, even when the wording differs.

The steps are:

  1. Documents are cut into chunks (a paragraph or two each).
  2. Each chunk is converted into an embedding.
  3. When someone asks a question, the system finds the handful of chunks closest in meaning and hands them to the AI along with the question.
  4. The AI writes its answer from those chunks, so it's grounded in your actual material.

Part 2: The problem of continuously changing documents

Documents get edited all the time. If the system still holds the old version of a chunk, the bot confidently quotes last week's policy.

The lazy fix is to reembed everything after every edit. With 500 documents (about 10,000 chunks), that means redoing all 10,000 chunks to fix one sentence. It works, but it's slow and wasteful.

The better answer has three layers.

Layer 1: Detect what changed

Layer 2: Update only that chunk

Layer 3: Safety nets

The takeaway: don't rebuild everything. Detect what changed, update only that, and double-check on a schedule.

Part 3: Addendum — how the same ideas apply to our mentok store

Our store doesn't hold documents. It holds small entries made of single words, word pairs (binomials) and mini-phrases, which we call mentoks. The database manager's job is to keep that store current as new conversations arrive, so the AI stops repeating mistakes it has been corrected on. Below is how the three layers map onto that job. This is the proposed plan, and the details are still open.

The main difference

In the text above, the unit being managed is a chunk of a document. Here, every entry is already tiny, so there's no chunking. And nothing is "edited" the way a file is. Instead, every new question and answer passing through the system changes the entries: counts go up, new words appear, and corrections replace older wording. The change trigger is a new query and reply arriving, not a webhook from an app.

Layer 1: Detect what changed

Layer 2: Update only what changed

Layer 3: Safety nets

Where it sits

Two honest caveats

  1. The store is small, so a full rebuild is cheap. The change-detection layers matter most as the store grows, and until then they act more as insurance than necessity. That doesn't make them wasted, since building the habit now means growth won't force a redesign.
  2. "Search only the latest version" works against keeping history. The plan above resolves it by keeping old versions but hiding them from normal searches. If history isn't wanted, the design gets simpler.

Install on the live system stays the operator's call, and nothing here is built yet.