These operations allow you to search for vectors in Helix. Searching is done using cosine similarity.

SearchV

Search for vectors in your graph.

SearchV<Type>(vector, {properties})

Example:

In schema.hx:

V::Document {
    text: String
    created_at: I64
}

In query.hx:

QUERY SearchVector (vector: [F64], k: I64) =>
    // Search for the vector in the graph (returns k results)
    documents <- SearchV<Document>(vector, k)
    RETURN documents

Note: Currently, we only support using an array of F64 values to represent the vector. We will be adding support for different types such as F32, binary vectors and more in the very near future. Please reach out to us if you need a different vector type.


Prefiltering

You can prefilter the results of a search by adding a PREFILTER clause to the query. The condition in the PREFILTER step must evaluate to a boolean value.

SearchV<Type>(vector)::PREFILTER(<boolean_expression>)

Example:

QUERY SearchVector (vector: [F64], now: I64) =>
    documents <- SearchV<Document>(vector)::PREFILTER(_::{created_at}::LTE(now))
    RETURN documents

The condition is applied through out the search process. At each step, when the HNSW algorithm looks at the nearest neighbors, it will only consider nodes that satisfy the condition. This means that the final results have only been influenced by other vectors that satisfy the condition.


Postfiltering

You can postfilter the results of a search by adding a WHERE clause to the query. The condition in the WHERE step must evaluate to a boolean value.

SearchV<Type>(vector)::WHERE(<boolean_expression>)

Example:

QUERY SearchVector (vector: [F64], now: I64) =>
    documents <- SearchV<Document>(vector)
    documents <- documents::WHERE(_::{created_at}::LTE(now))
    RETURN documents

The condition is applied after the search has been completed.