Home

Awesome

licence release rust

HNSW for Redis

<a id="markdown-hnsw-for-redis" name="hnsw-for-redis"></a>

redis_hnsw is a Hierarchical Navigable Small World (HNSW) implementation for Redis. Based on the paper Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs. Currently only supports Euclidean distance, Hamming distance forthcoming.

<!-- TOC -->

Table of Contents

<!-- /TOC -->

Getting Started

<a id="markdown-getting-started" name="getting-started"></a>

:warning: requires nightly rust

Build the module - cargo build

Load the module - redis-server --loadmodule ./target/<build_mode>/libredis_hnsw.<dylib|so>

Redis commands

<a id="markdown-redis-commands" name="redis-commands"></a> Creating a new index - hnsw.new {index_name} [DIM {data_dim}] [M {m}] [EFCON {ef_construction}]

Add nodes - hnsw.node.add {index_name} {node_name} [DATA {dim} {...data}]

Delete nodes - hnsw.node.del {index_name} {node_name}

Search KNN - hnsw.search {index_name} [K {k}] [DATA {dim} {...data}]

Command Reference

<a id="markdown-command-reference" name="command-reference"></a>

HNSW.NEW

<a id="markdown-hnsw.new" name="hnsw.new"></a>

Format

HNSW.NEW {index} [DIM {data_dim}] [M {m}] [EFCON {ef_construction}]

Description

Creates an HNSW index

Example

HNSW.NEW foo DIM 128 M 5 EFCON 200

Parameters

Complexity

O(1)

Returns

OK or an error

HNSW.GET

<a id="markdown-hnsw.get" name="hnsw.get"></a>

Format

HNSW.GET {index}

Description

Retrieves an HNSW index

Example

HNSW.GET foo

Parameters

Complexity

O(1)

Returns

Array Reply key-value pairs of index attributes

HNSW.DEL

<a id="markdown-hnsw.del" name="hnsw.del"></a>

Format

HNSW.DEL {index}

Description

Deletes an HNSW index

Example

HNSW.DEL foo

Parameters

Complexity

O(1)

Returns

OK or an error

HNSW.NODE.ADD

<a id="markdown-hnsw.node.add" name="hnsw.node.add"></a>

Format

HNSW.NODE.ADD {index} {node} [DATA {dim} {...data}]

Description

Adds an element to the index

Example

HNSW.NODE.ADD foo bar DATA 4 1.0 1.0 1.0 1.0

Parameters

Complexity

O(log(n)) where n is the number of nodes in the index

Returns

OK or an error

HNSW.NODE.GET

<a id="markdown-hnsw.node.get" name="hnsw.node.get"></a>

Format

HNSW.NODE.GET {index} {node}

Description

Retrieves an element from the index

Example

HNSW.NODE.GET foo bar

Parameters

Complexity

O(1)

Returns

Array Reply key-value pairs of node attributes

HNSW.NODE.DEL

<a id="markdown-hnsw.node.del" name="hnsw.node.del"></a>

Format

HNSW.NODE.DEL {index} {node}

Description

Removes an element from the index

Example

HNSW.NODE.DEL foo bar

Parameters

Complexity

O(log(n)) where n is the number of nodes in the index

Returns

OK or an error

HNSW.SEARCH

<a id="markdown-hnsw.search" name="hnsw.search"></a>

Format

HNSW.SEARCH {index} [K {k}] [QUERY {dim} {...data}]

Description

Search the index for the K nearest elements to the query

Example

HNSW.SEARCH foo K 5 QUERY 4 0.0 0.0 0.0 0.0

Parameters

Complexity

O(log(n)) where n is the number of nodes in the index

Returns

Array Reply where the first element is the number of results, followed by key-value pairs of similiarity and returned node key.