Skip to main content

Optimize Hybrid Search Results for RAG

Learning Objectives

After completing this unit, you’ll be able to:

  • Explain why hybrid search is important for retrieval augmented generation (RAG) use cases.
  • List three strategies for optimizing hybrid search results.

Before You Start

Before you start this module, make sure you complete this content. The work you do here builds on the concepts and work you do in that content.

As you learned in Search Index Types in Data Cloud: Quick Look, you can build search indexes in Data Cloud to ground AI on your organization’s unstructured, semi-structured, or structured data. In this module you learn how to optimize search results for RAG. First, let’s define these terms.

Retrieval augmented generation (RAG) in Data Cloud is a framework for grounding large language model (LLM) prompts with accurate, current, and pertinent information, improving the relevance and value of LLM responses. For more information on Data Cloud RAG framework, see Using Retrieval Augmented Generation.

Hybrid search is the foundational search service that combines the strengths of semantically aware vector search with the precision of keyword search to handle domain vocabulary. When you create a hybrid search index, Data Cloud automatically creates a default retriever for the index, which you can use in a prompt template when crafting your prompt to the LLM.

With hybrid search indexes, you can augment search queries and ground LLM prompts with the most relevant information for RAG use cases.

Let’s Start with a Real-Life Scenario

Storm Eowyn was a powerful cyclone that hit Ireland in January, 2025—the most severe storm to hit the country since 2017. Before the storm, many residents called their insurance companies to find out about their coverage and how to enhance it.

Let’s say you’re an admin at one of the insurance companies, and you want your service reps to easily find this information with Agentforce. This is a straightforward scenario for vector search. Vector search can identify relevant article chunks that describe natural disaster coverage, such as for storms and cyclones.

But after the Eowyn storm, the government of Ireland provided additional support through a Humanitarian Assistance Scheme (HAS) program for qualified residents. Hybrid search is ideal for this scenario. Hybrid search combines ‌semantic search on natural disaster coverage with specific keywords for the Eowyn storm and acronyms such as HAS. In addition, hybrid search can surface ongoing updates to the HAS program with ranking factors.

Hybrid search gives you three optimization strategies to ensure the most accurate and up-to-date results.

  • Configure pre-filter fields at the time of index creation and use pre-filter conditions to select relevant results.
  • Add ranking factors such as recency and popularity at the time of index creation to get the most recent and useful results.
  • Use ranking models to send relevance-specific parameters to influence results with search queries.

Now let’s dig into how you can craft search queries with these optimization strategies to get the most relevant results for our scenario.

Enhance Hybrid Search Queries with Pre-filter Fields

When you create the search index, add fields from the search index object or related objects to provide more ways to filter a search. You can select up to 10 filter fields. Use the pre-filter fields to filter results. For more information on how to create a hybrid search index, see Create a Hybrid Search Index with Advanced Setup.

For the home insurance policies example, you add the type of insurance policy as a field for filtering results.

Image shows Data Cloud Search Index guided setup user interface where a field representing the type of insurance policy is selected as a field for filtering results.

You can then create a query that selects home insurance policy articles to make sure the relevant articles are returned.

select c.Chunk__c, h.hybrid_score__c, h.keyword_score__c, h.vector_score__c, res.Type_of_Insurance__c,res.Policy_Name__c
from
hybrid_search(table(Insurance_PoliciesV1_index__dlm),
'Humanitarian Assistance Scheme ',
'Type_of_Insurance__c=''Home''', 10)
as h join Insurance_PoliciesV1_chunk__dlm as c on
h.RecordId__c=c.RecordId__c
join Insurance_PoliciesV1__dlm as res on c.SourceRecordId__c=res.Id__c
ORDER by h.hybrid_score__c desc

Configure Ranking Factors to Get the Most Up-to-Date Results

When you create the index, configure ranking factors such as recency and popularity. The built-in hybrid search fusion ranking model includes your ranking factors to get results that are most relevant to customers.

A flow chart showing how the hybrid search fusion ranker merges results from the vector and keyword searches along with the ranking factors to generate relevant search results.

For our scenario, you’re interested in the most recent and popular articles. For recency, select the Last Updated field. For popularity, select the Page Views field. The default fusion ranker model takes these ranking factors into account when it generates a similarity score for the most relevant results. For more information on how the fusion ranker works see, Hybrid Search Fusion Ranking.

Note

If there aren’t any fields that adequately represent recency or popularity, then don’t configure them when you create an index.

Data Cloud Search Index guided setup user interface, depicting where ranking factors for popularity and recency are selected. Page Views are selected for Popularity, and Last Updated field is selected for Recency.

In the next section, let’s see how you can use and fine-tune these ranking factors for our scenario.

Influence Results Ranking with Ranking Models

At query time, you can send relevance-specific parameters to the search index with ranking models and increase the accuracy of the search results. You can modify the importance given to a search type and to the ranking factors.

Data Cloud hybrid search supports three fusion ranking models.

  • Linear Fusion Ranker (LFR) model
  • Deep Fusion Ranker (DFR) model
  • Reciprocal Rank Fusion (RRF) model, which is the industry-standard

The Linear Fusion Ranking model is a customizable form of the default fusion ranker model, which calculates a weighted sum of the transformed scores from both vector search (dense) and keyword search (sparse). The search results are ranked using the sum derived from the LFR formula. For more information on the LFR model see, Influence Hybrid Search Relevance Ranking.

The linear fusion ranking formula with weighted and transformed vector and keyword search scores.

The Deep Fusion Ranking model enhances search relevance by integrating traditional signals such as vector similarity, keyword matches, popularity, and recency with a deeper understanding of the query text. By using deep learning techniques and transformer architectures, the model captures complex feature interactions and jointly scores records. For more information on the DFR model see, Influence Hybrid Search Relevance Ranking.

The industry standard Reciprocal Rank Fusion (RRF) model formula is the sum of both the keyword search (sparse) and vector search (dense) reciprocal rank scores with a default rank constant of k=60. The formula also provides an alpha parameter, which controls the sparse weight in a convex combination of the two scores. The formula can also factor in the ranking factors you configure at index creation time. The search results are ranked using the sum derived from the RRF rank fusion formula.

The reciprocal rank fusion formula with keyword search, vector search reciprocal rank scores, and considers ranking factors, popularity and recency, along with the importance for each component.

Note

In the advanced RRF formula:

  • Alpha (a) represents the importance given to keyword search. Default is 0.5f.
  • Beta (B) represents the importance given to vector search and is calculated based on the importance given to keyword search (1-alpha).
  • Gamma (Y) represents the importance of ranking factor popularity. Default is 0.00074478f. Maximum is 1.
  • Delta represents the importance given to ranking factor recency. Default is 0.00028472f. Maximum is 1.

Specify the importance of weights in your query. Tweak and refine the values in low increments to make sure you achieve the right relevance for your results.

For more information on the RRF model see, Influence Hybrid Search Relevance Ranking.

For our scenario, let’s use the RRF model to assign a higher importance to keyword search for home insurance domain-specific terms. In this query, you’re looking to surface results for a question about adding a rider or an add-on to a home insurance policy for storm damage. Keyword search importance is set to a high 0.8 weight to surface the relevant articles.

select c.Chunk__c, h.hybrid_score__c, h.keyword_score__c, h.vector_score__c, res.Type_of_Insurance__c,res.Policy_Name__c
from
hybrid_search(table(Insurance_PoliciesV1_index__dlm),
'Why should I add a rider to my home policy?',
'', 10,
'{"rrf": {"keyword_weight": 0.8}}')
as h join Insurance_PoliciesV1_chunk__dlm as c on
h.RecordId__c=c.RecordId__c
join Insurance_PoliciesV1__dlm as res on c.SourceRecordId__c=res.Id__c
ORDER by h.hybrid_score__c desc

You also value recent and popular articles more. This helps make sure that the latest policy additions to the HAS program are more important in the response than previous articles. Since you configured a recency factor at the time of index creation, you can add that to the query and make sure that the most recent articles surface higher in the query results. You can also add popularity weight to ensure that articles with the most page views surface up in the results. Tweak and refine component weights to make sure the most relevant results are returned for a query.

select c.Chunk__c, h.hybrid_score__c, h.keyword_score__c, h.vector_score__c, res.Type_of_Insurance__c,	res.Last_Updated__c from
hybrid_search(table(Insurance_PoliciesV1_index__dlm),
'How Humanitarian Assistance Scheme can help in case of Severe weather conditions?',
'Type_of_Insurance__c=''Home''', 10,
'{"rrf": {"keyword_weight": 0.8,"recency_weight": 0.0018,"popularity_weight": 0.0008}}')
as h join Insurance_PoliciesV1_chunk__dlm as c on
h.RecordId__c=c.RecordId__c
join Insurance_PoliciesV1__dlm as res on c.SourceRecordId__c=res.Id__c
ORDER by h.hybrid_score__c desc

In Summary

Data Cloud hybrid search optimizes search results with customizable strategies for each scenario. For example, create pre-filter fields and configure ranking factors at search index creation time. Use pre-filter fields and ranking factors with ranking models in your search queries. You can also fine-tune the component weights for keyword search, vector search, and ranking factors for a ranking model. Surface the results your users need with hybrid search in Data Cloud.

Resources

Salesforce 도움말에서 Trailhead 피드백을 공유하세요.

Trailhead에 관한 여러분의 의견에 귀 기울이겠습니다. 이제 Salesforce 도움말 사이트에서 언제든지 새로운 피드백 양식을 작성할 수 있습니다.

자세히 알아보기 의견 공유하기