Skip to main content
M8 · 0%

Module 8 of 18

Retrieval-Augmented Prompting

Combine prompt engineering with external knowledge retrieval

Extending AI with Knowledge and Tools

While standalone LLMs are powerful, their true potential is unlocked when combined with external knowledge and tools. This module explores techniques that extend model capabilities beyond their training data and enable them to take actions in the world.

You will learn how to implement systems that retrieve relevant information on-demand, use specialized tools to solve tasks, and improve through observation and feedback.

The future of AI is not just about smarter models, but about intelligent systems that combine models with data, tools, and feedback mechanisms to solve real-world problems more effectively than any single component could alone.

Retrieval-Augmented Generation (RAG)

RAG combines the reasoning capabilities of LLMs with external knowledge retrieval to deliver more accurate, relevant, and up-to-date responses. Instead of relying solely on what the model learned during training, RAG systems dynamically access and incorporate information as needed.

Knowledge Base Creation

Document collection and preprocessing. Chunking text into manageable segments. Creating vector embeddings for each chunk. Storing in a vector database for retrieval.

Query Processing

Converting user query to vector embedding. Searching the vector database for relevant chunks. Ranking and selecting top results. Compiling retrieved context.

Response Generation

Crafting prompt with retrieved context. Instructing the LLM how to use the context. Generating a response based on context and query. Formatting and delivering the final answer.

Continuous Improvement

Monitoring retrieval quality. Tracking response relevance and accuracy. Refining retrieval algorithms. Updating the knowledge base.

RAG systems combine the best of both worlds: the factual accuracy and recency of a knowledge base with the flexibility and reasoning capabilities of an LLM, enabling more reliable, verifiable responses with explicit sources.

Prompt

You are a helpful assistant that uses retrieved context to answer questions. Here is the relevant context: [Retrieved Context] The company's Q2 earnings report shows: - Revenue: $1.2B (up 15% YoY) - Net Income: $250M (up 20% YoY) - Operating Margin: 21% - Key Growth Drivers: Cloud Services (+25%), AI Products (+40%) Question: What were the key growth drivers in Q2 and how did they perform?

Output

Based on the retrieved context, the key growth drivers in Q2 were: 1. Cloud Services: Grew by 25% year-over-year 2. AI Products: Grew by 40% year-over-year These two segments showed strong performance, with AI Products demonstrating particularly robust growth. The company's overall revenue increased by 15% YoY, reaching $1.2B, with these two segments being significant contributors to this growth.

LLM Agents and Tool Use

LLM agents are systems that can use tools to interact with the world and solve tasks. By giving language models the ability to use specialized tools (like calculators, search engines, or APIs), we enable them to accomplish tasks beyond text generation.

The true power of LLMs emerges when they can choose and use appropriate tools to accomplish tasks. This transforms them from passive text generators into active problem-solvers capable of interacting with the world.
  1. 01

    Tool Collection

    A set of specialized functions the agent can call to perform specific tasks, each with a description, parameters, and expected outputs.
  2. 02

    Planning Module

    Analyzes user requests, breaks them into steps, and determines which tools to use and in what sequence to accomplish the goal.
  3. 03

    Execution Engine

    Calls tools with appropriate parameters, handles their outputs, and manages state between steps of multi-step processes.
  4. 04

    Memory System

    Stores previous interactions, tool results, and intermediate states to maintain context throughout multi-step tasks.
  5. 05

    Communication Interface

    Translates between the user's natural language and the agent's internal processes, explaining actions, requesting clarification, and presenting results.

Prompt

You are an agent that can use tools to help users. You have access to these tools: 1. Calculator: Perform mathematical calculations 2. Web Search: Search the internet for information 3. Calendar: Schedule and manage events 4. Email: Send and receive emails User Request: "Schedule a meeting with the team for next Tuesday at 2 PM and send them an email with the agenda."

Output

I'll help you schedule the meeting and send the email. Let me break this down into steps: Calendar Tool: - Date: Next Tuesday - Time: 2:00 PM - Duration: 1 hour - Participants: Team members Email Tool: - Subject: Team Meeting Agenda - Next Tuesday - Body: Including key discussion points and preparation items - Attachments: Any relevant documents Would you like me to proceed with these actions?

Observation-Based Improvement

Observation-based systems go beyond static prompting by incorporating feedback and learning from interactions. They track performance, collect observations, and adapt their behavior to improve over time.

The most effective AI systems do not just execute instructions. They learn from their experiences. By collecting observations and adapting behavior based on feedback, these systems continuously improve their performance and better meet user needs.

Feedback Collection

Explicit user ratings and reviews. Implicit signals (clicks, time spent, etc.). Success and failure metrics for tasks. User corrections and clarifications. A/B testing different approaches.

Adaptation Strategies

Prompt refinement based on performance. Tool selection optimization. User preference modeling. Self-critique and reflection. Memory-augmented interactions.

Prompt

You are an observation-based agent that learns from interactions. Here's your recent performance data: Previous Interactions: 1. User asked about weather - Response was accurate but too technical 2. User requested recipe - Response missed key ingredients 3. User needed directions - Response was clear and helpful Current Request: "What's the weather like today?"

Output

Based on my previous interactions, I'll provide a clear, non-technical weather update: Weather Today: The weather today is sunny with a high of 75 degrees F (24 degrees C). There's a light breeze, and it's perfect for outdoor activities. Don't forget your sunglasses! Was this response helpful? [Yes] [No]

Combining RAG, Agents, and Observation

The most powerful systems integrate all three approaches:

  1. 01

    RAG provides up-to-date knowledge

    Retrieves relevant information to inform decision-making.
  2. 02

    Agents take actions based on this knowledge

    Use tools to accomplish tasks informed by retrieved information.
  3. 03

    Observation systems improve both components

    Refine retrieval strategies and agent behaviors based on outcomes.

Activities

Activity 1

45-60 min · Advanced

RAG Implementation

Implement a basic RAG system using a vector database and LLM to answer questions about a specific domain.

Activity 2

40-50 min · Advanced

Agent Design

Design and implement a simple agent that can use tools to solve a specific task.

Activity 3

50-60 min · Advanced

Observation-Based System

Create a system that uses observations to improve its responses over time.

Additional Resources