๐Ÿ”Ž

RAG (Retrieval-Augmented Generation)

RAG is a technique for grounding an LLM's answers in your own documents rather than relying purely on what the model memorized during training. It retrieves the most relevant chunks of text from a knowledge base โ€” typically via vector similarity search โ€” and injects them into the prompt alongside the user's question. RAG ranks #6 among trending AI tags at roughly 10.6% usage share, reflecting how many production AI apps need to answer questions about private or up-to-date data that no base model was trained on.

Quick facts
Type: AI architecture pattern / technique (not a single product)
Made by: N/A โ€” open technique, popularized by a 2020 Facebook AI Research paper
License/Access: Open concept โ€” implemented with any combination of vector database + embeddings model + LLM
Language/Platform: Implemented in any language; common stacks use Python with libraries like LangChain or LlamaIndex
Primary use case: Q&A and chat over private documents, internal wikis, support tickets, or any data outside the model's training set
Jump to: ExampleGetting startedBest for

Example

A basic RAG pipeline embeds the user's question, searches a vector store for similar chunks, then builds a prompt that includes those chunks as context before calling the LLM.

# 1. embed the incoming question
query_vector = embed_model.encode("What's our refund policy?")

# 2. find the most similar chunks in the vector database
results = vector_db.similarity_search(query_vector, top_k=4)
context = "\n---\n".join(r.text for r in results)

# 3. build a prompt that grounds the model in retrieved context
prompt = f"""Answer using only the context below.

Context:
{context}

Question: What's our refund policy?"""

# 4. call the LLM with the grounded prompt
answer = llm.generate(prompt)

Getting started

Pick an embeddings model and a vector store, then wire them together with any LLM โ€” no need to build the search index from scratch.

# install a common RAG toolkit
pip install langchain chromadb sentence-transformers

# then: load docs -> split into chunks -> embed -> store in Chroma -> query
Best for: Internal knowledge-base chatbots, customer support assistants, and any app that must answer questions accurately about proprietary or frequently changing documents without retraining or fine-tuning the underlying model.