Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions content/develop/data-types/vector-sets/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Start by adding the point vectors to a set called `points` using
The [`TYPE`]({{< relref "/commands/type" >}}) command returns a type of `vectorset`
for this object.

```
{{< clients-example vecset_tutorial vadd >}}
> VADD points VALUES 2 1.0 1.0 pt:A
(integer) 1
> VADD points VALUES 2 -1.0 -1.0 pt:B
Expand All @@ -73,26 +73,27 @@ for this object.
(integer) 1
> TYPE points
vectorset
```
{{< /clients-example >}}


Get the number of elements in the set (also known as the *cardinality* of the set)
using [`VCARD`]({{< relref "/commands/vcard" >}}) and the number of dimensions of
the vectors using [`VDIM`]({{< relref "/commands/vdim" >}}):

```
{{< clients-example vecset_tutorial vcardvdim >}}
> VCARD points
(integer) 5
> VDIM points
(integer) 2
```
{{< /clients-example >}}

Get the coordinate values from the elements using [`VEMB`]({{< relref "/commands/vemb" >}}).
Note that the values will not typically be the exact values you supplied when you added
the vector because
[quantization]({{< relref "/develop/data-types/vector-sets/performance#quantization-effects" >}})
is applied to improve performance.

```
{{< clients-example vecset_tutorial vemb >}}
> VEMB points pt:A
1) "0.9999999403953552"
2) "0.9999999403953552"
Expand All @@ -108,14 +109,14 @@ is applied to improve performance.
> VEMB points pt:E
1) "1"
2) "0"
```
{{< /clients-example >}}

Set and retrieve an element's JSON attribute data using
[`VSETATTR`]({{< relref "/commands/vsetattr" >}})
and [`VGETATTR`]({{< relref "/commands/vgetattr" >}}). You can also pass an empty string
to `VSETATTR` to delete the attribute data:

```
{{< clients-example vecset_tutorial attr >}}
> VSETATTR points pt:A "{\"name\": \"Point A\", \"description\": \"First point added\"}"
(integer) 1
> VGETATTR points pt:A
Expand All @@ -124,11 +125,11 @@ to `VSETATTR` to delete the attribute data:
(integer) 1
> VGETATTR points pt:A
(nil)
```
{{< /clients-example >}}

Remove an unwanted element with [`VREM`]({{< relref "/commands/vrem" >}})

```
{{< clients-example vecset_tutorial vrem >}}
> VADD points VALUES 2 0 0 pt:F
(integer) 1
127.0.0.1:6379> VCARD points
Expand All @@ -137,24 +138,24 @@ Remove an unwanted element with [`VREM`]({{< relref "/commands/vrem" >}})
(integer) 1
127.0.0.1:6379> VCARD points
(integer) 5
```
{{< /clients-example >}}

### Vector similarity search

Use [`VSIM`]({{< relref "/commands/vsim" >}}) to rank the points in order of their vector distance from a sample point:

```
{{< clients-example vecset_tutorial vsim_basic >}}
> VSIM points values 2 0.9 0.1
1) "pt:E"
2) "pt:A"
3) "pt:D"
4) "pt:C"
5) "pt:B"
```
{{< /clients-example >}}

Find the four elements that are closest to point A and show their distance "scores":

```
{{< clients-example vecset_tutorial vsim_options >}}
> VSIM points ELE pt:A WITHSCORES COUNT 4
1) "pt:A"
2) "1"
Expand All @@ -164,13 +165,13 @@ Find the four elements that are closest to point A and show their distance "scor
6) "0.5"
7) "pt:D"
8) "0.5"
```
{{< /clients-example >}}

Add some JSON attributes and use
[filter expressions]({{< relref "/develop/data-types/vector-sets/filtered-search" >}})
to include them in the search:

```
{{< clients-example vecset_tutorial vsim_filter >}}
> VSETATTR points pt:A "{\"size\":\"large\",\"price\": 18.99}"
(integer) 1
> VSETATTR points pt:B "{\"size\":\"large\",\"price\": 35.99}"
Expand All @@ -194,7 +195,7 @@ to include them in the search:
> VSIM points ELE pt:A FILTER '.size == "large" && .price > 20.00'
1) "pt:C"
2) "pt:B"
```
{{< /clients-example >}}

## More information

Expand Down