Redis.VectorSet (Redis v0.8.0)

Copy Markdown View Source

High-level API for Redis Vector Sets (Redis 8.0+).

Wraps the Vector Set commands with a connection-aware interface. For raw command builders, see Redis.Commands.VectorSet.

Quick Start

# Add elements with vectors
{:ok, 1} = Redis.VectorSet.vadd(conn, "movies", "matrix", [0.1, 0.8, 0.3])

# Search by vector similarity
{:ok, results} = Redis.VectorSet.search(conn, "movies", [0.1, 0.8, 0.3], count: 5)

# Search by existing element
{:ok, results} = Redis.VectorSet.vsim(conn, "movies", {:element, "matrix"}, count: 10)

# Manage attributes
{:ok, "OK"} = Redis.VectorSet.vsetattr(conn, "movies", "matrix", ~s({"year": 1999}))
{:ok, json} = Redis.VectorSet.vgetattr(conn, "movies", "matrix")

Attribute Filtering

When searching with vsim/4 or search/4, the :filter option accepts a filter expression string that is evaluated against element attributes:

Redis.VectorSet.search(conn, "movies", vector, filter: ".year > 2000")

Summary

Functions

Searches for similar elements using a vector.

Adds an element with a vector to a vector set.

Returns the number of elements in a vector set.

Returns the vector dimensions of a vector set.

Gets the embedding vector of an element.

Gets the JSON attributes of an element.

Returns information about a vector set.

Gets the graph links of an element.

Returns one or more random elements from a vector set.

Removes an element from a vector set.

Sets JSON attributes on an element.

Performs a similarity search on a vector set.

Functions

search(conn, key, vector, opts \\ [])

Searches for similar elements using a vector.

This is a convenience wrapper around vsim/4 that accepts a plain list of floats as the query vector instead of requiring the {:vector, v} tuple.

{:ok, results} = Redis.VectorSet.search(conn, "movies", [0.1, 0.8, 0.3], count: 5)

vadd(conn, key, element, vector, opts \\ [])

Adds an element with a vector to a vector set.

See Redis.Commands.VectorSet.vadd/4 for available options.

vcard(conn, key)

Returns the number of elements in a vector set.

vdim(conn, key)

Returns the vector dimensions of a vector set.

vemb(conn, key, element, opts \\ [])

Gets the embedding vector of an element.

See Redis.Commands.VectorSet.vemb/3 for available options.

vgetattr(conn, key, element)

Gets the JSON attributes of an element.

vinfo(conn, key)

Returns information about a vector set.

vlinks(conn, key, element, opts \\ [])

Gets the graph links of an element.

See Redis.Commands.VectorSet.vlinks/3 for available options.

vrandmember(conn, key, opts \\ [])

Returns one or more random elements from a vector set.

See Redis.Commands.VectorSet.vrandmember/2 for available options.

vrem(conn, key, element)

Removes an element from a vector set.

vsetattr(conn, key, element, json)

Sets JSON attributes on an element.

vsim(conn, key, search_input, opts \\ [])

Performs a similarity search on a vector set.

The search_input is either {:element, name} to search by an existing element, or {:vector, [floats]} to search by a raw vector.

See Redis.Commands.VectorSet.vsim/3 for available options.