-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update doc about vector * update doc about vector * fix
- Loading branch information
Showing
13 changed files
with
224 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
60 changes: 60 additions & 0 deletions
60
docs/MatrixOne/Reference/Functions-and-Operators/Vector/cosine_distance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# COSINE_DISTANCE() | ||
|
||
## Description | ||
|
||
The `COSINE_DISTANCE()` function is used to calculate the cosine distance between two vectors. | ||
|
||
Cosine Distance is a measure of the directional difference between two vectors, typically defined as 1 minus the cosine similarity ([Cosine Similarity](cosine_similarity.md)). The value of cosine distance ranges from 0 to 2. A value of 0 indicates that the directions of the two vectors are exactly the same (minimum distance). A value of 2 indicates that the directions of the two vectors are exactly opposite (maximum distance). In text analysis, cosine distance can be used to measure the similarity between documents. Since it only considers the direction of the vectors and not their magnitude, it is fair for comparisons between long and short texts. | ||
|
||
<div align="center"> | ||
<img src=https://community-shared-data-1308875761.cos.ap-beijing.myqcloud.com/artwork/docs/reference/vector/cosine_distance.png width=50% heigth=50%/> | ||
</div> | ||
|
||
## Syntax | ||
|
||
``` | ||
> SELECT COSINE_DISTANCE(vector1, vector2) FROM tbl; | ||
``` | ||
|
||
## Examples | ||
|
||
```sql | ||
drop table if exists vec_table; | ||
create table vec_table(a int, b vecf32(3), c vecf64(3)); | ||
insert into vec_table values(1, "[1,2,3]", "[4,5,6]"); | ||
mysql> select * from vec_table; | ||
+------+-----------+-----------+ | ||
| a | b | c | | ||
+------+-----------+-----------+ | ||
| 1 | [1, 2, 3] | [4, 5, 6] | | ||
+------+-----------+-----------+ | ||
1 row in set (0.01 sec) | ||
|
||
mysql> select cosine_distance(b,c) from vec_table; | ||
+-----------------------+ | ||
| cosine_distance(b, c) | | ||
+-----------------------+ | ||
| 0.0253681538029239 | | ||
+-----------------------+ | ||
1 row in set (0.00 sec) | ||
|
||
mysql> select cosine_distance(b,"[1,2,3]") from vec_table; | ||
+-----------------------------+ | ||
| cosine_distance(b, [1,2,3]) | | ||
+-----------------------------+ | ||
| 0 | | ||
+-----------------------------+ | ||
1 row in set (0.00 sec) | ||
|
||
mysql> select cosine_distance(b,"[-1,-2,-3]") from vec_table; | ||
+--------------------------------+ | ||
| cosine_distance(b, [-1,-2,-3]) | | ||
+--------------------------------+ | ||
| 2 | | ||
+--------------------------------+ | ||
1 row in set (0.00 sec) | ||
``` | ||
|
||
## Constraints | ||
|
||
When using the `COSINE_DISTANCE()`, input vectors must not be zero vectors, as this would result in a division by zero, which is undefined in mathematics. In practical applications, we generally consider the cosine similarity between a zero vector and any other vector to be zero, because there is no directional similarity between them. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
docs/MatrixOne/Reference/Functions-and-Operators/Vector/l2_distance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# L2_DISTANCE() | ||
|
||
## Description | ||
|
||
The `L2_DISTANCE()` function is used to calculate the Euclidean distance between two vectors. It returns a value of the FLOAT64 type. | ||
|
||
L2 distance, also known as Euclidean distance, is one of the most commonly used methods of measuring distance in vector spaces. It measures the straight-line distance between two points in multidimensional space. L2 distance has many practical applications, including fields such as machine learning, computer vision, and spatial analysis. | ||
|
||
<div align="center"> | ||
<img src=https://community-shared-data-1308875761.cos.ap-beijing.myqcloud.com/artwork/docs/reference/vector/l2_distance.png width=50% heigth=50%/> | ||
</div> | ||
|
||
## Syntax | ||
|
||
``` | ||
> SELECT L2_DISTANCE(vector, const_vector) FROM tbl; | ||
``` | ||
|
||
## Examples | ||
|
||
```sql | ||
drop table if exists vec_table; | ||
create table vec_table(a int, b vecf32(3), c vecf64(3)); | ||
insert into vec_table values(1, "[1,2,3]", "[4,5,6]"),(2, "[1,1,1]", "[2,2,2]"); | ||
mysql> select * from vec_table; | ||
+------+-----------+-----------+ | ||
| a | b | c | | ||
+------+-----------+-----------+ | ||
| 1 | [1, 2, 3] | [4, 5, 6] | | ||
| 2 | [1, 1, 1] | [2, 2, 2] | | ||
+------+-----------+-----------+ | ||
2 rows in set (0.00 sec) | ||
|
||
mysql> select l2_distance(b,c) from vec_table; | ||
+--------------------+ | ||
| l2_distance(b, c) | | ||
+--------------------+ | ||
| 5.196152422706632 | | ||
| 1.7320508075688772 | | ||
+--------------------+ | ||
2 rows in set (0.00 sec) | ||
``` |
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions
40
docs/MatrixOne/Reference/Functions-and-Operators/Vector/normalize_l2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# NORMALIZE_L2() | ||
|
||
## Description | ||
|
||
The`NORMALIZE_L2()` function performs Euclidean normalization (L2 normalization) on a vector. | ||
|
||
The L2 norm is the square root of the sum of the squares of the vector's elements. Therefore, the purpose of L2 normalization is to make the length (or norm) of the vector equal to 1, which is often referred to as a unit vector. This method of normalization is particularly useful in machine learning, especially when dealing with feature vectors. It can help standardize the scale of features, thereby improving the performance of the algorithm. | ||
|
||
<div align="center"> | ||
<img src=https://community-shared-data-1308875761.cos.ap-beijing.myqcloud.com/artwork/docs/reference/vector/normalize_l2.png width=50% heigth=50%/> | ||
</div> | ||
|
||
## Syntax | ||
|
||
``` | ||
> SELECT NORMALIZE_L2(vector_column) FROM tbl; | ||
``` | ||
|
||
## Examples | ||
|
||
```sql | ||
drop table if exists vec_table; | ||
create table vec_table(a int, b vecf32(3), c vecf64(3)); | ||
insert into vec_table values(1, "[1,2,3]", "[4,5,6]"); | ||
mysql> select * from vec_table; | ||
+------+-----------+-----------+ | ||
| a | b | c | | ||
+------+-----------+-----------+ | ||
| 1 | [1, 2, 3] | [4, 5, 6] | | ||
+------+-----------+-----------+ | ||
1 row in set (0.00 sec) | ||
|
||
mysql> select normalize_l2(b) from vec_table; | ||
+-------------------------------------+ | ||
| normalize_l2(b) | | ||
+-------------------------------------+ | ||
| [0.26726124, 0.5345225, 0.80178374] | | ||
+-------------------------------------+ | ||
1 row in set (0.00 sec) | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters