Skip to content
  • #rag
  • #python

Retrieval-Augmented-Generation (RAG) on simple terms (Part-01)

glance of the background of RAG

Sep 3, 2026 • 5 min read

Hey , I am going to write on RAG , lets see the background first, it is widely adopted famous abbreviation which came into picture after LLMs. The longer form tells you the story a bit. Retrieval Augmented Generation. Lets take the word meaning. Retrieval-> Which means it is taken from something , Augmented-> means modified, aligned , Generation-> produce something new. That is it. But compare to the word meaning lot of happening behind the scenes. First I will tell you , how the customer care agents work when you call them.

From my experience, (I Worked as a part time call center agent for a amidst of my university time to earn few bucks) it is a some stressful work because customers have tons of questions regarding the services provided. They will ask everything to solve their curiosity. That is human nature right ??. We all take information and No one cannot blame any of these questions. Since someone sitting an answer a random question differently , call center agents have given a set of rules about how to greet, how to explain things and a knowledge base documents. During the call, They refer these documents(pdfs) to find the answers which they do not have a clear idea or forgot.Telcommunication Service Providers have handful of packages,devices and services that provides to customers and question may be regarding a package details, a device configuration or anything , call center agents will answer using those documents. Why these documents are needed ?. Can't they answer from their knowledge ?. <-- good questions, let me explain to you!

Lets take a moment and assume that scenario ,these call center agents will answer from their knowledge without referring these documents. Bit chaotic and what will happen is, based on their knowledge and what they remember about these services , they will give false promises regarding a particular service/package/device which may not provided, and once that expectation is not met by the actual service , customers wanna sue the company in the courts, blame on social media and you know the drill what happens most of the time. pretty weird right ?. This is exactly what happens , LLMs will answer questions they are totally unaware of , when they trained.

Do LLM know everything ?? . Hell no, they know what theyare the trained-on and most of the time, LLMS are very creative to trick you on something they do not learn. What we called "Hallucination". So If we need to take the power of LLM, then we need to align those outputs correctly. That is where RAG took the responsibility and solve most of the problem. Wait!! , before RAG how people solve this kind of problem ?. techniques like keyword search and semantic search provide a helping hand on that. Lets take a note on these two. TF-IDF (Term Frequency /Inverse Document Frequency) vectorization is one of keyword search technique , that I've worked on my final year project for fake news detection to identify certain key words related to a text. since it converts text into a machine-readable matrix , this is useful to perform some diverse tasks in NLP(Natural Language Processing). Semantic search means, searching for something that truly understood its meaning. Here is a simple code example of TF-IDF vectorizer in sci-kit learn.

import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer

# 1. Define sample text documents
documents = [
    "The quick brown fox jumps over the lazy dog",
    "This document is the second document",
    "And this is the third one",
]

# 2. Initialize the TfidfVectorizer
vectorizer = TfidfVectorizer()

# 3. Fit the model and transform the text into a matrix
tfidf_matrix = vectorizer.fit_transform(documents)

# 4. Extract feature names (the words in the vocabulary)
feature_names = vectorizer.get_feature_names_out()

# 5. Convert the matrix to a readable format (Pandas DataFrame)
df = pd.DataFrame(tfidf_matrix.toarray(), columns=feature_names)

# Display the results
print("Vocabulary List:\n", feature_names)
print("\nTF-IDF Matrix Weights:")
print(df)


It output something a machine can understand.


Vocabulary List:
 ['and' 'brown' 'document' 'dog' 'fox' 'is' 'jumps' 'lazy' 'one' 'over'
 'quick' 'second' 'the' 'third' 'this']

TF-IDF Matrix Weights:
       and     brown  document       dog       fox        is     jumps      lazy      one      over     quick    second       the    third      this
0  0.00000  0.345129  0.000000  0.345129  0.345129  0.000000  0.345129  0.345129  0.00000  0.345129  0.345129  0.000000  0.407678  0.00000  0.000000
1  0.00000  0.000000  0.784125  0.000000  0.000000  0.298174  0.000000  0.000000  0.00000  0.000000  0.000000  0.392063  0.231559  0.00000  0.298174
2  0.47111  0.000000  0.000000  0.000000  0.000000  0.358291  0.000000  0.000000  0.47111  0.000000  0.000000  0.000000  0.278245  0.47111  0.358291


To solve this ambiguity, there are two other techniques comes into play. One is prompt engineering. You can write a detailed guidance/බලගතු ප්‍රොම්ට් රාජයා.Yes definitely! it can help but it is a state of art to harness the power of an LLM , but lets keep that aside for a moment. one other thing is to tune the LLM with sample questions. But it is not that much useful in dynamic conditions where information changes frequently. so you have to train again and again when the content is changing.That is the trade-off which gets you about fine-tuning.we will have this discussion on fine-tuning another time, lets go on RAG on second part.

Okay, I get you . I took first part to give you what is actually behind this technology.A lot to explain you to in next chapters- See ya!.

disclaimer- I make mistakes on grammar/context. I am improvising on my knowledge/writing. if you notice something I understood incorrectly or wrote badly. send me an email with details in contact us page. Kudos to KodeCloud for detailed video , but I took a different approach to explain this to you! and a project comes to explain you in future. this is another variation . enjoy the article.

and STAY KIND, BE SAFE, YOU'RE ALWAYS APPRECIATED . ( I am a fan of why files, and I love that ending,,, )