Skip to content

Commit

Permalink
Add KNN operator for K-Nearest Neighbors search
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekwuno committed Mar 12, 2024
1 parent ed4c527 commit 5e83ea2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions versioned_docs/version-1.x/surrealql/operators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,15 @@ ORDER BY score DESC;
]
```

## `#KNN` {#KNN}

Performs a K-Nearest Neighbors (KNN) search to find a specified number of records closest to a given data point, optionally using a defined distance metric. Supports customizing the number of results and choice of distance calculation method.

```surql
CREATE pts:3 SET point = [8,9,10,11];
DEFINE INDEX mt_pts ON pts FIELDS point MTREE DIMENSION 4;
SELECT id, vector::distance::euclidean(point, [2,3,4,5]) AS dist FROM pts WHERE point <|2,EUCLIDEAN|> [2,3,4,5];
SELECT id FROM pts WHERE point <|2|> [2,3,4,5] EXPLAIN;
```

<br /><br />

0 comments on commit 5e83ea2

Please sign in to comment.