Skip to content

Latest commit

 

History

History
59 lines (38 loc) · 2.35 KB

File metadata and controls

59 lines (38 loc) · 2.35 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 valkey-search

  1. Follow the instructions to build Valkey from source. Make sure to use Valkey version 7.2.6 or later as the previous versions have Valkey module API bugs.
  2. Follow the instructions to build the valkey-search module from source.

Step 2: Run the Valkey Server

Once valkey-search is built, run the Valkey server with the valkey-search module loaded:

./valkey-server "--loadmodule libsearch.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.