RAG in Salesforce | Live Implementation with Agentforce | Learn RAG (Retrieval-Augmented Generation)


Introduction

After unifying data using Salesforce Data Cloud in earlier videos, I wanted to take the next step: bringing that data to life with AI-powered contextual reasoning.

In this session, I implemented Retrieval-Augmented Generation (RAG) in Salesforce Agentforce, showing how it can help teams quickly find relevant information from internal documents in this case, company policy PDFs from Adventure Cloud.


We’ll look at two approaches:

  1. Using a dedicated Agent connected to a Data Library
  2. Using a Prompt Template for reusable, controlled responses


Scenario Overview

Our story continues with Right Swift Rental and Adventure Cloud, two companies that merged into Rideswift Adventure.

After integration, their policies for vehicle insurance, personal insurance, booking, and safety were scattered across multiple PDF documents.


Employees and customers struggled to find simple answers like:

  • “What’s covered under vehicle insurance?”
  • “Can I cancel my adventure booking?”


The goal was to build a Policy Assistant in Salesforce that could read and respond directly from these documents using RAG.

What is RAG?

Retrieval-Augmented Generation allows AI models to generate grounded, accurate responses by retrieving data from a company’s own documents or systems.

Rather than “guessing,” the model retrieves and reads relevant sections from your internal data - PDFs, Knowledge Articles, or Data Cloud objects and generates an answer that’s factual and verifiable.


You can use RAG within Salesforce with or without Data Cloud.

  • With Data Cloud → connect to external systems or structured data.
  • Without Data Cloud → rely on Agentforce Data Library for unstructured data like PDFs.


How RAG Works Behind the Scenes

When a user asks a question, the process follows these steps:

  • Text Extraction - Salesforce reads text from the uploaded policy PDFs.
  • Chunking - Large text is split into small, meaningful pieces (500–1000 tokens).
  • Embedding & Indexing - Each chunk is converted into a numerical vector and stored in a managed vector index.
  • Semantic Retrieval - When a query comes in, Salesforce converts it into a vector and retrieves the most similar chunks.
  • Grounded Response - The retrieved text is added to the prompt, and the LLM generates an answer based only on that context.


This ensures every response is accurate, explainable, and free from hallucinations.


Setting Up the Policy Assistant Agent

Enable Einstein 1 and Agentforce

  • Verify access to Agentforce Studio and Data Library

Create a Data Library

Upload PDFs

Create a New Agent

  • Name: Policy Assistant Agent
  • Role: Helps users understand company policies including insurance, booking, and safety.
  • Link the Adventure Cloud Policies Data Library as its knowledge source.

Customize the Agent Prompt

  • You are Adventure Cloud’s official Policy Assistant.
  • Answer user questions based only on the policy documents available in your Data Library.
  • Be factual, professional, and always cite the policy section or document name.

Test the Agent by Asking

  • “What damages are covered under vehicle insurance?”
  • “Does personal insurance cover medical emergencies during treks?”


✅ The agent returned grounded, precise answers with clear citations.


Alternative Approach - Using Prompt Templates

For teams that need reusable prompts or want tighter control across multiple Agents, Salesforce Prompt Builder is a great alternative.


Steps

Create a New Data Library

  • Upload the same PDFs

Create a Prompt Template in Prompt Builder

  • Name: Company Policy Prompt
  • Input Variables: user_query, retrieved_context
  • Prompt Logic:You are a Salesforce policy assistant. Use the retrieved context to answer user questions accurately. If information is not found, respond: “The requested policy detail is not available in the current documents.”
  • Always cite the source document title.

Integrate with Agentforce Default Agent

  • Create a Topic: Official Policy Assistant
  • Action: link to Company Policy Prompt template
  • Set tone, instructions, and goals directly in Topic settings.


Test the Integration

Questions like:

  • “What exclusions exist in vehicle insurance?”
  • “Does Adventure Cloud provide emergency support?”


Conclusion

RAG brings real-world context into Salesforce AI.

By connecting policy documents to an Agent or Prompt Template, organizations like Rideswift Adventure can instantly make internal information accessible and accurate without leaving Salesforce.

Whether you choose a simple Agent-based approach or an advanced Prompt Template setup, RAG provides a scalable, trustworthy foundation for intelligent assistants in your org.


Watch the complete video below

 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks

Post a Comment

0 Comments