Content APISearchHybrid Search

Hybrid Search

Hybrid search is a method that combines the benefits of both semantic search and keyword search. This method provides users with comprehensive search results by considering both the meaning of the user’s search query and the exact keywords used.

This method is best to use when you want to provide comprehensive and contextually relevant search results even when the user’s search query contains both specific keywords and broader concepts.

Syntax

Hybrid search can be performed on any text (string) field of any object. Here’s how:

Usage

Example 1 - Google Docs

Example 2 - Discord Messages

Example 3 - Any text block

Example 4 - Google Docs with specific fields

Arguments

NameTypeDefaultDescription
querystringQuery string
alphafloatSearch weight
fusionTyperankedFusion
relativeScoreFusionAlgorithm used for fusing results from vector and keyword search.
propertiesstring[]Specify which fields to search

Advanced Usage

Fusion (Ranking) Method: Fine-Tune Your Results

When you’re working with Hybrid Search, the way keyword and vector search results are combined can make a big difference. By default, Unbody uses rankedFusion, adding inverted ranks of both search methods. However, if you prefer, you can switch to relativeScoreFusion to add normalized scores instead. This option is especially useful when you want to prioritize the relevance of results.

Example: Using Relative Score Fusion

Target Specific Properties: Get Precise

💡

NOTE: This feature is available from v1.19.0 onwards

Unbody allows you to focus your search on specific fields of your data. you can target particular properties for the keyword portion of your search. Moreover, this doesn’t affect the vector search, ensuring your semantic search remains broad and context-aware. Liked that? I guess, yesss!!

Example: Focus on Title

Boosting Properties: Give Priority Where Needed

Isn’t it true that some things deserve more attention than others? Well, the same is true for data. Sometimes, certain parts of your data might be more important than others. With property weighting, you can tell Unbody to give more importance to specific fields during the BM25 keyword search.

Example: Boosting title

In the example given above, Unbody’s Hybrid Search considers matches in the title to be twice as important as matches in the content.

Have you got your own vector? Great! You can provide it directly to the Hybrid Search and Unbody will use it for the vector part of the search. It will still consider your query string for the keyword search. This is perfect for when you have a very specific semantic context in mind.

Example: Search near a Vector

You can add conditional filters to your hybrid search queries. These filters will refine the results without impacting the ranking. For example, if you want to search for articles about “coding in Python” but only if they are tagged as “tutorials”, you can write the query as given below.

Example: Search when tags are equal to tutorial

©2024 Unbody