Vector Search
Redlite supports Redis 8-compatible vector sets for K-NN similarity search. Requires --features vectors when compiling.
Installation
Section titled “Installation”cargo add redlite --features vectors# orcargo install redlite --features vectorsCommands
Section titled “Commands”Add a vector element to a set.
VADD key VALUES n v1 v2 ... element [NOQUANT|Q8|BF16] [SETATTR json]Parameters:
key- Vector set keyVALUES n v1 v2 ...- Vector dimensions (n floats)element- Element identifier (string)NOQUANT|Q8|BF16- Optional quantization (default: NOQUANT)SETATTR json- Optional JSON attributes
Examples:
# Add a 3-dimensional vector127.0.0.1:6379> VADD embeddings VALUES 3 0.1 0.2 0.3 item1(integer) 1
# Add with attributes127.0.0.1:6379> VADD embeddings VALUES 3 0.4 0.5 0.6 item2 SETATTR '{"category":"books"}'(integer) 1
# Add with quantization (8-bit)127.0.0.1:6379> VADD embeddings VALUES 3 0.7 0.8 0.9 item3 Q8(integer) 1Find similar vectors using K-NN search.
VSIM key (ELE element | VALUES n v1 v2 ...) [COUNT n] [WITHSCORES] [WITHATTRIBS] [FILTER expr]Parameters:
key- Vector set keyELE element- Reference element in the setVALUES n v1 v2 ...- Query vectorCOUNT n- Maximum results to return (default: 10)WITHSCORES- Include distance scoresWITHATTRIBS- Include element attributesFILTER expr- Filter by attributes
Examples:
# Find 5 nearest neighbors127.0.0.1:6379> VSIM embeddings VALUES 3 0.15 0.25 0.35 COUNT 51) "item1"2) "item2"
# With distance scores127.0.0.1:6379> VSIM embeddings VALUES 3 0.15 0.25 0.35 COUNT 5 WITHSCORES1) "item1"2) "0.0087"3) "item2"4) "0.1875"
# Using existing element as query127.0.0.1:6379> VSIM embeddings ELE item1 COUNT 31) "item1"2) "item2"3) "item3"
# With attribute filter127.0.0.1:6379> VSIM embeddings VALUES 3 0.1 0.2 0.3 FILTER '@category == "books"'1) "item2"Remove an element from a vector set.
VREM key elementExample:
127.0.0.1:6379> VREM embeddings item1(integer) 1Get the number of elements in a vector set.
VCARD keyExample:
127.0.0.1:6379> VCARD embeddings(integer) 3Get the dimensions of vectors in a set.
VDIM keyExample:
127.0.0.1:6379> VDIM embeddings(integer) 3VEXISTS
Section titled “VEXISTS”Check if an element exists in a vector set.
VEXISTS key elementExample:
127.0.0.1:6379> VEXISTS embeddings item1(integer) 1127.0.0.1:6379> VEXISTS embeddings nonexistent(integer) 0Get the embedding vector for an element.
VGET key elementExample:
127.0.0.1:6379> VGET embeddings item11) "0.1"2) "0.2"3) "0.3"VGETALL
Section titled “VGETALL”Get all elements and their embeddings.
VGETALL keyExample:
127.0.0.1:6379> VGETALL embeddings1) 1) "item1" 2) 1) "0.1" 2) "0.2" 3) "0.3"2) 1) "item2" 2) 1) "0.4" 2) "0.5" 3) "0.6"VGETATTRIBUTES
Section titled “VGETATTRIBUTES”Get JSON attributes for elements.
VGETATTRIBUTES key element [element ...]Example:
127.0.0.1:6379> VGETATTRIBUTES embeddings item21) "item2"2) "{\"category\":\"books\"}"VSETATTRIBUTES
Section titled “VSETATTRIBUTES”Set JSON attributes for an element.
VSETATTRIBUTES key element jsonExample:
127.0.0.1:6379> VSETATTRIBUTES embeddings item1 '{"tags":["new","featured"]}'OKVDELATTRIBUTES
Section titled “VDELATTRIBUTES”Delete attributes from an element.
VDELATTRIBUTES key elementExample:
127.0.0.1:6379> VDELATTRIBUTES embeddings item1OKVSIMBATCH
Section titled “VSIMBATCH”Batch similarity search across multiple vector sets.
VSIMBATCH n key1 key2 ... VALUES m v1 v2 ... [COUNT n] [WITHSCORES]Example:
127.0.0.1:6379> VSIMBATCH 2 embeddings1 embeddings2 VALUES 3 0.1 0.2 0.3 COUNT 51) 1) "embeddings1" 2) 1) "item1" 2) "item2"2) 1) "embeddings2" 2) 1) "doc1"Use Cases
Section titled “Use Cases”Semantic Search
Section titled “Semantic Search”# Index document embeddingsVADD docs VALUES 384 0.1 0.2 ... doc:1 SETATTR '{"title":"Introduction to AI"}'VADD docs VALUES 384 0.15 0.25 ... doc:2 SETATTR '{"title":"Machine Learning Basics"}'
# Search by query embeddingVSIM docs VALUES 384 0.12 0.22 ... COUNT 10 WITHATTRIBSImage Similarity
Section titled “Image Similarity”# Index image feature vectorsVADD images VALUES 512 ... img:1 SETATTR '{"path":"/uploads/cat.jpg"}'VADD images VALUES 512 ... img:2 SETATTR '{"path":"/uploads/dog.jpg"}'
# Find similar imagesVSIM images ELE img:1 COUNT 5 WITHSCORES WITHATTRIBSRecommendation Engine
Section titled “Recommendation Engine”# Index user embeddingsVADD users VALUES 128 ... user:1VADD users VALUES 128 ... user:2
# Find similar users for recommendationsVSIM users ELE user:1 COUNT 10Quantization
Section titled “Quantization”Redlite supports three quantization modes to trade off precision for storage:
| Mode | Description | Storage | Precision |
|---|---|---|---|
NOQUANT | Full precision (f32) | 4 bytes/dim | Highest |
Q8 | 8-bit quantization | 1 byte/dim | Good |
BF16 | BFloat16 | 2 bytes/dim | High |
Use quantization for large-scale deployments to reduce storage while maintaining search quality.
Implementation Notes
Section titled “Implementation Notes”- Backend: sqlite-vec extension for SIMD-accelerated distance calculations
- Storage: Vectors stored as BLOBs in SQLite
- Distance metric: L2 (Euclidean) distance
- Auto-dimension: Vector dimensions are auto-detected from the first element