A Cheat Sheet and Some Recipes For Building Advanced RAG | by Andrei | Jan, 2024 | LlamaIndex Blog #315
Labels
llm
Large Language Models
Papers
Research papers
RAG
Retrieval Augmented Generation for LLMs
technical-writing
Links to deep technical writing and books
A comprehensive RAG Cheat Sheet detailing motivations for RAG as well as techniques and strategies for progressing beyond Basic or Naive RAG builds. (high-resolution version)
It’s the start of a new year and perhaps you’re looking to break into the RAG scene by building your very first RAG system. Or, maybe you’ve built Basic RAG systems and are now looking to enhance them to something more advanced in order to better handle your user’s queries and data structures.
In either case, knowing where or how to begin may be a challenge in and of itself! If that’s true, then hopefully this blog post points you in the right direction for your next steps, and moreover, provides for you a mental model for you to anchor your decisions when building advanced RAG systems.
The RAG cheat sheet shared above was greatly inspired by a recent RAG survey paper (“Retrieval-Augmented Generation for Large Language Models: A Survey” Gao, Yunfan, et al. 2023).
Basic RAG
Mainstream RAG as defined today involves retrieving documents from an external knowledge database and passing these along with the user’s query to an LLM for response generation. In other words, RAG involves a Retrieval component, an External Knowledge database and a Generation component.
LlamaIndex Basic RAG Recipe:
from llama_index import SimpleDirectoryReader, VectorStoreIndex
load data
documents = SimpleDirectoryReader(input_dir="...").load_data()
build VectorStoreIndex that takes care of chunking documents
and encoding chunks to embeddings for future retrieval
index = VectorStoreIndex.from_documents(documents=documents)
The QueryEngine class is equipped with the generator
and facilitates the retrieval and generation steps
query_engine = index.as_query_engine()
Use your Default RAG
response = query_engine.query("A user's query")
Suggested labels
{ "key": "RAG-Building", "value": "Techniques and strategies for building advanced Retrieval Augmented Generation systems for language models" }
The text was updated successfully, but these errors were encountered: