Learn

Getting started with vector sets

Prasan Kumar
Author
Prasan Kumar, Technical Solutions Developer at Redis

Vector sets are a Redis data type similar to sorted sets. However, instead of associating each element with a numerical score, elements in a vector set are associated with a vector—a list of floating-point numbers representing the item in a multi-dimensional space.


This makes vector sets ideal for similarity search tasks such as:

- Retrieving the most similar items to the vector of an existing element already in the set.

- Retrieving the most similar items to a specified vector (e.g., a new embedding not yet in the set).


With these capabilities, vector sets are useful in semantic search, recommendation systems, face recognition, and other applications where vector similarity is important.


A vector set is a collection of elements, each associated with a vector and optional custom attributes.


In above representation:

- Vector set key is `"pg:sts"`

- Element IDs are sentences identified by `"s1"`, `"s2"`, etc., each storing a vector and custom attributes required for future filtering or inspection.

You can add items to a vector set using the VADD command.

Parameters:

- {vectorSetKey} – The name of your vector set.

- {embeddingDimension} – The length of the vector (number of dimensions).

- {embeddingValues...} – The vector values (space-separated floats).

- {elementId} – A unique identifier for this element in the set.

- {elementAttributesAsJSON} – A JSON object containing any metadata about the element, making it easy to filter or inspect later.


The full Semantic Textual Similarity (STS) Development Set used in this tutorial is available here.

Upload that file into Redis Insight:

- Click `Bulk Actions` -> choose `Upload Data` tab -> upload the file and click `Upload`


- Post upload, you can see the status of the upload data


The VSIM command allows you to find elements in a vector set that are most similar to the vector of an existing element in the same set.

This is useful when you already have an element in your dataset and want to find others that are semantically or visually close to it.

Parameters:

- {vectorSetKey} – The name of your vector set.

- ELE {elementId} – The ID of the element whose vector you want to use for similarity search.

- WITHSCORES – Returns the similarity score for each result.

- WITHATTRIBS – Returns the stored attributes (metadata) for each result.


You can experiment with Element similarity queries in the Redis Sandbox:


- Element similarity with scores and count example


- Element similarity with logical filter


The VSIM command can also search for elements similar to a vector you provide directly, instead of using an existing element’s vector.


This is useful when:

- You have a new piece of text, image, or audio not in your dataset.

- You have already generated its vector embeddings using the same model and dimensions used when seeding the vector set.

Where:

- {vectorSetKey} – The name of your vector set.

- VALUES {embeddingDimension} {embeddingValues...} – The embedding vector to compare against.

- WITHSCORES – Returns the similarity score for each result.

- WITHATTRIBS – Returns the stored attributes (metadata) for each result.

- COUNT N (optional) – Limits the number of results returned.


Experiment with Value similarity queries in the Redis Sandbox:


Value similarity with scores and count example


Value similarity with logical filter


Vector sets in Redis support several utility commands that let you inspect, debug, and retrieve metadata, attributes, or structure-related information.


- `VCARD` – Count elements.

- `VDIM` – Get vector dimensions.

- `VEMB` – Get vector for an element.

- `VGETATTR` – Get attributes for an element.

- `VINFO` – Get metadata about the vector set.

- `VISMEMBER` – Check if an element exists.

- `VLINKS` – Get neighbors in the HNSW graph.

- `VRANDMEMBER` – Get random elements.

Experiment with other vector set commands in the Redis sandbox:


You’ve learned how to:

- Add elements to a vector set.

- Run similarity searches using existing or custom vectors.

- Use other utility commands to inspect and explore your data.


Vector sets provide fast, scalable similarity search in Redis — perfect for semantic search, recommendations, and AI-powered retrieval.


Next Steps:

- Try the Redis sandbox links in this guide.

- Import your own data and test queries.- Explore full docs: Vector sets data type