RAG explained: how to give an LLM your own information | Xiliux Blog
A language model knows a great deal about the world, but knows nothing about your company : your manuals, your policies, your products. And if you ask it about something it doesn't know, it may invent an answer that sounds convincing. RAG (Retrieval-Augmented Generation) solves both problems. The i

Posted on Oct 23 • Originally published at xiliux.com
A language model knows a great deal about the world, but knows nothing about your company: your manuals, your policies, your products. And if you ask it about something it doesn't know, it may invent an answer that sounds convincing. RAG (Retrieval-Augmented Generation) solves both problems.
Instead of expecting the model to "already know" your information, you give it to it at the moment of the question:
The model no longer guesses: it answers from a real context that you control. And you can ask it to cite where each fact came from.
# 1. Indexado (una vez): fragmentos -> embeddings -> base vectorial # (con librerías como sentence-transformers + FAISS, o un servicio gestionado) # 2. En cada pregunta: recuperar los fragmentos relevantes fragmentos = base_vectorial. buscar ( pregunta, k = 4 ) contexto = " \n\n ". join ( fragmentos ) # 3.
Generar la respuesta con el contexto from anthropic import Anthropic client = Anthropic () resp = client. messages. create ( model = " claude-opus-4-8 ", max_tokens = 1024, system = " Responde SOLO con la información del contexto. Si no está, dilo. ", messages = [{ " role ": " user ", " content ": f " Contexto: \n { contexto } \n\n Pregunta: { pregunta } ", }], ) print ( resp. content [ 0 ]. text ) Enter fullscreen mode Exit fullscreen mode Note the instruction in the system prompt: asking it to answer only with the context and to admit when it doesn't know is what drastically reduces hallucinations.
RAG is today one of the most cost-effective ways to apply AI in a business: you retrain nothing, and the assistant improves just by updating your documents.
At Xiliux I build RAG systems in Python from end to end. Tell me what information you want to put to work: contact.