faiss_ParameterSpace_set_index_parameters usage
guskovd opened this issue · comments
I want to change the parameter "nprobe" in the index.
According to https://github.com/facebookresearch/faiss/wiki/FAQ you need to use the set_index_parameter function (I found faiss_ParameterSpace_set_index_parameters)
But I do not understand how to create an instance of FaissParameterSpace and how to work with it
I'm afraid that the high-level bindings do not expose setting index parameters once the index was already constructed. I have managed to make do without this, apparently.
In the low-level API, the constructor function to the parameter space object is faiss_ParameterSpace_new
.
FaissParameterSpace* params = NULL;
int err = faiss_ParameterSpace_new(¶ms);
Nevertheless, if you'd like to try and extend the safe API with parameter space setting, please let me know, so I can then provide better guidance.
I seem to have succeeded
let param = "nprobe".to_string();
let mut param_vec: Vec<*mut faiss_sys::FaissParameterSpace> = vec![std::ptr::null::<*mut faiss_sys::FaissParameterSpace>() as *mut _];
faiss_sys::faiss_ParameterSpace_new(param_vec.as_mut_ptr());
faiss_sys::faiss_ParameterSpace_set_index_parameter(*param_vec.as_mut_ptr(), self.inner_ptr(), param.as_ptr() as *const _, 2.0 );
let nprobe = faiss_sys::faiss_IndexIVF_nprobe(self.inner_ptr());
println!("{:?}", nprobe);
2
Good to know! I'll leave this open in the event that we or someone else would be interested in making it part of the high level API.
Why is faiss_ParameterSpace_new required *mut *mut
?
https://github.com/Enet4/faiss-rs/blob/master/faiss-sys/src/bindings.rs#L263
@ava57r The function
extern "C" {
pub fn faiss_ParameterSpace_new(space: *mut *mut FaissParameterSpace) -> ::std::os::raw::c_int;
Is the translation of the C function
int faiss_ParameterSpace_new(ParameterSpace** p_space);
Where to *p_space
is assigned the output of constructing a ParameterSpace
object via new
. Using it would be something like this:
let mut p_space = std::ptr::null_mut();
let e = faiss_ParameterSpace_new(&mut p_space);
faiss_ParameterSpace_free
function exists only versions >= 1.6.4
This seems to have been resolved by #14.