seekdb Vector Ops
A practical, safety-first playbook for working with seekdb as a vector + full-text + relational database. It is for agents that need to produce SQL that actually runs, choose the right index, and verify results instead of guessing.
When to use this skill
Use it when the user asks to:
- create or tune a seekdb
VECTOR INDEX(HNSW / IVF / HGraph,lib=vsagorlib=cuvs); - use
TOKENIZE,MATCH ... AGAINST, or an IK/ngram/whitespace full-text parser; - write a hybrid query that combines vector similarity, full-text match,
scalar filters, and
LIMITin one SQL statement; - diagnose slow vector/FTS queries, bad recall, or a query that unexpectedly falls back to a full scan;
- build a reproducible seekdb smoke test or benchmark.
Do not use it as a substitute for the actual seekdb version's documentation
when a feature is version-gated. Verify with EXPLAIN and a small smoke query.
Ground rules
- Never invent SQL. Check the server version and run the smallest possible statement first. If a syntax is not supported by the installed seekdb, say so and offer a portable alternative.
- Keep the public vector type FP32. Internal quantization or GPU backends may be used, but the column and result semantics must remain FP32.
- Do not hide a CPU fallback. If
lib=cuvs/GPU is requested, show evidence that the GPU path actually built and served; otherwise report the fallback. - Measure with a cold index and include the first query. Vector index builds can be lazy; a build benchmark that stops before the first query is invalid.
- Protect credentials. Use
MODELSCOPE_*/database env vars or a local.env; never print passwords or API keys.
Workflow
1. Establish the environment
mysql -h "$SEEKDB_HOST" -P "${SEEKDB_PORT:-2881}" -u "$SEEKDB_USER" -p"$SEEKDB_PASSWORD" \
-e "SELECT VERSION(); SHOW VARIABLES LIKE 'ob_vector%';"
Ask for/confirm:
- seekdb version and whether it is embedded, standalone, or OceanBase-compatible;
- vector dimension and distance metric (
l2,cosine,inner_product); - expected row count, query Top-K, and whether filters/deletes are required;
- whether the task needs
lib=vsag(CPU),lib=cuvs(AMD GPU), or both.
2. Inspect before changing
SHOW CREATE TABLE your_table;
SHOW INDEX FROM your_table;
EXPLAIN SELECT ...;
Do not add a second vector index to a column that already has one unless the user explicitly wants an A/B comparison.
3. Choose the index
| Need | Recommended |
| --- | --- |
| General CPU vector search | type=hnsw, lib=vsag |
| AMD GPU CAGRA path | type=hnsw, lib=cuvs (L2 only; verify build trace) |
| Full-text Chinese/English | FULLTEXT INDEX ... WITH PARSER ik (or beng/ngram) |
| Vector + keyword + scalar | separate vector and full-text indexes; combine in one SQL |
| Exact ground truth | no ANN index; use exact distance scan for the test set only |
Start with m=16, ef_construction=200, ef_search=64 for a small HNSW smoke
test; tune only after Recall@K is measured.
4. Create and smoke-test
Use the inline SQL templates below. After DDL:
SELECT COUNT(*) FROM your_table;
SELECT id, l2_distance(embedding, '[...]') AS d
FROM your_table
ORDER BY d
LIMIT 10;
Then run the same query with the ANN index and compare IDs/Recall against the exact query. A result is not "working" until IDs are legal and Recall is within the task's threshold.
5. Diagnose
EXPLAINshows a full scan or the vector index is not used: check the column type/dimension, metric compatibility, and whether the index build finished.- GPU requested but query falls back: check
lib=cuvssupport, L2-only DDL, GPU device visibility, bridge library, and build/serve trace. - Full-text returns nothing: confirm the parser language,
TOKENIZEoutput, and that theMATCHcolumn list matches the index definition. - Hybrid query is slow: push scalar predicates into both branches, keep
LIMITbounded, and avoidSELECT *in the candidate branch.
Deliverables
When you finish, give the user:
- the exact DDL and query SQL;
- the seekdb version and index parameters;
- a small smoke test (table + rows + expected shape);
- the measured build/query numbers and Recall@K, or a clear statement that the environment could not measure them;
- any fallback/support caveats.
Inline SQL templates
Keep this section open while working; it is the minimum set that covers most seekdb vector/FTS/hybrid tasks.
Vector table and HNSW
CREATE TABLE docs (
id BIGINT PRIMARY KEY,
title VARCHAR(255),
body TEXT,
embedding VECTOR(128),
VECTOR INDEX vidx(embedding)
WITH (distance=l2, type=hnsw, lib=vsag, m=16, ef_construction=200, ef_search=64)
);
SELECT id, l2_distance(embedding, '[...]') AS d
FROM docs
ORDER BY d
LIMIT 10;
AMD GPU CAGRA uses the same shape with lib=cuvs; it is L2-only in the contest
baseline. Do not silently replace a failed GPU build with CPU results.
Full text
CREATE TABLE articles (
id BIGINT PRIMARY KEY,
title VARCHAR(255),
body TEXT,
FULLTEXT INDEX ft_idx(title, body) WITH PARSER ik
);
SELECT TOKENIZE('全文索引的分词器热路径优化', 'ik');
SELECT id, title
FROM articles
WHERE MATCH(title, body) AGAINST('全文索引 分词器' IN NATURAL LANGUAGE MODE)
LIMIT 20;
Use beng for English and ngram for fixed-length n-grams; verify the parser
name against the installed version.
One-SQL hybrid candidate
Validate with EXPLAIN first because the exact syntax is version-gated. A
portable shape is a bounded UNION ALL of a vector branch and a full-text
branch, with the same scalar filters applied in each branch:
SELECT id, title, score
FROM (
SELECT id, title, 1.0 / (1.0 + l2_distance(embedding, '[...]')) AS score
FROM docs
WHERE category = 'database'
ORDER BY l2_distance(embedding, '[...]')
LIMIT 50
) v
UNION ALL
SELECT id, title, 1.0 AS score
FROM docs
WHERE MATCH(title, body) AGAINST('全文索引 分词器' IN NATURAL LANGUAGE MODE)
AND category = 'database'
LIMIT 50;
Deduplicate by id in the application or an outer query when both branches can
hit the same row.
Smoke-test command
SEEKDB_HOST=127.0.0.1 SEEKDB_PORT=2881 \
SEEKDB_USER=root SEEKDB_PASSWORD='...' \
bash seekdb_smoke.sh
The full connection/DDL/query smoke script is available in the contest
repository if you need a runnable helper; the SQL templates above are
self-contained if only SKILL.md is available.
References
- seekdb project: https://github.com/oceanbase/seekdb
- PowerContext project: https://github.com/oceanbase/powercontext

Scan to join WeChat group