RAG explained: how to make AI answer from your own content A developer published a walkthrough showing how retrieval-augmented generation (RAG) can make an AI assistant answer questions from a business's own content rather than relying on the model's training. The example uses plain JavaScript and keyword matching to score help articles against a customer question, then injects the top matches into the system prompt with instructions to answer only from those sources and cite the article URL. The writeup notes keyword matching misses paraphrased questions and points to embeddings and hybrid keyword-plus-semantic search for larger systems. An AI model knows a lot about the world and nothing about your business. Ask it about your return policy and it will either say it doesn’t know or, worse, make something up https://mosaddik.dev/blog/ai-hallucinations . Retrieval-augmented generation RAG fixes this: before the model answers, your code finds the relevant parts of your own content and puts them in the prompt. A visitor asks: “Can I return a sale item?” The model doesn’t need to have learned your policy. It reads it at the moment it answers, like an assistant checking the handbook before replying. For a small site, you can. If all your FAQs fit in a few pages, sending them with every question is the simplest approach, and that’s what the Wix AI assistant guide https://mosaddik.dev/blog/add-ai-assistant-to-wix-with-velo does. RAG becomes useful when: This example uses plain JavaScript and simple keyword matching, so you can see each step. It works for a modest set of articles. js const articles = { title: "Returns", url: "/help/returns", text: "You can return items within 14 days. Sale items can be exchanged but not refunded." }, { title: "Delivery", url: "/help/delivery", text: "Orders in Dhaka arrive in 1-2 days. Other cities take 3-5 days." }, { title: "Payment", url: "/help/payment", text: "We accept cards, bKash and cash on delivery." }, ; // 1. Retrieve: score articles by how many words they share with the question function findRelevant question, limit = 2 { const words = question.toLowerCase .match /\w+/g ?? ; return articles .map article = { const text = ${article.title} ${article.text} .toLowerCase ; const score = words.filter word = word.length 2 && text.includes word .length; return { ...article, score }; } .filter article = article.score 0 .sort a, b = b.score - a.score .slice 0, limit ; } // 2. Augment: build the prompt from the matching articles function buildSystemPrompt question { const sources = findRelevant question .map a =