KiviDB implements Redis Stack–compatible search and vector commands, so existing clients and tutorials largely work unchanged. Use them for full-text (BM25), tags / numerics, and vector ANN (FLAT or HNSW) on hash fields.
- Create an index on keys with a prefix, declaring at least one
VECTORfield (HNSW or FLAT) and optionalTEXT/TAG/NUMERICfields:
redis-cli -p 6380 FT.CREATE idx ON HASH PREFIX 1 doc: SCHEMA \
vec VECTOR HNSW 10 TYPE FLOAT32 DIM 128 DISTANCE_METRIC COSINE M 16 EF_CONSTRUCTION 128-
Store vectors as raw FLOAT32 little-endian bytes in a hash field (
DIM × 4bytes), the same convention as Redis Stack andredis-py/numpyblobs. Use your client's binary-safeHSET(the integration tests undertests/e2e/have examples). -
Query with KNN (Dialect 2), passing the query vector as a named binary parameter (
<blob>stands for the query vector's raw bytes, which a shell cannot type: send this from a client library, as in step 2):
redis-cli -p 6380 FT.SEARCH idx '*=>[KNN 10 @vec $q]' PARAMS 2 q <blob> DIALECT 2The full command surface, filters, hybrid search and edge cases are in COMMANDS.md (search for FT.CREATE, FT.SEARCH, FT.HYBRID, and so on).
-
Vectors are linked into an HNSW graph by helper threads, as many as
search-index-threadssays (--search-index-threads, or in the configuration file; read at startup,CONFIG GETshows it): a number, 0 meaning each write links its own vector as 1.2 did, orauto, the default.autostarts none under a CPU quota (a container's--cpus, a Kubernetes CPU limit) or on fewer than 8 CPUs. Otherwise it starts one fewer than the CPUs (seven on 8, fifteen on 16), and how many of them link depends on what the server is doing:- while it serves clients, (CPUs - 2) / 2 of them: three on 8, seven on 16;
- while it does nothing but take the writes that fill the backlogs (a bulk load,
FT.CREATEover existing keys, a replica's full sync), all of them.
The server counts as serving when, besides the commands that wrote vectors, it served 500 commands a second, or its threads used a CPU's worth of time besides the links and the commands that wrote vectors. The helpers look every 50 ms. They go back to the serving count at the first look that finds clients. They take the others in again after 200 ms without any. A number starts exactly that many, all of which always link. They start on the first write that needs them and run as
SCHED_IDLEon Linux, taking CPU time the workers leave; the log says how many there are, andFT.INFOshowshnsw_index_threads(started) andhnsw_index_threads_active(linking now).- On a server of fewer than 8 CPUs, builds run at 1.2's speed by default.
search-index-threads 1(or more) trades serving latency for build speed there. Measured with every CPU of a 4-vCPU server busy (memtier GET/SET, one client loading 384-d vectors in pipelines, oneHSETevery 2 ms from another client): GET/SET p99 1.6 ms with none, 2.1 ms with one helper, 2.6 ms with two; the build alone 1,540, 3,190 and 3,620 documents a second. A writer whose connection shares the bulk loader's worker waits behind the loader's pipelines with or without helpers (its median 15-25 ms with none, 12-16 ms with one); on the other connections one helper raised theHSETp99 from 2.3-2.7 ms to 4.5-4.7 ms. - Under a CPU limit the helpers would spend the quota the workers need and the whole
server would be throttled (GET/SET p99 8-9 ms against 0.35 ms beside a load with
--cpus 2and one helper), so there builds run at 1.2's speed unlesssearch-index-threadsis given a number. - On a server whose CPUs the workers keep busy the backlog stays full and each write links its own vector too (measured with every server CPU busy: the backlog held its limit the whole time).
-
A write puts its vector in the graph's backlog and returns; a search measures every vector of the backlog exactly, beside what it finds in the graph, so a document is found from the moment its
HSETis answered, as before. The backlog holds at most 1,024 vectors, and at most 128 Ki floats (85 vectors of 1,536 dimensions, 341 of 384; never fewer than 64): a writer that finds it full links its vector itself. The walk that indexes the documents already there (FT.CREATEon existing keys, a restart, a replica's full sync) hands its vectors over the same way. A graph of fewer than 1,000 nodes links each vector in the write. -
FT.INFOshows the backlog ashnsw_backlog(andbacklogper field underhnsw_indexes), and ashnsw_backlog_bytesthe memory it holds, the helpers' queued jobs included: at most one a waiting key, so writes over the same keys do not grow it. A graph dropped (FT.DROPINDEX,FLUSHALL) or replaced by a compaction is freed at once, whatever its jobs.hnsw_live_countcounts the graph's nodes, so it trails the documents while the backlog is not empty;num_docsdoes not. -
A KNN search looks at no fewer than 50 candidates, whatever
EF_RUNTIMEsays (the default is 10, as in Redis). So the default answers with the recall Redis gives at aboutEF_RUNTIME 50, and costs about what that costs; compare the two at the same recall, not the sameEF_RUNTIME. -
Measured numbers are in PERFORMANCE.md.
A GEOSHAPE field holds a shape in WKT, as in Redis 8.10: POINT(x y) or
POLYGON((x y, …), (hole), …), nothing else (LINESTRING, MULTI… and the
rest are refused). Its coordinate system follows the type:
GEOSHAPE FLAT (the plane) or GEOSHAPE SPHERICAL (the default: lon lat in
degrees). It takes SORTABLE, NOINDEX and INDEXMISSING.
On a FLAT field a coordinate is 0 or between 1e-100 and 1e100 in magnitude,
so that no product the checks and predicates form can overflow or underflow.
A stored value outside that leaves its document in the index without a shape,
counted in hash_indexing_failures; a query's shape outside it is refused.
SPHERICAL coordinates are angles and have no such limit.
FT.CREATE shapes ON HASH PREFIX 1 shape: SCHEMA geom GEOSHAPE FLAT
HSET shape:1 geom "POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))"
FT.SEARCH shapes "@geom:[WITHIN $area]" PARAMS 2 area "POLYGON((-1 -1, 11 -1, 11 11, -1 11, -1 -1))" DIALECT 2
- Queries:
@field:[WITHIN $p],[CONTAINS $p],[INTERSECTS $p]and[DISJOINT $p], the shape always a parameter, fromDIALECT 2on. In dialect 1 (the default,search-default-dialect) and with the WKT written in the query, the clause is a syntax error, as in Redis.WITHINandCONTAINSdo not count a point on an edge or a corner: such a point intersects the shape but is not within it. A point is never within, nor contains, another point. A shape clause scores 0. - Values that are no shape: a HASH value that is not WKT, a polygon that
crosses itself, has a spike, has no area, or has a hole outside it or
inside another hole, leaves its document in the index without a shape in
that field, and counts as a failure in
FT.INFO'shash_indexing_failures, with Redis's error.POINT EMPTYis refused too (Redis keeps it, with coordinates of no use). On JSON the field takes a string; a number, boolean, object or array (even of strings) leaves the whole document out of the index, as in Redis. - Edges and rounding: a point a rounding step from an edge is on it; the step grows with the coordinates, so near 1e9 a point 1e-7 inside an edge is on it, as in Redis.
- SPHERICAL: an edge is the shorter great-circle arc between its points,
so a polygon with an edge across the antimeridian is the narrow one there.
Coordinates are not range checked, as in Redis. Redis measures edges on
the WGS84 ellipsoid with an approximation; the two can decide a point
within about 0.01 degree of a long edge differently (north of the edge
from
0 60to90 60, Redis puts it near latitude 67.8 at longitude 45, the great circle at 67.79). A SPHERICAL polygon, stored or queried, must fit within 44.5 degrees of the middle of its points (about 4,900 km): a larger stored one is a failure when it is written (the document stays, without a shape), and a larger query shape is an error. Redis takes larger ones; this keeps any two shapes that may meet comparable in one projection. - Limits: a shape has at most 32,768 points. Checking a polygon takes at
most 16,777,216 steps (pairs of its segments, and the points its holes
are located by). A query has at most 16 shape clauses. Its shape clauses
together take at most 134,217,728 steps (shapes looked at, segment pairs,
point tests) over the documents they measure,
TIMEOUT 0too, and the query answers an error past that. That is about a second of one worker for the costliest shapes (a release build on a 4-CPU Azure D4s_v5), andsearch-geoshape-max-steps(CONFIG SET, the configuration file) sets it; aTIMEOUTends them sooner, withTimeout limit was reached. InMULTI/EXECand in a script run alone, where every other command waits for it, the steps are a sixteenth of that.FT.HYBRIDgives each of its two queries half. What the clauses keep of their answers (a bit and 16 bytes a matching document) is at most 64 MiB a query, an error past that. Bounding boxes come first: a document whose box rules it out costs no segment loop.DISJOINTfinds only documents that hold a shape, as in Redis. - Storage: each document's shape is parsed once, when it is written, and
kept with the document's other postings; a query reads no WKT of the
documents it measures. The shapes are counted in the index's memory
(
used_memory,maxmemory) and inFT.INFO'spostings_shape_bytesandgeoshapes_sz_mb.FT.INFOlists the field astype GEOSHAPE coord_system FLAT;FT.EXPLAINwrites the clauseGEOSHAPE{2 <wkt>}, the number being the predicate (1CONTAINS, 2WITHIN, 3DISJOINT, 4INTERSECTS).
- Native snapshots (
dump.kdb) store the keys, the index schemas, and, when youSAVE/BGSAVEwith indexes populated, the HNSW graph of each vector field, so search quality after a restart matches the graph you had before shutdown. - While search indexes are being rebuilt at startup, most commands return
LOADINGuntil the rebuild finishes;PING,INFOand a few other commands still work. - Documents that a query finds level (equal
SORTBYvalues, the same score, vectors as near) come in the order they were written, as in Redis:SORTBY … ASCfirst written first,DESCthe reverse. A write that names a field of the index makes its document the last written. Snapshots keep that order (their document order section), the AOF replays it, and a replica has its master's. - Limits of that order:
HEXPIREof an indexed field leaves the document where it is; with KNN andkbelow the number of vectors at the same distance, which of those are returned is not decided by the order they were written in; withaof-preamble no, the order after an AOF rewrite is that of the rewritten file;FT.HYBRIDdoes not use it; a replica fed from its master's stream can order level documents written at the same time from different connections otherwise than its master, so aLIMITpage that ends among them can differ; an index of vector fields only keeps the order of the keys; the documents written after anFT.CREATEwhile its first walk is still filling the index, saved in that window, load in the order of their keys. ARENAMEkeeps the document's place, as in Redis.FT.AGGREGATEgives groups in the order of their first documents written. - After a large ingest, run
SAVE(or scheduleBGSAVE) so the next start reloads the graph from disk instead of rebuilding it from the hashes.