Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 2.27 KB

QUICK_START.md

File metadata and controls

56 lines (38 loc) · 2.27 KB

Quick Start

Follow these steps to set up, build, and run the Valkey server with vector search capabilities. This guide will walk you through creating a vector index, inserting vectors, and issuing queries.

Step 1: Install Valkey and ValkeySearch

  1. Build Valkey from source by following the instructions here.
  2. Build ValkeySearch module from source by following the instructions here.

Step 2: Run the Valkey Server

Once ValkeySearch is built, run the Valkey server with the ValkeySearch module loaded:

./valkey-server "--loadmodule libvalkeysearch.so  --reader-threads 64 --writer-threads 64"

You should see the Valkey server start, and it will be ready to accept commands.

Step 3: Create a Vector Index

To enable vector search functionality, you need to create an index for storing vector data. Start a Valkey CLI session:

valkey-cli

Create a vector field using the FT.CREATE command. For example:

FT.CREATE myIndex SCHEMA vector VECTOR HNSW 6 TYPE FLOAT32 DIM 3 DISTANCE_METRIC COSINE
  • vector is the vector field for storing the vectors.
  • VECTOR HNSW specifies the use of the HNSW (Hierarchical Navigable Small World) algorithm for vector search.
  • DIM 3 sets the vector dimensionality to 3.
  • DISTANCE_METRIC COSINE sets the distance metric to cosine similarity.

Step 4: Insert Some Vectors

To insert vectors, use the HSET command:

HSET my_hash_key_1 vector "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?"
HSET my_hash_key_2 vector "\x00\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x80?"

Replace the \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80? and \x00\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x80? with actual vectors.

Step 5: Issue Vector Queries

Now that you've created an index and inserted vectors, you can perform a vector search. Use the FT.SEARCH command to find similar vectors:

FT.SEARCH myIndex "*=>[KNN 5 @vector $query_vector]" PARAMS 2 query_vector "\xcd\xccL?\x00\x00\x00\x00\x00\x00\x00\x00"

This command performs a K-nearest neighbors search and returns the top 5 closest vectors to the provided query vector.