NitroSQLite

knnSearch

API Reference


API Reference / react-native-nitro-sqlite-vec / knnSearch

Function: knnSearch()

knnSearch(db, table, query, k, options?): KnnMatch[]

Search a vec0 table for the nearest vectors. Executes synchronously and returns matches ordered by increasing distance.

Parameters

db

NitroSQLiteConnection

Open NitroSQLite connection with sqlite-vec enabled.

table

string

Trusted SQL table identifier, interpolated into the statement.

query

string | number[]

JSON vector string passed through unchanged, or a numeric array serialized as JSON.

k

number

Maximum number of matches requested.

options?

KnnSearchOptions

Optional trusted vector column identifier.

Returns

KnnMatch[]

Matching row IDs and distances, or an empty array when no rows are returned.