Hi, I’m GuiGui, exploring AI. If you like the content here, please follow to stay updated!
Slash Little Ghost
Have you ever encountered a situation where you eagerly ask AI a question, only for it to provide a completely absurd answer? For instance, if you ask, “What is Python?” and it responds, “Python is a snake that lives in the tropical rainforest and is occasionally used for coding.”—well, the first part is correct, but the second part seems… not wrong either? But what is this nonsense?!

This is the “pitfall” of AI-generated content: it seems smart but may actually be a “master of fabrication.” Especially when you ask questions that require precise answers, it might provide a completely wrong response in fluent language. This phenomenon of “nonsense” in the AI field is known as “hallucination.”
So, is there a technology that can make AI-generated content both fluent and reliable? The answer is: yes! It’s the star of today’s discussion—RAG (Retrieval-Augmented Generation), a “savior” that makes AI-generated content more trustworthy.
The core idea of RAG is simple: teach AI to look up information. It can generate fluent text like traditional AI, but also retrieve relevant information from a vast number of documents, ensuring that the generated content is verifiable. In other words, RAG is like a “top student” that can quickly look up information and write excellent articles.
If you’re a beginner in programming, you might find AI technology to be inscrutable, but don’t worry! This article is prepared just for you. We won’t overload you with complex terms, but instead use a light and humorous approach to help you understand what RAG is, what it can do for you, and how to use it to create your personal AI assistant.
Are you ready? Let’s summon this “top student” of AI and start your RAG experience!
PART
ONE
What is RAG? The “Top Student” of AI
The Persona of RAG: Information Retrieval Maniac + Writing Expert

The full name of RAG is Retrieval-Augmented Generation. Its core capabilities can be divided into two parts:
-
Retrieval Capability: RAG acts like a super librarian, able to quickly find relevant information from a vast number of documents.
-
Generation Capability: RAG also acts like a writer, able to organize the retrieved information into fluent text to answer your questions.
For example, if you ask RAG, “What is the difference between lists and tuples in Python?” it will first run to the “library” (its knowledge base) to find relevant documents, and then generate an accurate and easy-to-understand explanation. In contrast, traditional AI (like GPT) is more like a “master of fabrication,” which might come up with an answer that sounds reasonable but is actually completely wrong.
What Can RAG Do for You?
Since RAG is so powerful, what exactly can it help you with? In fact, its application scenarios are very diverse, with one of the most typical examples being:Your Personal Knowledge Base (Your Private AI Assistant)
You can hand over your documents, notes, or even code repositories to RAG, allowing it to become your personal assistant. For instance, you can upload your study notes and then ask RAG, “What did I note about Python decorators before?” RAG will find relevant information from your notes and generate a response.
Moreover, you can upload your team’s long-established product and technical documents and then ask RAG, “I want to optimize the ‘a’ feature of product XXX. Please provide a comprehensive explanation of this feature and what aspects need to be considered during optimization?” RAG will fetch the relevant content and leverage the LLM’s capabilities to provide explanations and suggestions.
Next, we will guide you step-by-step on how to “summon” this AI top student!
PART
TWO
How to Use RAG? A Step-by-Step Guide to Summon the Top Student
Today, the tool we will use is LlamaIndex, a super handy library that can help you easily build a RAG system.
What is LlamaIndex?

LlamaIndex is like a “magic toolbox” specifically designed to help you maximize the capabilities of RAG. Its core function is to help you convert various documents (such as PDFs, Markdown, code files) into a “knowledge base” that RAG can understand, so you can happily ask RAG questions!
Step-by-Step Tutorial: Summoning the RAG Top Student
Step One: Install LlamaIndex
First, you need to install LlamaIndex and its good partner OpenAI. Open your terminal (or Jupyter Notebook) and enter the following command:
pip install llama-index openai
Step Two: Set Up OpenAI API Key
The basic RAG can call the online large model’s interface to generate answers, so you need an OpenAI API key. If you don’t have one, you can register on the OpenAI platform.
After obtaining the key, set it in the environment variable:
import os
os.environ["OPENAI_API_KEY"] = "your_api_key"
Step Three: Load Your Documents (Links)
Now, we need to give the documents to LlamaIndex to turn them into RAG’s “knowledge base.” Suppose you have a Markdown file (my_notes.md) that records detailed descriptions of your company’s products.
# Load documents
from llama_index.core import SimpleDirectoryReader
documents = SimpleDirectoryReader("path/to/my_notes.md").load_data()
# Load links
from llama_index.readers.web import SimpleWebPageReader
url = "https://mp.weixin.qq.com/s/Xr1SofPScylWK5pMiaLvNg" # Replace with the URL of the webpage you want to read
documents = SimpleWebPageReader(html_to_text=True).load_data([url])
Step Four: Create an Index
Next, we need to turn these documents into an “index” that RAG can understand. You can think of the index as a super directory that RAG can quickly navigate to find relevant content.
from llama_index.core import VectorStoreIndex
# Create index
index = VectorStoreIndex.from_documents(documents)
Step Five: Summon the RAG Top Student!
Now, everything is ready, and you can start asking RAG questions! For example, you can ask it, “What features does product XXX have?”
How about that? Isn’t it simple? With just a few lines of code, you can summon a super “top student” RAG to help you solve various programming problems. Go give it a try and make your programming journey easier!
⭐️ Here’s the link to access Colab! You can run it directly with scientific access! Come and check it out~
https://colab.research.google.com/drive/1InfNidPUHiVbXdA9dPO89lhPz8phlw6E?usp=sharing
Tip: How to Make RAG Understand You Better?
-
Custom Documents: You can give your notes, webpage content, or even code repositories to LlamaIndex to become RAG’s knowledge base.
-
Adjust Parameters: If you want RAG’s answers to be more detailed or concise, you can adjust the parameters of the generation model (like temperature).
-
Multi-turn Dialogue: LlamaIndex also supports multi-turn dialogue functionality, allowing you to interact with RAG like chatting with a friend!
PART
THREE
Interaction
-
Regarding the principles and practices of RAG, do you have any questions or things you want to ask?
-
You must be wondering if you can use Deepseek instead of OpenAI?
-
Do you want to know how to use other RAG frameworks, like LangChain?
-
Would you like to learn about advanced usage, like recall precision? Embedding optimization? Stacking graph database buffs? Stacking multimodal buffs?
⭐️ If you have more ideas and questions, please leave a message. The next article will discuss the AI technology guide you want to know about~
The End
END
END