This course is based on the attached Unit 5: RAG & AI Search presentation, covering Modules 13β15: RAG Fundamentals, Context Injection & Prompt Templates, and AI Search Optimization.
π― Unit Learning Objectives
By the end of this unit, learners will be able to:
- Explain Retrieval-Augmented Generation (RAG).
- Understand how a RAG system retrieves and uses external information.
- Explain embeddings and vector databases.
- Differentiate keyword, semantic, and hybrid search.
- Understand context injection and its different types.
- Create structured prompt templates.
- Explain AI Search Optimization.
- Understand vector search and AI ranking systems.
- Identify practical applications of RAG and AI search.
Module 13: RAG Fundamentals
13.1 What is RAG?
RAG stands for Retrieval-Augmented Generation.
RAG is an AI technique in which an AI system first retrieves relevant information from external sources and then uses that information to generate a more accurate and context-aware response.
RAG has three stages:
R β Retrieval
The AI searches external sources such as databases, documents, websites, PDFs, knowledge bases, and vector databases.
A β Augmented
The retrieved information is added to the AI's context.
G β Generation
The LLM uses the retrieved information together with its existing knowledge to generate the final answer.
Visual: RAG Architecture
Simple Flow:
User Question β Retrieve Information β Add Context β LLM β Answer
13.2 Why is RAG Important?
An LLM working without external retrieval can face problems such as:
- Outdated information
- Incorrect or fabricated answers
- Lack of company-specific knowledge
- Poor performance on niche topics
- Lack of access to recent information
RAG helps provide more accurate, grounded and domain-specific responses while improving reliability.
Example
Imagine an employee asks:
"What is our company's current leave policy?"
A normal AI model may not know the company's latest policy.
A RAG system can retrieve the company's HR policy document and use the relevant section to answer the question.
13.3 How RAG Works
A RAG workflow generally follows four steps.
Step 1 β User Query
The user submits a question.
Example:
"What are the latest AI trends in healthcare?"
Step 2 β Information Retrieval
The system searches relevant sources such as research papers, databases, documents, or websites.
Step 3 β Context Injection
Relevant information is inserted into the prompt.
Step 4 β Response Generation
The LLM uses the enriched prompt to generate the response.
13.4 Architecture of a RAG System
A RAG system consists of several components:
User Interface
Where the user submits a query.
Retriever
Searches knowledge sources and identifies relevant information.
Vector Database
Stores document embeddings and supports semantic retrieval.
Examples include:
Embedding Model
Converts text into numerical vectors.
LLM / Generator
Uses the retrieved information to generate the final answer.
Visual
13.5 Embeddings and Vector Databases
An embedding is a numerical representation of text that captures semantic meaning.
This allows AI systems to recognize that different words can have similar meanings.
Examples
Dog β Puppy
Car β Automobile
Even though the words are different, they represent related concepts.
Popular Vector Databases
| Vector Database | Description |
|---|
| Pinecone | Managed cloud vector database |
| Weaviate | Open-source database with ML integrations |
| ChromaDB | Lightweight option for prototyping |
13.6 Types of Retrieval
Keyword Search
Searches for exact words.
Example:
Searching for "AI course" looks for documents containing those words.
Limitation: It may miss related terms such as "artificial intelligence training."
Semantic Search
Understands the meaning and intent of the query.
It can recognize related phrases and concepts.
Hybrid Search
Combines:
Keyword Search + Semantic Search
This can provide better accuracy and relevance.
Visual: Semantic & Hybrid Search
13.7 Applications of RAG
π Education
- AI tutors
- Personalized learning
- Smart study assistants
- Textbook Q&A
- Exam preparation
π’ Business
- Customer-support chatbots
- Internal knowledge assistants
- HR policy Q&A
- Automated report generation
π₯ Healthcare
- Medical information retrieval
- Drug interaction lookup
- Clinical decision support
- Patient history analysis
βοΈ Legal
- Contract analysis
- Legal document search
- Case law research
- Compliance checking
13.8 Advantages and Challenges
β
Advantages
- Updated information
- Reduced hallucinations
- Domain-specific knowledge
- Personalized responses
- Better factual accuracy
- Enterprise scalability
β οΈ Challenges
- Complex architecture
- Requires high-quality databases
- Retrieval quality affects answer quality
- Higher computational requirements
- Additional retrieval latency
- Documents need to remain updated
13.9 Future of RAG
Future RAG systems may include:
- Faster retrieval
- Multimodal RAG
- Real-time enterprise AI
- Personalized AI
- Agentic RAG
- IoT and edge-computing integration
Module 14: Context Injection & Prompt Templates
14.1 What is Context Injection?
Context Injection means adding additional information to a prompt so that AI can generate a more accurate and relevant response.
Without Context
"Explain the policy."
The AI does not know which policy is being discussed.
With Context
"Using the company HR policy document, explain the leave policy for employees."
The AI now has specific information to work with.
Visual: Context Injection
14.2 How Context Injection Works
Step 1 β User Query
The user asks a question.
Step 2 β Retrieve Context
The system collects relevant information.
Step 3 β Insert Context
The system creates:
User Query + Retrieved Information + System Instructions
Step 4 β Generate Response
The LLM processes the enriched prompt and generates the answer.
14.3 Types of Context
1. Static Context
Information that remains fixed.
Examples:
- Company policies
- System instructions
- Tone guidelines
- Formatting rules
2. Dynamic Context
Information that changes according to the query.
Examples:
- Retrieved documents
- Product information
- Real-time data
- API responses
- User preferences
3. Conversational Context
Information from previous messages in the conversation.
Examples:
- Earlier questions
- Previous responses
- Clarifications
- Conversation history
14.4 Prompt Templates
A prompt template provides a structured format for creating consistent AI instructions.
A good prompt template can include:
Role
Defines who the AI should act as.
"You are a professional teacher."
Task
Defines what the AI should do.
"Explain photosynthesis clearly."
Context
Provides relevant background information.
Output Format
Defines how the response should be presented.
"Use bullet points and provide a brief summary."
Example Prompt Template
You are an expert AI tutor.
Explain the topic: {topic}
Use simple language suitable for beginners.
Provide 2β3 real-world examples.
End with a concise summary in 3 bullet points.
The variable {topic} can be replaced with different topics, making the template reusable.
14.5 Best Practices
For effective context injection:
- Use relevant information.
- Use high-quality context.
- Keep prompts structured.
- Keep prompts concise.
- Update context regularly.
Common Challenges
- Too much context can confuse AI.
- Long prompts can increase token costs.
- Poor retrieval can produce poor answers.
- Context windows have limits.
- Outdated context can produce outdated responses.
Module 15: AI Search Optimization
15.1 What is AI Search Optimization?
AI Search Optimization is the process of improving how AI systems search, retrieve, and rank information.
Its major goals are:
π― Improve Accuracy
Return results that actually answer the user's needs.
β‘ Faster Retrieval
Find relevant information quickly.
π Better User Experience
Make search more natural and intuitive.
15.2 Traditional Search vs AI Search
| Feature | Traditional Search | AI Search |
|---|
| Basis | Keywords | Meaning and semantics |
| Matching | Exact words | Synonyms, paraphrases, intent |
| Context | Limited | Context-aware |
| Ranking | Basic ranking | AI-driven ranking |
| Results | Links/documents | Answers + supporting sources |
| Personalization | Limited | More intent-aware |
Example
Traditional Search:
"best places to study"
may focus on exact keyword matches.
AI Search:
"Quiet spots for focused work"
can understand the underlying intent and find conceptually relevant results.
15.3 Semantic Search
Semantic search focuses on the meaning behind a query rather than only matching words.
It considers:
User Intent
What does the user want?
Context
What is the surrounding situation?
Word Meaning
How do the words relate to each other?
Visual
15.4 Components of AI Search
An AI search system can include:
1. Query Understanding
Understands the user's intent.
2. Retrieval System
Finds relevant documents.
3. Ranking System
Orders results according to relevance, quality, and freshness.
4. Response Generation
Creates the final answer from the best results.
15.5 Search Optimization Techniques
Keyword Optimization
Use relevant keywords so documents can be discovered effectively.
Semantic Optimization
Improve semantic understanding using:
- Better embeddings
- Rich descriptions
- Concept-aware indexing
Metadata Optimization
Add:
- Tags
- Categories
- Dates
- Descriptions
Embedding Optimization
Improve vector representations so related content is grouped together more accurately.
15.6 Vector Search
Vector search compares numerical representations rather than relying only on exact words.
It helps identify:
- Similar meanings
- Related concepts
- Contextually relevant information
- Different ways of expressing the same idea
15.7 Hybrid Search
Hybrid search combines:
Keyword Search + Semantic Search
Benefits include:
- Higher accuracy
- Better retrieval speed
- Greater relevance across different query types
15.8 AI Ranking Systems
AI ranking systems can prioritize results based on:
Relevance
How closely does the result match the user's intent?
Quality
How credible and complete is the information?
User Intent
Does it satisfy what the user is actually trying to achieve?
Freshness
How recent is the information?
15.9 Applications of AI Search
π E-Commerce
Intelligent recommendations and product filters.
π Education
Learning search and curriculum discovery.
π₯ Healthcare
Medical document retrieval and assistance.
π’ Business
Enterprise knowledge bases and internal search.
βοΈ Legal
Case law research and contract analysis.
π¬ Media
Personalized content discovery and recommendations.
15.10 Future of AI Search
The future of AI search includes:
- Understanding complete human conversations
- Multimodal search across text, images, audio, and video
- Real-time personalized results
- Integration with AI agents
- Privacy-preserving search
- On-device AI search using edge models
π§ Unit 5: Quick Revision
RAG
Retrieval + Augmented + Generation
Allows AI systems to use external information when generating responses.
Context Injection
Adds relevant information to a prompt so that AI can produce a more precise response.
Prompt Templates
Provide a reusable structure containing elements such as Role, Task, Context, and Output Format.
Semantic Search
Searches based on meaning and intent, not just exact keywords.
Vector Search
Uses numerical embeddings to identify semantically related information.
Hybrid Search
Combines keyword + semantic search.
AI Ranking
Prioritizes results using factors such as relevance, quality, user intent, and freshness.
π Practice Activity
Scenario:
You are designing an AI assistant for a company's employees.
The assistant must answer questions about company policies.
Think about:
- What information should be stored in the knowledge base?
- Why would RAG be useful?
- What type of context would be dynamic?
- What could be included in a prompt template?
- Would keyword, semantic, or hybrid search be most useful?
Challenge:
Design the basic flow:
Employee Question β Retrieval β Relevant Context β Prompt β LLM β Answer
This activity directly applies the concepts covered throughout Unit 5.
Reply to Comment