Docs
GraphQL API
Search
Hybrid Search Advanced

Hybrid Search - Advanced Guide

The advanced guide for Hybrid Search is helpful for those developers who are comfortable with the basics of Hybrid Search. If you haven’t had the chance to read the basics of Hybrid search, please visit this page.

Fusion (Ranking) Method: Fine-Tune Your Results

⚠️

NOTE: This feature is available from v1.20 onwards

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.

The sample code given below demonstrates how you can do it.

{
  Get {
    Article(
      limit: 3
      hybrid: { query: "coding in Python", fusionType: relativeScoreFusion }
    ) {
      title
      content
    }
  }
}

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!!

Take a look at the example given below.

{
  Get {
    Article(
      limit: 3
      hybrid: { query: "coding in Python", properties: ["title"], alpha: 0.25 }
    ) {
      title
      content
    }
  }
}

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.

You can write a query as given below.

{
  Get {
    Article(
      limit: 3
      hybrid: {
        query: "coding"
        properties: ["title^2", "content"]
        alpha: 0.25
      }
    ) {
      title
      content
    }
  }
}

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

Bring Your Own Vectors: Customized Semantic Search

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.

The example given below shows you how you can form a query with your own vector.

{
  Get {
    Article(
      limit: 3
      hybrid: {
        query: "coding in Python"
        vector: [...your_vector_here...]
      }
    ) {
      title
      content
    }
  }
}

Add a Conditional Filter: Refine Your Search

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.

{
  Get {
    Article(
      limit: 3
      hybrid: { query: "coding in Python" }
      where: { path: ["tags"], operator: Equal, valueText: "tutorial" }
    ) {
      title
      content
      tags
    }
  }
}

Wrapping Up: Power in Your Hands

Now that you have mastered Unbody's Hybrid Search, you have more control and flexibility over your search results. Whether you're fine-tuning rankings, focusing on specific properties, or bringing your own vectors, Unbody is here to help you find exactly what you need.

Happy searching!