// Connect to Redis
const redis = require('redis');
const client = redis.createClient();
// Create a vector set and add vectors
async function addVectors() {
// Create a text embedding vector set
await client.sendCommand([
'VADD', 'product_descriptions',
'product:1002', 'VALUES', '5', '1.0', '0.2', '0.5', '0.8', '0.1'
]);
// Add another vector to the set
await client.sendCommand([
'VADD', 'product_descriptions',
'product:1002', 'VALUES', '5', '0.9', '0.3', '0.4', '0.7', '0.2'
]);
console.log('Vectors added successfully!');
}
// Connect to Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
// Create a vector set and add vectors
function addVectors($redis) {
// Create an image embedding vector set
$redis->rawCommand(
'VADD', 'image_embeddings',
'image:1001', 'VALUES', '5', '0.7', '0.3', '0.5', '0.2', '0.9'
);
// Add another vector to the set
$redis->rawCommand(
'VADD', 'image_embeddings',
'image:1002', 'VALUES', '5', '0.6', '0.4', '0.5', '0.3', '0.8'
);
// Add multiple vectors in a batch operation
$vectors = [
['id' => 'image:1003', 'vector' => [0.5, 0.5, 0.6, 0.2, 0.7]],
['id' => 'image:1004', 'vector' => [0.4, 0.6, 0.5, 0.3, 0.8]],
['id' => 'image:1005', 'vector' => [0.3, 0.7, 0.4, 0.4, 0.9]]
];
foreach ($vectors as $item) {
$params = array_merge(
['VADD', 'image_embeddings', $item['id'], 'VALUES', '5'],
$item['vector']
);
$redis->rawCommand(...$params);
}
echo "Vectors added successfully!\n";
}
#include
#include
#include
#include "hiredis.h"
int main() {
// Connect to Redis
redisContext *c = redisConnect("127.0.0.1", 6379);
if (c == NULL || c->err) {
if (c) {
printf("Error: %s\n", c->errstr);
redisFree(c);
} else {
printf("Cannot allocate redis context\n");
}
return 1;
}
// Create an audio embedding vector set
redisReply *reply;
reply = redisCommand(c, "VADD audio_embeddings audio:1001 0.4 0.6 0.3 0.7 0.2");
if (reply) freeReplyObject(reply);
// Add another vector to the set
reply = redisCommand(c, "VADD audio_embeddings audio:1002 0.5 0.5 0.4 0.6 0.3");
if (reply) freeReplyObject(reply);
printf("Vectors added successfully!\n");
// Clean up
redisFree(c);
return 0;
}
Vector sets make it easy to store text embeddings from any source. Easily store and query text embeddings with simple commands that are perfect for semantic search, recommendation systems, and natural language processing apps.
Power visual similarity searches for content-based image retrieval, duplicate detection, visual recommendation systems, and high-dimensional image embeddings with higher performance.
// Find similar vectors
async function findSimilarProducts() {
// Search for products similar to product:1001
const results = await client.sendCommand([
'VSIM', 'product_descriptions', 'ELE','product:1001', 'WITHSCORES'
]);
// Results include product IDs and similarity scores
console.log('Similar products:', results);
// Find similar vectors
function findSimilarImages($redis) {
// Search for images similar to image:1001
$results = $redis->rawCommand(
'VSIM', 'image_embeddings', 'ELEMENT', 'image:1001', 'WITHSCORES'
);
// Results include image IDs and similarity scores
echo "Similar images: " . print_r($results, true) . "\n";
// Find similar vectors
int find_similar_audio(redisContext *c) {
redisReply *reply;
// Search for audio similar to audio:1001
reply = redisCommand(c, "VSIM audio_embeddings audio:1001 3");
if (reply) {
printf("Similar audio files:\n");
for (int i = 0; i elements; i += 2) {
printf(" ID: %s, Score: %s\n",
reply->element[i]->str,
reply->element[i+1]->str);
}
freeReplyObject(reply);
}
// Search using a vector directly
const queryVector = [0.95, 0.25, 0.45, 0.75, 0.15];
const directResults = await client.sendCommand([
'VSIM', 'product_descriptions', 'VALUES', '5',
...queryVector, "WITHSCORES"
]);
console.log('Direct vector search results:', directResults);
}
// Search using a vector directly
$queryVector = [0.65, 0.35, 0.55, 0.25, 0.85];
$params = array_merge(
['VSIM', 'image_embeddings', 'VALUES', '5'],
$queryVector,
['WITHSCORES', 'LIMIT', '0', '3']
);
$directResults = $redis->rawCommand(...$params);
echo "Direct vector search results: " . print_r($directResults, true) . "\n";
}
findSimilarImages($redis);
?>
// Search using a vector directly
reply = redisCommand(c,
"VSIMDIRECT audio_embeddings 5 0.45 0.55 0.35 0.65 0.25 3");
if (reply) {
printf("Direct vector search results:\n");
for (int i = 0; i elements; i += 2) {
printf(" ID: %s, Score: %s\n",
reply->element[i]->str,
reply->element[i+1]->str);
}
freeReplyObject(reply);
}
return 0;
}
Vector sets make audio similarity searches lightning fast for audio fingerprinting, voice recognition, music recommendation, and sound classification.
Vector sets a simple, powerful way to work with vector embeddings
In-memory performance for real-time vector similarity searches
Simple commands that work with your existing Redis setup
Handle millions of vectors with consistent performance
Store text, image, audio, or any other vector embeddings
Works with any embedding model or provider
Built with our proven reliability and performance
Speak to a Redis expert and learn more about enterprise-grade Redis today.