refundsshippinghoursgiftsretshiphrsgiftcosembed()retshiphrsgiftLLM1vecs = [embed(d) for d in docs]2q = embed(question)3hits = search(vecs, q, k=2)4prompt = build(hits, question)Answer using only this context.Context:Question:Most shops allow14 days. Maybe?source: noneYes: returns areOK within 30 days.source: refundsrefundsshippinghoursgiftsCan I return an itemafter 20 days?refundsshippingCan I return an itemafter 20 days?
Khaki shelf: the documents, as four chunks · grey tray: the vector indexSand block: the embedding model · rose block: the LLMChips: chunks and the question moving through the pipelineAsked directly, the LLM can only guess: it never read this shop's rules. RAG adds a lookup. Ahead of time, each chunk of the shop's documents goes through an embedding model and its vector is stored in the index. When the question arrives it gets a vector from the same model; cosine similarity scores every chunk, the two best are pasted into the prompt with the question, and the LLM answers from them. The embedding here is a toy: four numbers, each counting words that start with a topic stem. Real embedding models are trained neural networks; all-MiniLM-L6-v2, for example, gives 384 numbers, and no single number means one named topic.

The problem

  1. A large language model (LLM) learned from public text up to a cutoff date. It never read this shop's rules, so for "Can I return an item after 20 days?" it can only guess. A fluent answer with no source is a hallucination.

Indexing

Answering

What happens

;; step 1/9 · direct
question  Can I return an item after 20 days?

the LLM knows only what was in its training text:
  public pages, up to a cutoff date
  not this shop's policy, not last week's changes
answer    "Most shops allow 14 days. Maybe?"   (a guess)

The embedding here is a toy: four numbers, each counting words that start with a topic stem. Real embedding models are trained neural networks; all-MiniLM-L6-v2, for example, gives 384 numbers, and no single number means one named topic. The answers in the figure are illustrations of what a model typically does, not the output of a real model.