Skip to main content
It is important to be able to show your user why a certain result is relevant to their search, highlighting can fill this role in a few different ways.

Vector

Highlights in a vector search context only make sense if the search is done on array properties; the highlight will return the most relevant array items along with their scores, while the resource property will return the entire property content. This allows you to show the user which part of the array matched the query. Highlights are returned for the three most relevant items for every matched resource. Matched resources are found through HNSW (Hierarchical Navigable Small World) search.
Consider the threshold an implementation detail, it may change from model to model and Clinia takes care of fine-tuning it to return relevant results.The score will vary between 0 and 1. It is the cosine similarity between the passage and the knn operator value.

Textual

Highlights for match operators directly return the matched text with <em> tags around the matched terms.

Examples

The following setup is required to run the subsequent code snippets, but you can skip it and still follow along with the rest of the tutorial if you prefer! In short, it sets up and ingests data for a profile with three properties:
  • title: a symbol property
  • abstract: a symbol property that is vectorized
  • content: an array of objects, each object having two symbol properties: sectionTitle and text. The text property is vectorized.
To correctly showcase highlights, we need to set up a registry source with an embedding pipeline. For the sake of this tutorial, we will be using the prestigious-journal source and the articles collection.
1

Create a source

2

Create a collection

3

Create an embedding pipeline

4

Add sample data

5

Wait for ingestion to complete

Look at the Task API guide to better understand how to poll for task status. This is not done here since it cannot be expressed as a single curl command.

Vector search on a Symbol property

Vector search using the knn operator on the vectorized abstract.vector property. Vector highlighting requires a property that is an array or nested inside one. Since abstract is a flat symbol, the response includes no highlighting field.

Textual search on a vectorized Symbol property

Even though abstract is vectorized, you can still request textual highlights on it using a match operator. Textual and vector highlights on the same property are independent — one highlight entry is returned per match occurrence, with the matched term wrapped in <em> tags.

Textual search on a non-vectorized Symbol property

Textual search works the same on properties without a vectorizer. One highlight entry is returned per match occurrence, with the matched term wrapped in <em> tags.

Multiple textual queries on the same Symbol property

Textual highlights combine all match queries on a same property.

Vector search on an Array property

When your data contains arrays, you can use the knn operator on the vectorized property to retrieve the most semantically relevant passages as highlights. In this example, the content property is an array of objects, each object having a text symbol property vectorized at content.text.vector. The highlights return the top matching passages with their similarity scores.

Multiple vector queries on the same Array property

The following query does not work. You cannot request highlights for a vector property that is queried by two different knn operators since there would be no way to know which highlight corresponds to which knn operator.

Textual search on an Array of objects

You can also request textual highlights on an array of objects. A separate highlight entry is returned for each array item that matches the query.