Docs
GraphQL API
Search
Semantic Search Advanced

Semantic Search: Advanced Guide

This guide is designed for developers who have a good grasp of the basics of semantic search and are ready to explore more sophisticated functionalities to enhance their search capabilities. Let’s dive in, folks!

Understanding nearVector: A Deeper Dive

We have already explained vector space in the previous doc. nearVector provides direct access to the vector space, allowing for precise navigation and customized search experiences. Here, we’ll explore advanced techniques and use cases to fully leverage this powerful feature.

Fine-Tuning with moveTo and moveAwayFrom

moveTo and moveAwayFrom are very powerful advanced functionalities that enable you to steer your search query towards or away from specific concepts. You can probably sense how powerful this concept is which gives you precise control over your search results.

  • Example: Balancing Concepts For example, let us consider you’re searching for articles related to web development, but you want a balanced view, considering both frontend and backend perspectives. The example given below imitates the scenario.
graphqlCopy code
{
  Get {
    Article(
      nearVector: {
        vector: [...vector representing “web development”...],
        moveTo: {
          concepts: ["frontend", "backend"],
          force: 0.5
        }
      }
    ) {
      title
      content
    }
  }
}

Utilizing Custom Vectors

If you have access to custom words or document vectors, nearVector allows you to integrate them directly into your search queries.

{
  Get {
    Article(
      nearVector: {
        vector: [...your custom word vector...]
      }
    ) {
      title
      content
    }
  }
}

Optimizing Search with Boosting and Filtering

Let us now have a look at how you can enhance your search results by boosting certain properties and applying filters to hone in on the most relevant data.

Property Boosting

Some of the properties in the data are more relevant than others. You can boost the relevance of specific properties in your data to ensure they have a greater impact on the search results.

  • Example: Boosting Titles
{
  Get {
    Article(
      nearText: {
        query: "web development",
        boost: { title: 2 }
      }
    ) {
      title
      content
    }
  }
}

Conditional Filtering

You can also apply filters to your semantic search queries. It helps to narrow down results based on specific conditions.

  • Example: Filtering by Tags
{
  Get {
    Article(
      nearText: {
        query: "web development"
      },
      where: {
        path: ["tags"],
        operator: Equal,
        valueText: "tutorial"
      }
    ) {
      title
      content
      tags
    }
  }
}

Conclusion: Mastering Semantic Search

Now that you have mastered these advanced techniques, you can unlock the full potential of Unbody’s semantic search capabilities.

Whether you’re aiming for precision with nearVector, balancing concepts, or optimizing search results with property boosting and filters, the power is in your hands to create a tailored and efficient search experience.

Happy coding, and may your searches always be semantically rich and relevant!