5 concepts · 10 practice questions
RAG answers from your documents instead of the model's memory. Offline, documents are parsed, chunked, embedded and indexed. Online, the question is turned into a search, the best chunks are retrieved, placed in the prompt, and the model answers from them. It is the default way to give a model private or recent knowledge, because updating an index is far cheaper and faster than retraining a model.
def answer(question):
chunks = retrieve(question, k=8) # search + rerank
context = "\n\n".join(f"[{i+1}] {c.text}" for i, c in enumerate(chunks))
prompt = f"<context>\n{context}\n</context>\n\nQuestion: {question}"
return llm(SYSTEM_GROUNDED, prompt), chunks
Sign in to read the rest and take the 10-question test.
Sign in to continue