Skip to content

Commit e8e60ef

Browse files
Update VECTOR documentation based on review feedback
1 parent b55c13a commit e8e60ef

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

docs/distance-function.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# DISTANCE() Function
22

3-
The `DISTANCE()` function calculates the distance between two `VECTOR` values. Use this function to compare vectors for similarity search and other vector-based operations.
3+
The `DISTANCE()` function computes the distance between two `VECTOR` values to enable similarity searches and other vector-based operations.
44

5-
A vector is an ordered list of numeric values, such as `[1, 2, 3]`. The distance between two vectors is a numeric value that indicates how different the vectors are.
5+
A vector is an ordered list of numeric values, such as `[1, 2, 3]`. The distance between two vectors is a numeric value that indicates how similar the vectors are.
66

77
A distance metric defines how the function calculates this value. Different metrics compare properties such as vector values, direction, or magnitude. In general, a smaller distance indicates greater similarity.
88

@@ -21,7 +21,8 @@ Both functions require exactly three arguments.
2121

2222
`DISTANCE()` accepts the following arguments:
2323

24-
* `vector_a` and `vector_b` specify the vectors to compare. Both arguments must be `VECTOR` values or binary strings that represent float vectors. Other data types cause an error. The vectors must have the same number of dimensions. A dimension mismatch causes an error.
24+
* `vector_a` and `vector_b` specify the vectors to compare. Both arguments must be values of `VECTOR` data type or binary strings that represent float vectors. Other data types cause an error. The vectors must have the same dimension. A dimension mismatch causes an error.
25+
2526
* `metric` specifies the distance metric. Use a constant string or hex literal that resolves to a supported metric. Metric names are case-insensitive. You cannot use a column reference or a computed expression, such as `CONCAT()`, for this argument.
2627

2728
For a binary-string vector, the byte length must be a multiple of 4 because each vector element is a 4-byte single-precision floating-point value. An invalid byte length causes an error.
@@ -70,15 +71,13 @@ The result is a `DOUBLE` value:
7071

7172
??? example "Expected output"
7273

73-
````
74-
```text
75-
+-------------------+
76-
| distance |
77-
+-------------------+
78-
| 5.196152422706632 |
79-
+-------------------+
80-
```
81-
````
74+
```text
75+
+-------------------+
76+
| distance |
77+
+-------------------+
78+
| 5.196152422706632 |
79+
+-------------------+
80+
```
8281

8382
### Use another distance metric
8483

docs/vector.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The VECTOR Type
22

3-
The `VECTOR` data type stores an ordered list of numeric values, called a vector, in a table column. For example, `[0.1, 0.2, 0.3]` represents a vector with three values.
3+
The `VECTOR` data type stores an ordered list of numeric values, called a vector, in a table column. For example, `[0.1, 0.3, 0.2]` represents a vector with three elements.
44

55
Vectors can represent numerical features, such as embeddings used for similarity search and machine learning. Each element in a `VECTOR` value uses a single-precision floating-point number.
66

@@ -10,9 +10,9 @@ Vectors can represent numerical features, such as embeddings used for similarity
1010
VECTOR(N)
1111
```
1212

13-
`N` specifies the number of elements, or dimensions, in the vector. All values stored in the column must have the same number of dimensions.
13+
`N` specifies the dimension of the `VECTOR` column and defines the maximum number of elements that a stored vector can contain.
1414

15-
For example, the following statement creates an `embedding` column that stores three-dimensional vectors:
15+
For example, the following statement creates an `embedding` column with a dimension of three:
1616

1717
```sql
1818
CREATE TABLE documents (
@@ -22,24 +22,26 @@ CREATE TABLE documents (
2222
);
2323
```
2424

25-
A `VECTOR(3)` value contains exactly three elements, such as `[0.1, 0.2, 0.3]`. A vector with two or four elements does not match the column dimension.
25+
A `VECTOR(3)` column can store a vector with up to three elements. For example, it accepts vectors with two or three elements but rejects a vector with four elements.
26+
27+
Using the same number of elements as the declared dimension is strongly recommended.
2628

2729
## Store vector values
2830

2931
Use `TO_VECTOR()` to convert the string representation of a vector to a `VECTOR` value.
3032

31-
The following statement inserts a three-dimensional vector into the `embedding` column:
33+
The following statement inserts a three-element vector into the `embedding` column:
3234

3335
```sql
3436
INSERT INTO documents (id, title, embedding)
3537
VALUES (
3638
1,
3739
'Example document',
38-
TO_VECTOR('[0.1, 0.2, 0.3]')
40+
TO_VECTOR('[0.1, 0.3, 0.2]')
3941
);
4042
```
4143

42-
The number of elements passed to `TO_VECTOR()` must match the dimension of the `VECTOR` column.
44+
The number of elements in the vector must not exceed the dimension specified for the `VECTOR` column.
4345

4446
## Retrieve vector values
4547

@@ -54,19 +56,21 @@ FROM documents;
5456

5557
Vector applications often compare vectors to determine how similar they are. The result of a comparison is a numeric distance between the vectors.
5658

57-
Use `DISTANCE()` to calculate this distance with a supported distance metric. For example:
59+
Use `DISTANCE()` to calculate the distance between two vectors with a supported distance metric. The two vector values passed to `DISTANCE()` must contain the same number of elements. A mismatch causes an error.
60+
61+
For example:
5862

5963
```sql
6064
SELECT DISTANCE(
6165
embedding,
62-
TO_VECTOR('[0.1, 0.2, 0.3]'),
66+
TO_VECTOR('[0.1, 0.3, 0.2]'),
6367
'COSINE'
6468
) AS distance
6569
FROM documents;
6670
```
6771

68-
Different distance metrics compare vectors in different ways. For details about the supported metrics, arguments, and return values, see [DISTANCE() Function](distance-function.md).
72+
Different distance metrics compare vectors in different ways. For details about supported metrics, arguments, and return values, see [DISTANCE() Function](distance-function.md).
6973

7074
## See also
7175

72-
- [DISTANCE() Function](distance-function.md)
76+
* [DISTANCE() Function](distance-function.md)

0 commit comments

Comments
 (0)