Build Agentforce RAG

Overview
Builds a production-ready Agentforce agent that answers user questions by retrieving relevant passages from a document knowledge base stored in Data 360 (Data Cloud). The pipeline covers seven phases: cleaning and deduplicating source documents (Zendesk TXT exports and training PDFs), uploading them to a Data Library (Files type), configuring a Hybrid search index with the Multilingual E5 Large embedding model, building a Flex prompt template with a dynamically bound retriever, wiring the prompt template into an Agentforce agent action, and validating the pipeline with a structured 15-prompt test suite scored across five quality dimensions.
The recipe was validated in production and scored 148/150 (98.7%) across easy, medium and hard difficulty tiers.
What gets built
- A cleaned, deduplicated document corpus ready for ingestion, from raw Zendesk exports and PDF training materials
- A Data Library (Files type) containing all knowledge base documents, with auto-generated UDMOs, chunks and vector embeddings
- A Hybrid search index that combines semantic vector search with keyword matching, using Passage Extraction chunking (512 max tokens) and the Multilingual E5 Large embedding model
- An auto-configured search retriever connected to the Data Library for passage retrieval
- A Flex prompt template with a dynamic retriever resource bound to
{Input:User_Question}for real-time, query-based search - An Agentforce agent with a topic scoped to the knowledge base domain, with the prompt template wired in as a
generatePromptResponseaction - A 15-prompt RAG test suite across three difficulty tiers (single-doc factoid, multi-doc synthesis, reasoning and edge cases) with a 10-point scoring rubric per prompt
- A documented tuning methodology with six prioritized tuning levers for improving retrieval accuracy
How it works
Source documents are cleaned to remove HTML navigation artifacts, footers and duplicates, then uploaded to a Data Library. Salesforce extracts the content, chunks it with passage extraction, and generates vector embeddings that are indexed in a Hybrid search configuration.
When a user asks the agent a question, the Topic Selector routes to the right subagent, which invokes the prompt template action. The prompt template passes the question to the retriever, which runs a hybrid vector and keyword search against the indexed chunks and returns the top 5 passages. The LLM writes an answer grounded only in those passages, and the Trust Layer checks whether the response is GROUNDED before it reaches the user. If the Trust Layer flags a response as UNGROUNDED, the agent retries the retrieval and generation cycle.
Key configurations
- The retriever's search text must be the dynamic merge field
{Input:User_Question}. A hardcoded search text was the #1 root cause of RAG failure, dropping accuracy from 98% to 40% - Hybrid search (vector and keyword) outperforms vector-only search for knowledge bases with branded terms, product names and domain-specific acronyms
- The prompt template tells the LLM to use ONLY the retrieved document excerpts and to say so when the information is not available, which prevents hallucination
- Active prompt template versions are immutable. Changes need "Save as New Version" followed by explicit activation, and agent actions must be re-pointed to pick up input schema changes
What you'll need
- Products: Data 360 (Data Cloud), Agentforce, Salesforce Platform
- Connections: Salesforce org with Admin access, Data Cloud and Agentforce provisioned, and Einstein Generative AI enabled
- Prerequisites: Source knowledge base documents in TXT, HTML or PDF format, Python 3.x for the document cleaning script, and the Data Libraries feature enabled in Setup
Complexity
- Level: Advanced
- Steps: 7 major phases (document prep, upload, search index, agent configuration, prompt template, test suite, tuning)
- Est. time: 2–4 hours end to end, depending on document count and tuning iterations
Find the recipe in the Library and run it from there.
Build a Campaign for Marketing Cloud Advanced
Builds a complete, high-converting promotional email or landing page in Marketing Cloud Advanced from a campaign brief, with a PDF layout guide.
Technical Audit on Marketing Cloud Engagement
A read-only technical debt audit of a Marketing Cloud Engagement account that business, marketing ops and developers can each act on.