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 formatch 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: asymbolpropertyabstract: asymbolproperty that is vectorizedcontent: an array of objects, each object having twosymbolproperties:sectionTitleandtext. Thetextproperty is vectorized.
Required setup
Required setup
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 theknn 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 thoughabstract 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 allmatch queries on a same property.
Vector search on an Array property
When your data contains arrays, you can use theknn 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.