Skip to content

Commit a411092

Browse files
Merge pull request #1402 from redis/DOC-5073-py-vec-quant-example
DOC-5073 added quantization and reduction examples
2 parents ec837a5 + 29ad2dd commit a411092

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

content/develop/data-types/vector-sets/memory.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,19 @@ High-dimensional vectors increase storage:
6464
- 300 components at `FP32` = 1200 bytes/vector
6565
- 300 components at `Q8` = 300 bytes/vector
6666

67-
You can reduce this using the `REDUCE` option during [`VADD`]({{< relref "/commands/vadd" >}}), which applies random projection.
68-
69-
```bash
70-
VADD vset REDUCE 100 VALUES 300 ... item1
71-
```
67+
You can reduce this using the `REDUCE` option during [`VADD`]({{< relref "/commands/vadd" >}}), which applies [random projection](https://en.wikipedia.org/wiki/Random_projection):
68+
69+
{{< clients-example vecset_tutorial add_reduce >}}
70+
>VADD setNotReduced VALUES 300 ... element
71+
(integer) 1
72+
> VDIM setNotReduced
73+
(integer) 300
74+
75+
>VADD setReduced REDUCE 100 VALUES 300 ... element
76+
(integer) 1
77+
> VDIM setReduced
78+
(integer) 100
79+
{{< /clients-example >}}
7280

7381
This projects a 300-dimensional vector into 100 dimensions, reducing size and improving speed at the cost of some recall.
7482

content/develop/data-types/vector-sets/performance.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ Quantization greatly impacts both speed and memory:
4141
- `NOQUANT` (`FP32`): Full precision, slower performance, highest memory use
4242

4343
Use the quantization mode that best fits your tradeoff between precision and efficiency.
44+
The examples below show how the different modes affect a simple vector.
45+
Note that even with `NOQUANT` mode, the values change slightly,
46+
due to floating point rounding.
47+
48+
{{< clients-example vecset_tutorial add_quant >}}
49+
> VADD quantSetQ8 VALUES 2 1.262185 1.958231 quantElement Q8
50+
(integer) 1
51+
> VEMB quantSetQ8 quantElement
52+
1) "1.2643694877624512"
53+
2) "1.958230972290039"
54+
55+
> VADD quantSetNoQ VALUES 2 1.262185 1.958231 quantElement NOQUANT
56+
(integer) 1
57+
> VEMB quantSetNoQ quantElement
58+
1) "1.262184977531433"
59+
2) "1.958230972290039"
60+
61+
> VADD quantSetBin VALUES 2 1.262185 1.958231 quantElement BIN
62+
(integer) 1
63+
> VEMB quantSetBin quantElement
64+
1) "1"
65+
2) "1"
66+
{{< /clients-example >}}
4467

4568
## Deletion performance
4669

0 commit comments

Comments
 (0)