Skip to content

Commit af843e0

Browse files
committed
HHH-19705 Carry array length through to allow fixed size vector type expressions for DB2
1 parent c67f9ef commit af843e0

File tree

144 files changed

+2591
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+2591
-403
lines changed

docker_db.sh

Lines changed: 110 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ if command -v docker > /dev/null; then
44
CONTAINER_CLI=$(command -v docker)
55
HEALTCHECK_PATH="{{.State.Health.Status}}"
66
PRIVILEGED_CLI=""
7+
IS_PODMAN=false
8+
if [[ "$(docker version | grep Podman)" == "" ]]; then
9+
IS_DOCKER_RUNTIME=true
10+
else
11+
IS_DOCKER_RUNTIME=false
12+
fi
713
else
814
CONTAINER_CLI=$(command -v podman)
915
HEALTCHECK_PATH="{{.State.Healthcheck.Status}}"
16+
IS_PODMAN=true
17+
IS_DOCKER_RUNTIME=false
1018
# Only use sudo for podman
1119
if command -v sudo > /dev/null; then
1220
PRIVILEGED_CLI="sudo"
@@ -15,6 +23,12 @@ else
1523
fi
1624
fi
1725

26+
if [[ "$(uname -s)" == "Darwin" ]]; then
27+
IS_OSX=true
28+
else
29+
IS_OSX=false
30+
fi
31+
1832
mysql() {
1933
mysql_9_4
2034
}
@@ -286,29 +300,93 @@ db2() {
286300
}
287301

288302
db2_11_5() {
289-
$PRIVILEGED_CLI $CONTAINER_CLI rm -f db2 || true
290-
$PRIVILEGED_CLI $CONTAINER_CLI run --name db2 --privileged -e DB2INSTANCE=orm_test -e DB2INST1_PASSWORD=orm_test -e DBNAME=orm_test -e LICENSE=accept -e AUTOCONFIG=false -e ARCHIVE_LOGS=false -e TO_CREATE_SAMPLEDB=false -e REPODB=false -p 50000:50000 -d ${DB_IMAGE_DB2_11_5:-icr.io/db2_community/db2:11.5.9.0}
303+
CONTAINER_OPTIONS=""
304+
if [[ "$IS_OSX" == "true" ]]; then
305+
# Thanks to Mohamed Asfour https://community.ibm.com/community/user/discussion/db2-luw-115xx-mac-m1-ready#bm017584d2-8d76-42a6-8f76-018dac8e78f2
306+
# This SO post explains what goes wrong on OSX: https://stackoverflow.com/questions/70175677/ibmcom-db2-docker-image-fails-on-m1
307+
# Also, use the $HOME directory as base directory to make volume mounts work on Colima on Mac
308+
db2install=$HOME/db2install.sh
309+
rm -f ${db2install} || true
310+
cat <<'EOF' >${db2install}
311+
#!/bin/bash
312+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - db2inst1 -c '/su - db2inst1 -c '. .profile \&\& /g" {} +
313+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - db2inst1 -c \"/su - db2inst1 -c \". .profile \&\& /g" {} +
314+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${DB2INSTANCE?} -c '/su - \${DB2INSTANCE?} -c '. .profile \&\& /g" {} +
315+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${DB2INSTANCE?} -c \"/su - \${DB2INSTANCE?} -c \". .profile \&\& /g" {} +
316+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance?} -c '/su - \${instance?} -c '. .profile \&\& /g" {} +
317+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance?} -c \"/su - \${instance?} -c \". .profile \&\& /g" {} +
318+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance_name?} -c '/su - \${instance_name?} -c '. .profile \&\& /g" {} +
319+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance_name?} -c \"/su - \${instance_name?} -c \". .profile \&\& /g" {} +
320+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - db2inst1 -c \\\\\"/su - db2inst1 -c \\\". .profile \&\& /g" {} +
321+
. /var/db2_setup/lib/setup_db2_instance.sh
322+
EOF
323+
chmod 777 ${db2install}
324+
if [[ "$IS_PODMAN" == "true" ]]; then
325+
CONTAINER_OPTIONS='--platform=linux/amd64 -e IS_OSXFS=true -v '${db2install}':/db2install.sh --entrypoint=["/bin/bash","-c","/db2install.sh"]'
326+
CONTAINER_ARGS=
327+
else
328+
CONTAINER_OPTIONS='--platform=linux/amd64 -e IS_OSXFS=true -v '${db2install}':/db2install.sh --entrypoint=/bin/bash'
329+
CONTAINER_ARGS=" -c /db2install.sh"
330+
fi
331+
if [[ "$IS_PODMAN" == "false" ]]; then
332+
export DOCKER_DEFAULT_PLATFORM=linux/amd64
333+
fi
334+
fi
335+
$CONTAINER_CLI rm -f db2 || true
336+
$CONTAINER_CLI run --name db2 --privileged -e DB2INSTANCE=orm_test -e DB2INST1_PASSWORD=orm_test -e DBNAME=orm_test -e LICENSE=accept -e AUTOCONFIG=false -e ARCHIVE_LOGS=false -e TO_CREATE_SAMPLEDB=false -e REPODB=false -e BLU=false -e ENABLE_ORACLE_COMPATIBILITY=false -e UPDATEAVAIL=NO -e PERSISTENT_HOME=true -e HADR_ENABLED=false -p 50000:50000 $CONTAINER_OPTIONS -d ${DB_IMAGE_DB2_11_5:-icr.io/db2_community/db2:11.5.9.0} $CONTAINER_ARGS
291337
# Give the container some time to start
292338
OUTPUT=
293339
while [[ $OUTPUT != *"INSTANCE"* ]]; do
294340
echo "Waiting for DB2 to start..."
295341
sleep 10
296-
OUTPUT=$($PRIVILEGED_CLI $CONTAINER_CLI logs db2 2>&1)
342+
OUTPUT=$($CONTAINER_CLI logs db2 2>&1)
297343
done
298-
$PRIVILEGED_CLI $CONTAINER_CLI exec -t db2 su - orm_test bash -c ". /database/config/orm_test/sqllib/db2profile; /database/config/orm_test/sqllib/bin/db2 'connect to orm_test'; /database/config/orm_test/sqllib/bin/db2 'CREATE USER TEMPORARY TABLESPACE usr_tbsp MANAGED BY AUTOMATIC STORAGE'"
344+
$CONTAINER_CLI exec -t db2 su - orm_test bash -c ". /database/config/orm_test/sqllib/db2profile; /database/config/orm_test/sqllib/bin/db2 'connect to orm_test'; /database/config/orm_test/sqllib/bin/db2 'CREATE USER TEMPORARY TABLESPACE usr_tbsp MANAGED BY AUTOMATIC STORAGE'"
299345
}
300346

301347
db2_12_1() {
302-
$PRIVILEGED_CLI $CONTAINER_CLI rm -f db2 || true
303-
$PRIVILEGED_CLI $CONTAINER_CLI run --name db2 --privileged -e DB2INSTANCE=orm_test -e DB2INST1_PASSWORD=orm_test -e DBNAME=orm_test -e LICENSE=accept -e AUTOCONFIG=false -e ARCHIVE_LOGS=false -e TO_CREATE_SAMPLEDB=false -e REPODB=false -p 50000:50000 -d ${DB_IMAGE_DB2_11_5:-icr.io/db2_community/db2:12.1.2.0}
348+
CONTAINER_OPTIONS=""
349+
if [[ "$IS_OSX" == "true" ]]; then
350+
# Thanks to Mohamed Asfour https://community.ibm.com/community/user/discussion/db2-luw-115xx-mac-m1-ready#bm017584d2-8d76-42a6-8f76-018dac8e78f2
351+
# This SO post explains what goes wrong on OSX: https://stackoverflow.com/questions/70175677/ibmcom-db2-docker-image-fails-on-m1
352+
# Also, use the $HOME directory as base directory to make volume mounts work on Colima on Mac
353+
db2install=$HOME/db2install.sh
354+
rm -f ${db2install} || true
355+
cat <<'EOF' >${db2install}
356+
#!/bin/bash
357+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - db2inst1 -c '/su - db2inst1 -c '. .profile \&\& /g" {} +
358+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - db2inst1 -c \"/su - db2inst1 -c \". .profile \&\& /g" {} +
359+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${DB2INSTANCE?} -c '/su - \${DB2INSTANCE?} -c '. .profile \&\& /g" {} +
360+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${DB2INSTANCE?} -c \"/su - \${DB2INSTANCE?} -c \". .profile \&\& /g" {} +
361+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance?} -c '/su - \${instance?} -c '. .profile \&\& /g" {} +
362+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance?} -c \"/su - \${instance?} -c \". .profile \&\& /g" {} +
363+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance_name?} -c '/su - \${instance_name?} -c '. .profile \&\& /g" {} +
364+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - \${instance_name?} -c \"/su - \${instance_name?} -c \". .profile \&\& /g" {} +
365+
find /var/db2_setup -type f -not -path '*/\.*' -exec sed -i "s/su - db2inst1 -c \\\\\"/su - db2inst1 -c \\\". .profile \&\& /g" {} +
366+
. /var/db2_setup/lib/setup_db2_instance.sh
367+
EOF
368+
chmod 777 ${db2install}
369+
if [[ "$IS_PODMAN" == "true" ]]; then
370+
CONTAINER_OPTIONS='--platform=linux/amd64 -e IS_OSXFS=true -v '${db2install}':/db2install.sh --entrypoint=["/bin/bash","-c","/db2install.sh"]'
371+
CONTAINER_ARGS=
372+
else
373+
CONTAINER_OPTIONS='--platform=linux/amd64 -e IS_OSXFS=true -v '${db2install}':/db2install.sh --entrypoint=/bin/bash'
374+
CONTAINER_ARGS=" -c /db2install.sh"
375+
fi
376+
if [[ "$IS_PODMAN" == "false" ]]; then
377+
export DOCKER_DEFAULT_PLATFORM=linux/amd64
378+
fi
379+
fi
380+
$CONTAINER_CLI rm -f db2 || true
381+
$CONTAINER_CLI run --name db2 --privileged -e DB2INSTANCE=orm_test -e DB2INST1_PASSWORD=orm_test -e DBNAME=orm_test -e LICENSE=accept -e AUTOCONFIG=false -e ARCHIVE_LOGS=false -e TO_CREATE_SAMPLEDB=false -e REPODB=false -e BLU=false -e ENABLE_ORACLE_COMPATIBILITY=false -e UPDATEAVAIL=NO -e PERSISTENT_HOME=true -e HADR_ENABLED=false -p 50000:50000 $CONTAINER_OPTIONS -d ${DB_IMAGE_DB2_12_1:-icr.io/db2_community/db2:12.1.2.0} $CONTAINER_ARGS
304382
# Give the container some time to start
305383
OUTPUT=
306384
while [[ $OUTPUT != *"INSTANCE"* ]]; do
307385
echo "Waiting for DB2 to start..."
308386
sleep 10
309-
OUTPUT=$($PRIVILEGED_CLI $CONTAINER_CLI logs db2 2>&1)
387+
OUTPUT=$($CONTAINER_CLI logs db2 2>&1)
310388
done
311-
$PRIVILEGED_CLI $CONTAINER_CLI exec -t db2 su - orm_test bash -c ". /database/config/orm_test/sqllib/db2profile; /database/config/orm_test/sqllib/bin/db2 'connect to orm_test'; /database/config/orm_test/sqllib/bin/db2 'CREATE USER TEMPORARY TABLESPACE usr_tbsp MANAGED BY AUTOMATIC STORAGE'"
389+
$CONTAINER_CLI exec -t db2 su - orm_test bash -c ". /database/config/orm_test/sqllib/db2profile; /database/config/orm_test/sqllib/bin/db2 'connect to orm_test'; /database/config/orm_test/sqllib/bin/db2 'CREATE USER TEMPORARY TABLESPACE usr_tbsp MANAGED BY AUTOMATIC STORAGE'"
312390
}
313391

314392
db2_spatial() {
@@ -726,28 +804,30 @@ EOF\""
726804
}
727805

728806
disable_userland_proxy() {
729-
if [[ "$HEALTCHECK_PATH" == "{{.State.Health.Status}}" ]]; then
730-
if [[ ! -f /etc/docker/daemon.json ]]; then
731-
echo "Didn't find /etc/docker/daemon.json but need to disable userland-proxy..."
732-
echo "Stopping docker..."
733-
sudo service docker stop
734-
echo "Creating /etc/docker/daemon.json..."
735-
sudo bash -c "echo '{\"userland-proxy\": false}' > /etc/docker/daemon.json"
736-
echo "Starting docker..."
737-
sudo service docker start
738-
echo "Docker successfully started with userland proxies disabled"
739-
elif ! grep -q userland-proxy /etc/docker/daemon.json; then
740-
echo "Userland proxy is still enabled in /etc/docker/daemon.json, but need to disable it..."
741-
export docker_daemon_json=$(</etc/docker/daemon.json)
742-
echo "Stopping docker..."
743-
sudo service docker stop
744-
echo "Updating /etc/docker/daemon.json..."
745-
sudo bash -c "export docker_daemon_json='$docker_daemon_json'; echo \"\${docker_daemon_json/\}/,}\\\"userland-proxy\\\": false}\" > /etc/docker/daemon.json"
746-
echo "Starting docker..."
747-
sudo service docker start
748-
echo "Service status:"
749-
sudo journalctl -xeu docker.service
750-
echo "Docker successfully started with userland proxies disabled"
807+
if [[ "$IS_DOCKER_RUNTIME" == "true" ]]; then
808+
if [[ "$HEALTCHECK_PATH" == "{{.State.Health.Status}}" ]]; then
809+
if [[ ! -f /etc/docker/daemon.json ]]; then
810+
echo "Didn't find /etc/docker/daemon.json but need to disable userland-proxy..."
811+
echo "Stopping docker..."
812+
sudo service docker stop
813+
echo "Creating /etc/docker/daemon.json..."
814+
sudo bash -c "echo '{\"userland-proxy\": false}' > /etc/docker/daemon.json"
815+
echo "Starting docker..."
816+
sudo service docker start
817+
echo "Docker successfully started with userland proxies disabled"
818+
elif ! grep -q userland-proxy /etc/docker/daemon.json; then
819+
echo "Userland proxy is still enabled in /etc/docker/daemon.json, but need to disable it..."
820+
export docker_daemon_json=$(</etc/docker/daemon.json)
821+
echo "Stopping docker..."
822+
sudo service docker stop
823+
echo "Updating /etc/docker/daemon.json..."
824+
sudo bash -c "export docker_daemon_json='$docker_daemon_json'; echo \"\${docker_daemon_json/\}/,}\\\"userland-proxy\\\": false}\" > /etc/docker/daemon.json"
825+
echo "Starting docker..."
826+
sudo service docker start
827+
echo "Service status:"
828+
sudo journalctl -xeu docker.service
829+
echo "Docker successfully started with userland proxies disabled"
830+
fi
751831
fi
752832
fi
753833
}

documentation/src/main/asciidoc/userguide/chapters/query/extensions/Vector.adoc

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,25 @@ so no further configuration is necessary to make the features available.
5353
[[vector-module-usage]]
5454
==== Usage
5555

56-
Annotate a persistent attribute with `@JdbcTypeCode(SqlTypes.VECTOR)` and specify the vector length with `@Array(length = ...)`.
56+
Annotate a persistent attribute with one of the various vector type codes `@JdbcTypeCode` and specify the vector length with `@Array(length = ...)`.
57+
Possible vector type codes and the compatible Java types are:
58+
59+
* `@JdbcTypeCode(SqlTypes.VECTOR_BINARY)` for `byte[]`
60+
* `@JdbcTypeCode(SqlTypes.VECTOR_INT8)` for `byte[]`
61+
* `@JdbcTypeCode(SqlTypes.VECTOR_FLOAT16)` for `float[]`
62+
* `@JdbcTypeCode(SqlTypes.VECTOR_FLOAT32)` for `float[]`
63+
* `@JdbcTypeCode(SqlTypes.VECTOR_FLOAT64)` for `double[]`
64+
* `@JdbcTypeCode(SqlTypes.VECTOR)` for `float[]`
65+
66+
Hibernate ORM also provides support for sparse vectors through dedicated Java types:
67+
68+
* `@JdbcTypeCode(SqlTypes.SPARSE_VECTOR_INT8)` for `SparseByteVector`
69+
* `@JdbcTypeCode(SqlTypes.SPARSE_VECTOR_FLOAT32)` for `SparseFloatVector`
70+
* `@JdbcTypeCode(SqlTypes.SPARSE_VECTOR_FLOAT64)` for `SparseDoubleVector`
5771

5872
[WARNING]
5973
====
60-
As Oracle AI Vector Search supports different types of elements (to ensure better performance and compatibility with embedding models), you can also use:
61-
62-
- `@JdbcTypeCode(SqlTypes.VECTOR_INT8)` for `byte[]`
63-
- `@JdbcTypeCode(SqlTypes.VECTOR_FLOAT32)` for `float[]`
64-
- `@JdbcTypeCode(SqlTypes.VECTOR_FLOAT64)` for `double[]`.
74+
Vector data type support depends on native support of the underlying database.
6575
====
6676

6777
[[vector-module-usage-example]]
@@ -88,14 +98,21 @@ Expressions of the vector type can be used with various vector functions.
8898
| `euclidean_distance()` | Computes the https://en.wikipedia.org/wiki/Euclidean_distance[euclidean distance] between two vectors. Maps to the `<``-``>` operator for `pgvector` and maps to the
8999
`vector_distance(v1, v2, EUCLIDEAN)` function for `Oracle AI Vector Search`.
90100

101+
| `euclidean_squared_distance()` | Computes the https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance[squared euclidean distance] between two vectors.
102+
91103
| `l2_distance()` | Alias for `euclidean_distance()`
92104

105+
| `l2_squared_distance()` | Alias for `euclidean_squared_distance()`
106+
93107
| `taxicab_distance()` | Computes the https://en.wikipedia.org/wiki/Taxicab_geometry[taxicab distance] between two vectors. Maps to `vector_distance(v1, v2, MANHATTAN)` function for `Oracle AI Vector Search`.
94108

95109
| `l1_distance()` | Alias for `taxicab_distance()`
96110

97111
| `hamming_distance()` | Computes the https://en.wikipedia.org/wiki/Hamming_distance[hamming distance] between two vectors. Maps to `vector_distance(v1, v2, HAMMING)` function for `Oracle AI Vector Search`.
98112

113+
| `jaccard_distance()` | Computes the https://en.wikipedia.org/wiki/Jaccard_index[jaccard distance] between two vectors. Maps to the `<``%``>` operator for `pgvector` and maps to the
114+
`vector_distance(v1, v2, JACCARD)` function for `Oracle AI Vector Search`.
115+
99116
| `inner_product()` | Computes the https://en.wikipedia.org/wiki/Inner_product_space[inner product] between two vectors
100117

101118
| `negative_inner_product()` | Computes the negative inner product. Maps to the `<``#``>` operator for `pgvector` and maps to the
@@ -104,6 +121,14 @@ Expressions of the vector type can be used with various vector functions.
104121
| `vector_dims()` | Determines the dimensions of a vector
105122

106123
| `vector_norm()` | Computes the https://en.wikipedia.org/wiki/Euclidean_space#Euclidean_norm[Euclidean norm] of a vector
124+
125+
| `l2_norm()` | Alias for `vector_norm()`
126+
127+
| `l2_normalize()` | Normalizes each component of a vector by dividing it with the https://en.wikipedia.org/wiki/Euclidean_space#Euclidean_norm[Euclidean norm] of the vector.
128+
129+
| `binary_quantize()` | Reduces a vector of size N to a binary vector with N bits, using 0 for values <= 0 and 1 for values > 0.
130+
131+
| `subvector()` | Creates a subvector from a given vector, a 1-based start index and a count.
107132
|===
108133

109134
In addition to these special vector functions, it is also possible to use vectors with the following builtin `pgvector` operators:
@@ -143,6 +168,21 @@ include::{example-dir-vector}/FloatVectorTest.java[tags=euclidean-distance-examp
143168
----
144169
====
145170

171+
[[vector-module-functions-euclidean-squared-distance]]
172+
===== `euclidean_squared_distance()` and `l2_squared_distance()`
173+
174+
Computes the https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance[squared euclidean distance] between two vectors,
175+
which is `sum( (v1_i - v2_i)^2 )`, just like the regular `euclidean_distance`, but without the `sqrt`.
176+
The `l2_squared_distance()` function is an alias.
177+
178+
[[vector-module-functions-euclidean-squared-distance-example]]
179+
====
180+
[source, java, indent=0]
181+
----
182+
include::{example-dir-vector}/FloatVectorTest.java[tags=euclidean-squared-distance-example]
183+
----
184+
====
185+
146186
[[vector-module-functions-taxicab-distance]]
147187
===== `taxicab_distance()` and `l1_distance()`
148188

@@ -158,6 +198,36 @@ include::{example-dir-vector}/FloatVectorTest.java[tags=taxicab-distance-example
158198
----
159199
====
160200

201+
[[vector-module-functions-hamming-distance]]
202+
===== `hamming_distance()`
203+
204+
Computes the https://en.wikipedia.org/wiki/Hamming_distance[hamming distance] between two binary vectors,
205+
which is `bit_count(v1 ^ v2)` i.e. the amount of bits where two vectors differ.
206+
Maps to the `<``~``>` operator for `pgvector`.
207+
208+
[[vector-module-functions-taxicab-distance-example]]
209+
====
210+
[source, java, indent=0]
211+
----
212+
include::{example-dir-vector}/BinaryVectorTest.java[tags=hamming-distance-example]
213+
----
214+
====
215+
216+
[[vector-module-functions-jaccard-distance]]
217+
===== `jaccard_distance()`
218+
219+
Computes the https://en.wikipedia.org/wiki/Jaccard_index[jaccard distance] between two binary vectors,
220+
which is `1 - bit_count(v1 & v2) / bit_count(v1 | v2)`.
221+
Maps to the `<``%``>` operator for `pgvector`.
222+
223+
[[vector-module-functions-taxicab-distance-example]]
224+
====
225+
[source, java, indent=0]
226+
----
227+
include::{example-dir-vector}/BinaryVectorTest.java[tags=jaccard-distance-example]
228+
----
229+
====
230+
161231
[[vector-module-functions-inner-product]]
162232
===== `inner_product()` and `negative_inner_product()`
163233

@@ -187,10 +257,11 @@ include::{example-dir-vector}/FloatVectorTest.java[tags=vector-dims-example]
187257
====
188258

189259
[[vector-module-functions-vector-norm]]
190-
===== `vector_norm()`
260+
===== `vector_norm()` and `l2_norm()`
191261

192262
Computes the https://en.wikipedia.org/wiki/Euclidean_space#Euclidean_norm[Euclidean norm] of a vector,
193263
which is `sqrt( sum( v_i^2 ) )`.
264+
The `l2_norm()` function is an alias.
194265

195266
[[vector-module-functions-vector-norm-example]]
196267
====
@@ -200,6 +271,44 @@ include::{example-dir-vector}/FloatVectorTest.java[tags=vector-norm-example]
200271
----
201272
====
202273

274+
[[vector-module-functions-l2-normalize]]
275+
===== `l2_normalize()`
276+
277+
Normalizes each component of a vector by dividing it with the https://en.wikipedia.org/wiki/Euclidean_space#Euclidean_norm[Euclidean norm] of the vector.
278+
279+
[[vector-module-functions-l2-normalize-example]]
280+
====
281+
[source, java, indent=0]
282+
----
283+
include::{example-dir-vector}/FloatVectorTest.java[tags=l2-normalize-example]
284+
----
285+
====
286+
287+
[[vector-module-functions-binary-quantize]]
288+
===== `binary_quantize()`
289+
290+
Reduces a vector of size N to a binary vector with N bits, using 0 for values <= 0 and 1 for values > 0.
291+
292+
[[vector-module-functions-binary-quantize-example]]
293+
====
294+
[source, java, indent=0]
295+
----
296+
include::{example-dir-vector}/FloatVectorTest.java[tags=binary-quantize-example]
297+
----
298+
====
299+
300+
[[vector-module-functions-subvector]]
301+
===== `binary_quantize()`
302+
303+
Creates a subvector from a given vector, a 1-based start index and a count.
304+
305+
[[vector-module-functions-subvector-example]]
306+
====
307+
[source, java, indent=0]
308+
----
309+
include::{example-dir-vector}/FloatVectorTest.java[tags=subvector-example]
310+
----
311+
====
203312

204313

205314

0 commit comments

Comments
 (0)