Hybrid Search
Hybrid search is an Orama feature that allows you to perform full-text and vector search in one unique query, combining the results to get the best of both worlds.
Performing Hybrid Search
To perform hybrid search, you will need to use the same search
method you’re already using for full-text and vector search, which can be imported from @orama/orama
:
The key differences between running hybrid search and full-text search are:
- Instead of searching for a
term
exclusively, you will also need to provide avector
object to search. - You will need to set
mode
to"hybrid"
when running search. - You will need to specify the vector property you want to search on.
- At the time of writing, you can only search through one vector property at a time. If you think that this is too limiting, please open a feature request to support multiple vector properties at search-time.
Let’s see a full example of how to perform vector search:
The returning object will be exactly the same as the one we would expect when performing full-text search:
Since vectors can be quite large, you can also choose to not include them in the response by setting includeVectors
to false
(default behavior).
Custom hybrid weights
By default, Orama performs full-text and vector searches concurrently. Then, it aggregates the results and uses default weights to determine which result is more important (the full-text or the vector one) in the final list of results.
You can customize these weights by passing a hybridWeights
property to the search function:
By default, Orama assigns 0.5
to text
and 0.5
to vector
. This means that full-text results and vector results carry the same weight.
However, in the example above, we adjust these weights to { text: 0.8, vector: 0.2 }
. This implies that full-text search results will hold more relevance than vector search results in the final list.