Skip to content

Commit 14677d7

Browse files
fix: metric type inconsistency (lancedb#2122)
PR fixes lancedb#2113 --------- Co-authored-by: Will Jones <[email protected]>
1 parent dd22a37 commit 14677d7

File tree

24 files changed

+104
-89
lines changed

24 files changed

+104
-89
lines changed

Cargo.lock

+27-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/openapi.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ paths:
171171
distance_type:
172172
type: string
173173
description: |
174-
The distance metric to use for search. L2, Cosine, Dot and Hamming are supported. Default is L2.
174+
The distance metric to use for search. l2, Cosine, Dot and Hamming are supported. Default is l2.
175175
bypass_vector_index:
176176
type: boolean
177177
description: |
@@ -450,7 +450,7 @@ paths:
450450
type: string
451451
nullable: false
452452
description: |
453-
The metric type to use for the index. L2, Cosine, Dot are supported.
453+
The metric type to use for the index. l2, Cosine, Dot are supported.
454454
index_type:
455455
type: string
456456
responses:

docs/src/ann_indexes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Lance supports `IVF_PQ` index type by default.
6969

7070
The following IVF_PQ paramters can be specified:
7171

72-
- **distance_type**: The distance metric to use. By default it uses euclidean distance "`L2`".
72+
- **distance_type**: The distance metric to use. By default it uses euclidean distance "`l2`".
7373
We also support "cosine" and "dot" distance as well.
7474
- **num_partitions**: The number of partitions in the index. The default is the square root
7575
of the number of rows.

docs/src/concepts/index_hnsw.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Then the greedy search routine operates as follows:
5959

6060
There are three key parameters to set when constructing an HNSW index:
6161

62-
* `metric`: Use an `L2` euclidean distance metric. We also support `dot` and `cosine` distance.
62+
* `metric`: Use an `l2` euclidean distance metric. We also support `dot` and `cosine` distance.
6363
* `m`: The number of neighbors to select for each vector in the HNSW graph.
6464
* `ef_construction`: The number of candidates to evaluate during the construction of the HNSW graph.
6565

docs/src/concepts/index_ivfpq.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ We can combine the above concepts to understand how to build and query an IVF-PQ
4747

4848
There are three key parameters to set when constructing an IVF-PQ index:
4949

50-
* `metric`: Use an `L2` euclidean distance metric. We also support `dot` and `cosine` distance.
50+
* `metric`: Use an `l2` euclidean distance metric. We also support `dot` and `cosine` distance.
5151
* `num_partitions`: The number of partitions in the IVF portion of the index.
5252
* `num_sub_vectors`: The number of sub-vectors that will be created during Product Quantization (PQ).
5353

@@ -56,7 +56,7 @@ In Python, the index can be created as follows:
5656
```python
5757
# Create and train the index for a 1536-dimensional vector
5858
# Make sure you have enough data in the table for an effective training step
59-
tbl.create_index(metric="L2", num_partitions=256, num_sub_vectors=96)
59+
tbl.create_index(metric="l2", num_partitions=256, num_sub_vectors=96)
6060
```
6161
!!! note
6262
`num_partitions`=256 and `num_sub_vectors`=96 does not work for every dataset. Those values needs to be adjusted for your particular dataset.

docs/src/embeddings/understanding_embeddings.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ As mentioned, after creating embedding, each data point is represented as a vect
5454

5555
Points that are close to each other in vector space are considered similar (or appear in similar contexts), and points that are far away are considered dissimilar. To quantify this closeness, we use distance as a metric which can be measured in the following way -
5656

57-
1. **Euclidean Distance (L2)**: It calculates the straight-line distance between two points (vectors) in a multidimensional space.
57+
1. **Euclidean Distance (l2)**: It calculates the straight-line distance between two points (vectors) in a multidimensional space.
5858
2. **Cosine Similarity**: It measures the cosine of the angle between two vectors, providing a normalized measure of similarity based on their direction.
5959
3. **Dot product**: It is calculated as the sum of the products of their corresponding components. To measure relatedness it considers both the magnitude and direction of the vectors.
6060

docs/src/integrations/langchain.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ This method creates a scalar(for non-vector cols) or a vector index on a table.
108108
|:---|:---|:---|:---|
109109
|`vector_col`|`Optional[str]`| Provide if you want to create index on a vector column. |`None`|
110110
|`col_name`|`Optional[str]`| Provide if you want to create index on a non-vector column. |`None`|
111-
|`metric`|`Optional[str]` |Provide the metric to use for vector index. choice of metrics: 'L2', 'dot', 'cosine'. |`L2`|
111+
|`metric`|`Optional[str]` |Provide the metric to use for vector index. choice of metrics: 'l2', 'dot', 'cosine'. |`l2`|
112112
|`num_partitions`|`Optional[int]`|Number of partitions to use for the index.|`256`|
113113
|`num_sub_vectors`|`Optional[int]` |Number of sub-vectors to use for the index.|`96`|
114114
|`index_cache_size`|`Optional[int]` |Size of the index cache.|`None`|

docs/src/integrations/llamaIndex.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ The exhaustive list of parameters for `LanceDBVectorStore` vector store are :
125125
```
126126
- **_table_exists(self, tbl_name: `Optional[str]` = `None`) -> `bool`** : Returns `True` if `tbl_name` exists in database.
127127
- __create_index(
128-
self, scalar: `Optional[bool]` = False, col_name: `Optional[str]` = None, num_partitions: `Optional[int]` = 256, num_sub_vectors: `Optional[int]` = 96, index_cache_size: `Optional[int]` = None, metric: `Optional[str]` = "L2",
128+
self, scalar: `Optional[bool]` = False, col_name: `Optional[str]` = None, num_partitions: `Optional[int]` = 256, num_sub_vectors: `Optional[int]` = 96, index_cache_size: `Optional[int]` = None, metric: `Optional[str]` = "l2",
129129
) -> `None`__ : Creates a scalar(for non-vector cols) or a vector index on a table.
130130
Make sure your vector column has enough data before creating an index on it.
131131

docs/src/javascript/enums/MetricType.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Distance metrics type.
1010

1111
- [Cosine](MetricType.md#cosine)
1212
- [Dot](MetricType.md#dot)
13-
- [L2](MetricType.md#l2)
13+
- [l2](MetricType.md#l2)
1414

1515
## Enumeration Members
1616

docs/src/javascript/interfaces/IvfPQIndexConfig.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ___
8585

8686
`Optional` **metric\_type**: [`MetricType`](../enums/MetricType.md)
8787

88-
Metric type, L2 or Cosine
88+
Metric type, l2 or Cosine
8989

9090
#### Defined in
9191

docs/src/js/interfaces/HnswPqOptions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ The following distance types are available:
2424

2525
"l2" - Euclidean distance. This is a very common distance metric that
2626
accounts for both magnitude and direction when determining the distance
27-
between vectors. L2 distance has a range of [0, ∞).
27+
between vectors. l2 distance has a range of [0, ∞).
2828

2929
"cosine" - Cosine distance. Cosine distance is a distance metric
3030
calculated from the cosine similarity between two vectors. Cosine
3131
similarity is a measure of similarity between two non-zero vectors of an
3232
inner product space. It is defined to equal the cosine of the angle
33-
between them. Unlike L2, the cosine distance is not affected by the
33+
between them. Unlike l2, the cosine distance is not affected by the
3434
magnitude of the vectors. Cosine distance has a range of [0, 2].
3535

3636
"dot" - Dot product. Dot distance is the dot product of two vectors. Dot
3737
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
38-
L2 norm is 1), then dot distance is equivalent to the cosine distance.
38+
l2 norm is 1), then dot distance is equivalent to the cosine distance.
3939

4040
***
4141

docs/src/js/interfaces/HnswSqOptions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ The following distance types are available:
2424

2525
"l2" - Euclidean distance. This is a very common distance metric that
2626
accounts for both magnitude and direction when determining the distance
27-
between vectors. L2 distance has a range of [0, ∞).
27+
between vectors. l2 distance has a range of [0, ∞).
2828

2929
"cosine" - Cosine distance. Cosine distance is a distance metric
3030
calculated from the cosine similarity between two vectors. Cosine
3131
similarity is a measure of similarity between two non-zero vectors of an
3232
inner product space. It is defined to equal the cosine of the angle
33-
between them. Unlike L2, the cosine distance is not affected by the
33+
between them. Unlike l2, the cosine distance is not affected by the
3434
magnitude of the vectors. Cosine distance has a range of [0, 2].
3535

3636
"dot" - Dot product. Dot distance is the dot product of two vectors. Dot
3737
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
38-
L2 norm is 1), then dot distance is equivalent to the cosine distance.
38+
l2 norm is 1), then dot distance is equivalent to the cosine distance.
3939

4040
***
4141

docs/src/js/interfaces/IvfPqOptions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ The following distance types are available:
3131

3232
"l2" - Euclidean distance. This is a very common distance metric that
3333
accounts for both magnitude and direction when determining the distance
34-
between vectors. L2 distance has a range of [0, ∞).
34+
between vectors. l2 distance has a range of [0, ∞).
3535

3636
"cosine" - Cosine distance. Cosine distance is a distance metric
3737
calculated from the cosine similarity between two vectors. Cosine
3838
similarity is a measure of similarity between two non-zero vectors of an
3939
inner product space. It is defined to equal the cosine of the angle
40-
between them. Unlike L2, the cosine distance is not affected by the
40+
between them. Unlike l2, the cosine distance is not affected by the
4141
magnitude of the vectors. Cosine distance has a range of [0, 2].
4242

4343
Note: the cosine distance is undefined when one (or both) of the vectors
@@ -46,7 +46,7 @@ never be returned from a vector search.
4646

4747
"dot" - Dot product. Dot distance is the dot product of two vectors. Dot
4848
distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
49-
L2 norm is 1), then dot distance is equivalent to the cosine distance.
49+
l2 norm is 1), then dot distance is equivalent to the cosine distance.
5050

5151
***
5252

docs/src/search.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Currently, LanceDB supports the following metrics:
1515

1616
| Metric | Description |
1717
| --------- | --------------------------------------------------------------------------- |
18-
| `l2` | [Euclidean / L2 distance](https://en.wikipedia.org/wiki/Euclidean_distance) |
18+
| `l2` | [Euclidean / l2 distance](https://en.wikipedia.org/wiki/Euclidean_distance) |
1919
| `cosine` | [Cosine Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) |
2020
| `dot` | [Dot Production](https://en.wikipedia.org/wiki/Dot_product) |
2121
| `hamming` | [Hamming Distance](https://en.wikipedia.org/wiki/Hamming_distance) |

node/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ export interface IvfPQIndexConfig {
12991299
index_name?: string
13001300

13011301
/**
1302-
* Metric type, L2 or Cosine
1302+
* Metric type, l2 or Cosine
13031303
*/
13041304
metric_type?: MetricType
13051305

nodejs/lancedb/indices.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ export interface IvfPqOptions {
6262
*
6363
* "l2" - Euclidean distance. This is a very common distance metric that
6464
* accounts for both magnitude and direction when determining the distance
65-
* between vectors. L2 distance has a range of [0, ∞).
65+
* between vectors. l2 distance has a range of [0, ∞).
6666
*
6767
* "cosine" - Cosine distance. Cosine distance is a distance metric
6868
* calculated from the cosine similarity between two vectors. Cosine
6969
* similarity is a measure of similarity between two non-zero vectors of an
7070
* inner product space. It is defined to equal the cosine of the angle
71-
* between them. Unlike L2, the cosine distance is not affected by the
71+
* between them. Unlike l2, the cosine distance is not affected by the
7272
* magnitude of the vectors. Cosine distance has a range of [0, 2].
7373
*
7474
* Note: the cosine distance is undefined when one (or both) of the vectors
@@ -77,7 +77,7 @@ export interface IvfPqOptions {
7777
*
7878
* "dot" - Dot product. Dot distance is the dot product of two vectors. Dot
7979
* distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
80-
* L2 norm is 1), then dot distance is equivalent to the cosine distance.
80+
* l2 norm is 1), then dot distance is equivalent to the cosine distance.
8181
*/
8282
distanceType?: "l2" | "cosine" | "dot";
8383

@@ -125,18 +125,18 @@ export interface HnswPqOptions {
125125
*
126126
* "l2" - Euclidean distance. This is a very common distance metric that
127127
* accounts for both magnitude and direction when determining the distance
128-
* between vectors. L2 distance has a range of [0, ∞).
128+
* between vectors. l2 distance has a range of [0, ∞).
129129
*
130130
* "cosine" - Cosine distance. Cosine distance is a distance metric
131131
* calculated from the cosine similarity between two vectors. Cosine
132132
* similarity is a measure of similarity between two non-zero vectors of an
133133
* inner product space. It is defined to equal the cosine of the angle
134-
* between them. Unlike L2, the cosine distance is not affected by the
134+
* between them. Unlike l2, the cosine distance is not affected by the
135135
* magnitude of the vectors. Cosine distance has a range of [0, 2].
136136
*
137137
* "dot" - Dot product. Dot distance is the dot product of two vectors. Dot
138138
* distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
139-
* L2 norm is 1), then dot distance is equivalent to the cosine distance.
139+
* l2 norm is 1), then dot distance is equivalent to the cosine distance.
140140
*/
141141
distanceType?: "l2" | "cosine" | "dot";
142142

@@ -241,18 +241,18 @@ export interface HnswSqOptions {
241241
*
242242
* "l2" - Euclidean distance. This is a very common distance metric that
243243
* accounts for both magnitude and direction when determining the distance
244-
* between vectors. L2 distance has a range of [0, ∞).
244+
* between vectors. l2 distance has a range of [0, ∞).
245245
*
246246
* "cosine" - Cosine distance. Cosine distance is a distance metric
247247
* calculated from the cosine similarity between two vectors. Cosine
248248
* similarity is a measure of similarity between two non-zero vectors of an
249249
* inner product space. It is defined to equal the cosine of the angle
250-
* between them. Unlike L2, the cosine distance is not affected by the
250+
* between them. Unlike l2, the cosine distance is not affected by the
251251
* magnitude of the vectors. Cosine distance has a range of [0, 2].
252252
*
253253
* "dot" - Dot product. Dot distance is the dot product of two vectors. Dot
254254
* distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
255-
* L2 norm is 1), then dot distance is equivalent to the cosine distance.
255+
* l2 norm is 1), then dot distance is equivalent to the cosine distance.
256256
*/
257257
distanceType?: "l2" | "cosine" | "dot";
258258

0 commit comments

Comments
 (0)