Elffuss BraidHub

kikocis/lancedb public

4a63e77b7e97 · 3.9 KiBRenderedRawPermalink
1[**@lancedb/lancedb**](../README.md) • **Docs**
2
3***
4
5[@lancedb/lancedb](../globals.md) / IvfPqOptions
6
7# Interface: IvfPqOptions
8
9Options to create an `IVF_PQ` index
10
11## Properties
12
13### distanceType?
14
15> `optional` **distanceType**: `"l2"` \| `"cosine"` \| `"dot"`
16
17Distance type to use to build the index.
18
19Default value is "l2".
20
21This is used when training the index to calculate the IVF partitions
22(vectors are grouped in partitions with similar vectors according to this
23distance type) and to calculate a subvector's code during quantization.
24
25The distance type used to train an index MUST match the distance type used
26to search the index. Failure to do so will yield inaccurate results.
27
28The following distance types are available:
29
30"l2" - Euclidean distance. This is a very common distance metric that
31accounts for both magnitude and direction when determining the distance
32between vectors. L2 distance has a range of [0, ∞).
33
34"cosine" - Cosine distance. Cosine distance is a distance metric
35calculated from the cosine similarity between two vectors. Cosine
36similarity is a measure of similarity between two non-zero vectors of an
37inner product space. It is defined to equal the cosine of the angle
38between them. Unlike L2, the cosine distance is not affected by the
39magnitude of the vectors. Cosine distance has a range of [0, 2].
40
41Note: the cosine distance is undefined when one (or both) of the vectors
42are all zeros (there is no direction). These vectors are invalid and may
43never be returned from a vector search.
44
45"dot" - Dot product. Dot distance is the dot product of two vectors. Dot
46distance has a range of (-∞, ∞). If the vectors are normalized (i.e. their
47L2 norm is 1), then dot distance is equivalent to the cosine distance.
48
49***
50
51### maxIterations?
52
53> `optional` **maxIterations**: `number`
54
55Max iteration to train IVF kmeans.
56
57When training an IVF PQ index we use kmeans to calculate the partitions. This parameter
58controls how many iterations of kmeans to run.
59
60Increasing this might improve the quality of the index but in most cases these extra
61iterations have diminishing returns.
62
63The default value is 50.
64
65***
66
67### numPartitions?
68
69> `optional` **numPartitions**: `number`
70
71The number of IVF partitions to create.
72
73This value should generally scale with the number of rows in the dataset.
74By default the number of partitions is the square root of the number of
75rows.
76
77If this value is too large then the first part of the search (picking the
78right partition) will be slow. If this value is too small then the second
79part of the search (searching within a partition) will be slow.
80
81***
82
83### numSubVectors?
84
85> `optional` **numSubVectors**: `number`
86
87Number of sub-vectors of PQ.
88
89This value controls how much the vector is compressed during the quantization step.
90The more sub vectors there are the less the vector is compressed. The default is
91the dimension of the vector divided by 16. If the dimension is not evenly divisible
92by 16 we use the dimension divded by 8.
93
94The above two cases are highly preferred. Having 8 or 16 values per subvector allows
95us to use efficient SIMD instructions.
96
97If the dimension is not visible by 8 then we use 1 subvector. This is not ideal and
98will likely result in poor performance.
99
100***
101
102### sampleRate?
103
104> `optional` **sampleRate**: `number`
105
106The number of vectors, per partition, to sample when training IVF kmeans.
107
108When an IVF PQ index is trained, we need to calculate partitions. These are groups
109of vectors that are similar to each other. To do this we use an algorithm called kmeans.
110
111Running kmeans on a large dataset can be slow. To speed this up we run kmeans on a
112random sample of the data. This parameter controls the size of the sample. The total
113number of vectors used to train the index is `sample_rate * num_partitions`.
114
115Increasing this value might improve the quality of the index but in most cases the
116default should be sufficient.
117
118The default value is 256.