surrealdb-vector

v2026.09.24

Vector search with SurrealDB using HNSW indexes, KNN queries, and similarity scoring. Use when creating vector indexes, querying vectors with KNN distance operators, building semantic search or RAG pipelines, tuning HNSW parameters (EFC, M, M0, distance function, type), or implementing recommendation systems with SurrealDB. Triggers: HNSW, vector, embedding, KNN, cosine, euclidean, semantic search, RAG, vector::distance.

GitHub
安装命令
npx skhub add surrealdb/surrealdb-vector
Markdown
SKILL.md

SurrealDB Vector Search

HNSW Index

Create a basic HNSW index:

DEFINE INDEX hnsw_idx ON pts FIELDS point HNSW DIMENSION 4;

With specific distance function and type:

DEFINE INDEX hnsw_idx ON pts FIELDS point HNSW DIMENSION 4 DIST EUCLIDEAN TYPE F64;

Available types: F64, F32, I64, I32, I16.

Full Table Example

DEFINE TABLE OVERWRITE document SCHEMALESS;
DEFINE FIELD OVERWRITE embedding ON document TYPE array<float>;
DEFINE INDEX OVERWRITE hnsw_idx_document ON document
    FIELDS embedding
    HNSW DIMENSION 384
    DIST COSINE
    TYPE F32
    EFC 150 M 12 M0 24;

HNSW Parameters

ParameterDescription
DIMENSIONVector dimensionality (must match your embeddings)
DISTDistance function: COSINE, EUCLIDEAN, etc.
TYPENumeric type: F64, F32, I64, I32, I16
EFCConstruction search effort (higher = better index)
MMax connections per node
M0Max connections at layer 0

Querying Vectors

The <|K, EF|> operator performs KNN search. K is the number of results, EF is the search effort (higher = more accurate, slower).

Recommended effort values:

  • 40 — default, good accuracy
  • 17 — fast but may miss some results

Basic KNN Query

SELECT
    *,
    vector::distance::knn() AS dist
FROM document
WHERE embedding <|10, 40|> $vector;

vector::distance::knn() uses the distance function defined by the index.

Scored Results with Threshold

SELECT *, score
FROM (
    SELECT *, (1 - vector::distance::knn()) AS score
    FROM document
    WHERE embedding <|20, 40|> $vector
)
WHERE score >= $threshold
ORDER BY score DESC;
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

skills/surrealdb-vector

默认分支

main

最新提交

e5eadc5

Tree SHA

15eb4c6