surrealdb-vector — Claude Code skill: HNSW and KNN in SurrealDB
Teaches your agent to write vector search queries in SurrealDB: HNSW indexes, KNN operators, similarity scoring.
npx skills add surrealdb/agent-skills --skill surrealdb-vector -a claude-codeWhat surrealdb-vector does
The skill hands your agent ready-made SurrealQL patterns for vector search. It covers HNSW index definitions with DIMENSION, DIST, TYPE, EFC, M and M0, plus queries using the <|K, EF|> operator and vector::distance::knn(). Useful when you are building semantic search or a RAG pipeline on SurrealDB and keep forgetting the exact syntax.
There is a full table example: DEFINE TABLE OVERWRITE document SCHEMALESS, an embedding field typed array<float>, and an index with HNSW DIMENSION 384 DIST COSINE TYPE F32 EFC 150 M 12 M0 24. For filtered results the skill shows a nested query that computes score as 1 - vector::distance::knn(), then filters on score >= $threshold and orders descending.
Index dimensionality has to match your embeddings, or the search simply will not work. The skill suggests EF of 40 for solid accuracy and 17 when speed matters more. Pick F64 or F32 to match how your vectors are already stored.
Install runs through npx skills add with the target agent named.
What it helps with
- define an HNSW index for your embedding field
- write a KNN query with the
<|K, EF|>operator - compute a similarity score and drop weak matches by threshold
- tune
EFC,MandM0for your workload - build a semantic search result set ordered by score
Example prompts for the agent
- create an HNSW index on the document table over embedding, dimension 384, cosine distance
- write a KNN query returning the 10 nearest vectors to $vector with a similarity score
- add a score threshold and order the results descending
How to install surrealdb-vector
1Skills CLI (Vercel)
npx skills add surrealdb/agent-skills --skill surrealdb-vector -a claude-code2Manually: put the files in place
~/.claude/skills/surrealdb-vector/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/surrealdb-vector/
1Skills CLI (Vercel)
npx skills add surrealdb/agent-skills --skill surrealdb-vector -a codex2Manually: put the files in place
.agents/skills/surrealdb-vector/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add surrealdb/agent-skills --skill surrealdb-vector -a cursor2Manually: put the files in place
.cursor/skills/surrealdb-vector/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install surrealdb/agent-skills surrealdb-vector2Manually: put the files in place
.github/skills/surrealdb-vector/SKILL.md1Skills CLI (Vercel)
npx skills add surrealdb/agent-skills --skill surrealdb-vector -a gemini-cli2Platform CLI
gemini skills install https://github.com/surrealdb/agent-skills --path skills/surrealdb-vectorManually: put the files in place
.devin/skills/surrealdb-vector/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add surrealdb/agent-skills --skill surrealdb-vector -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about surrealdb-vector
How do I install surrealdb-vector in Claude?
Run npx skills add surrealdb/agent-skills --skill surrealdb-vector -a claude-code. The skill file lands at ~/.claude/skills/surrealdb-vector/SKILL.md.
What does surrealdb-vector do?
It gives the agent SurrealDB vector search syntax: HNSW index definitions, KNN queries, similarity scoring and index parameter tuning.
How is it different from a plain table lookup?
Queries go through HNSW indexes and the <|K, EF|> operator, so matching happens on vector distance instead of exact field values.
Source text
SKILL.md · MIT
---
name: surrealdb-vector
description: "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."
metadata:
author: surrealdb
version: "0.1.0"
---
# SurrealDB Vector Search
## HNSW Index
Create a basic HNSW index:
```surql
DEFINE INDEX hnsw_idx ON pts FIELDS point HNSW DIMENSION 4;
```
With specific distance function and type:
```surql
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
```surql
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
| Parameter | Description |
| --------- | ------------------------------------------------ |
| DIMENSION | Vector dimensionality (must match your embeddings)|
| DIST | Distance function: `COSINE`, `EUCLIDEAN`, etc. |
| TYPE | Numeric type: `F64`, `F32`, `I64`, `I32`, `I16` |
| EFC | Construction search effort (higher = better index)|
| M | Max connections per node |
| M0 | Max 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
```surql
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
```surql
SELECT *, score
FROM (
SELECT *, (1 - vector::distance::knn()) AS score
FROM document
WHERE embedding <|20, 40|> $vector
)
WHERE score >= $threshold
ORDER BY score DESC;
```
© surrealdb · MIT · surrealdb/agent-skills