-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go API - [WIP] #212
base: branch-25.02
Are you sure you want to change the base?
Go API - [WIP] #212
Changes from 1 commit
7961798
764dc1e
b0fd0b1
b47cf5b
1ec0c8c
d5c0dc3
cc6319e
01af7c9
ed9bf47
4e79d8e
d278abc
b91721d
6b90861
773fd94
7cbc1f9
46ec2f7
9dcffbd
f82216c
486d40a
6f5c5a6
bfdf3be
de3cea0
57e8dc0
ab173dc
2d5fb95
505d8dc
c3360ee
e261c8a
a4890ed
f2bac2d
a684b01
7d45e24
a7084c2
3af1b73
44d9e58
9447f63
04b6532
a082f67
a84e764
853d538
4021229
6dd2044
3e33692
b1a0476
dddb165
e05782a
a315632
3c97864
bd2dd76
bd76cf8
1e5a756
927f2be
f7fac35
d814e37
2708bc0
e634821
8c9105a
4a80cf7
f5b8e72
7b93510
f738da4
51b5747
ff36031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ type IndexParams struct { | |
params C.cuvsCagraIndexParams_t | ||
} | ||
|
||
// Supplemental parameters to build CAGRA Index | ||
type CompressionParams struct { | ||
params C.cuvsCagraCompressionParams_t | ||
} | ||
|
@@ -31,6 +32,7 @@ var cBuildAlgos = map[BuildAlgo]int{ | |
AutoSelect: C.AUTO_SELECT, | ||
} | ||
|
||
// Creates a new CompressionParams | ||
func CreateCompressionParams() (*CompressionParams, error) { | ||
var params C.cuvsCagraCompressionParams_t | ||
|
||
|
@@ -46,42 +48,54 @@ func CreateCompressionParams() (*CompressionParams, error) { | |
return &CompressionParams{params: params}, nil | ||
} | ||
|
||
// The bit length of the vector element after compression by PQ. | ||
func (p *CompressionParams) SetPQBits(pq_bits uint32) (*CompressionParams, error) { | ||
p.params.pq_bits = C.uint32_t(pq_bits) | ||
|
||
return p, nil | ||
} | ||
|
||
// The dimensionality of the vector after compression by PQ. When zero, | ||
// an optimal value is selected using a heuristic. | ||
func (p *CompressionParams) SetPQDim(pq_dim uint32) (*CompressionParams, error) { | ||
p.params.pq_dim = C.uint32_t(pq_dim) | ||
|
||
return p, nil | ||
} | ||
|
||
// Vector Quantization (VQ) codebook size - number of "coarse cluster | ||
// centers". When zero, an optimal value is selected using a heuristic. | ||
func (p *CompressionParams) SetVQNCenters(vq_n_centers uint32) (*CompressionParams, error) { | ||
p.params.vq_n_centers = C.uint32_t(vq_n_centers) | ||
|
||
return p, nil | ||
} | ||
|
||
// The number of iterations searching for kmeans centers (both VQ & PQ | ||
// phases). | ||
func (p *CompressionParams) SetKMeansNIters(kmeans_n_iters uint32) (*CompressionParams, error) { | ||
p.params.kmeans_n_iters = C.uint32_t(kmeans_n_iters) | ||
|
||
return p, nil | ||
} | ||
|
||
// The fraction of data to use during iterative kmeans building (VQ | ||
// phase). When zero, an optimal value is selected using a heuristic. | ||
func (p *CompressionParams) SetVQKMeansTrainsetFraction(vq_kmeans_trainset_fraction float64) (*CompressionParams, error) { | ||
p.params.vq_kmeans_trainset_fraction = C.double(vq_kmeans_trainset_fraction) | ||
|
||
return p, nil | ||
} | ||
|
||
// The fraction of data to use during iterative kmeans building (PQ | ||
// phase). When zero, an optimal value is selected using a heuristic. | ||
func (p *CompressionParams) SetPQKMeansTrainsetFraction(pq_kmeans_trainset_fraction float64) (*CompressionParams, error) { | ||
p.params.pq_kmeans_trainset_fraction = C.double(pq_kmeans_trainset_fraction) | ||
|
||
return p, nil | ||
} | ||
|
||
// Creates a new IndexParams | ||
func CreateIndexParams() (*IndexParams, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these function names namespaced in some way? For example, will this conflict with an ivfpq There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, I see the |
||
var params C.cuvsCagraIndexParams_t | ||
|
||
|
@@ -95,17 +109,20 @@ func CreateIndexParams() (*IndexParams, error) { | |
return IndexParams, nil | ||
} | ||
|
||
// Degree of input graph for pruning | ||
func (p *IndexParams) SetIntermediateGraphDegree(intermediate_graph_degree uintptr) (*IndexParams, error) { | ||
p.params.intermediate_graph_degree = C.size_t(intermediate_graph_degree) | ||
return p, nil | ||
} | ||
|
||
// Degree of output graph | ||
func (p *IndexParams) SetGraphDegree(intermediate_graph_degree uintptr) (*IndexParams, error) { | ||
p.params.graph_degree = C.size_t(intermediate_graph_degree) | ||
|
||
return p, nil | ||
} | ||
|
||
// ANN algorithm to build knn graph | ||
func (p *IndexParams) SetBuildAlgo(build_algo BuildAlgo) (*IndexParams, error) { | ||
CBuildAlgo, exists := cBuildAlgos[build_algo] | ||
|
||
|
@@ -117,18 +134,21 @@ func (p *IndexParams) SetBuildAlgo(build_algo BuildAlgo) (*IndexParams, error) { | |
return p, nil | ||
} | ||
|
||
// Number of iterations to run if building with NN_DESCENT | ||
func (p *IndexParams) SetNNDescentNiter(nn_descent_niter uint32) (*IndexParams, error) { | ||
p.params.nn_descent_niter = C.ulong(nn_descent_niter) | ||
|
||
return p, nil | ||
} | ||
|
||
// Compression parameters | ||
func (p *IndexParams) SetCompression(compression *CompressionParams) (*IndexParams, error) { | ||
p.params.compression = C.cuvsCagraCompressionParams_t(compression.params) | ||
|
||
return p, nil | ||
} | ||
|
||
// Destroys IndexParams | ||
func (p *IndexParams) Close() error { | ||
err := cuvs.CheckCuvs(cuvs.CuvsError(C.cuvsCagraIndexParamsDestroy(p.params))) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please document all of these functions? Does Go have a common convention or tooling for generating standardized documentation?