parse values properly

main
Ziyang Hu 1 year ago
parent 4c3fb1fdde
commit fdb5e0fddc

@ -194,7 +194,7 @@ pub(crate) fn parse_sys(
let mut vec_fields = vec![]; let mut vec_fields = vec![];
let mut distance = HnswDistance::L2; let mut distance = HnswDistance::L2;
let mut ef_construction = 0; let mut ef_construction = 0;
let mut max_elements = 0; let mut m_neighbours = 0;
let mut index_filter = None; let mut index_filter = None;
let mut extend_candidates = false; let mut extend_candidates = false;
let mut keep_pruned_connections = false; let mut keep_pruned_connections = false;
@ -203,13 +203,33 @@ pub(crate) fn parse_sys(
let mut opt_inner = opt_pair.into_inner(); let mut opt_inner = opt_pair.into_inner();
let opt_name = opt_inner.next().unwrap(); let opt_name = opt_inner.next().unwrap();
let opt_val = opt_inner.next().unwrap(); let opt_val = opt_inner.next().unwrap();
let opt_val_str = opt_val.as_str();
match opt_name.as_str() { match opt_name.as_str() {
"dim" => { "dim" => {
vec_dim = opt_val let v = build_expr(opt_val, param_pool)?
.as_str() .eval_to_const()?
.trim() .get_int()
.parse() .ok_or_else(|| miette!("Invalid vec_dim: {}", opt_val_str))?;
.map_err(|e| miette!("Invalid vec_dim: {}", e))?; ensure!(v > 0, "Invalid vec_dim: {}", v);
vec_dim = v as usize;
}
"ef_construction" | "ef" => {
let v = build_expr(opt_val, param_pool)?
.eval_to_const()?
.get_int()
.ok_or_else(|| {
miette!("Invalid ef_construction: {}", opt_val_str)
})?;
ensure!(v > 0, "Invalid ef_construction: {}", v);
ef_construction = v as usize;
}
"m_neighbours" | "m" => {
let v = build_expr(opt_val, param_pool)?
.eval_to_const()?
.get_int()
.ok_or_else(|| miette!("Invalid m_neighbours: {}", opt_val_str))?;
ensure!(v > 0, "Invalid m_neighbours: {}", v);
m_neighbours = v as usize;
} }
"dtype" => { "dtype" => {
dtype = match opt_val.as_str() { dtype = match opt_val.as_str() {
@ -237,20 +257,6 @@ pub(crate) fn parse_sys(
} }
} }
} }
"ef_construction" | "ef" => {
ef_construction = opt_val
.as_str()
.trim()
.parse()
.map_err(|e| miette!("Invalid ef_construction: {}", e))?;
}
"m_neighbours" | "m" | "M" => {
max_elements = opt_val
.as_str()
.trim()
.parse()
.map_err(|e| miette!("Invalid max_elements: {}", e))?;
}
"filter" => { "filter" => {
index_filter = Some(opt_val.as_str().to_string()); index_filter = Some(opt_val.as_str().to_string());
} }
@ -266,7 +272,7 @@ pub(crate) fn parse_sys(
if ef_construction == 0 { if ef_construction == 0 {
bail!("ef_construction must be set"); bail!("ef_construction must be set");
} }
if max_elements == 0 { if m_neighbours == 0 {
bail!("m_neighbours must be set"); bail!("m_neighbours must be set");
} }
SysOp::CreateVectorIndex(HnswIndexConfig { SysOp::CreateVectorIndex(HnswIndexConfig {
@ -277,7 +283,7 @@ pub(crate) fn parse_sys(
vec_fields, vec_fields,
distance, distance,
ef_construction, ef_construction,
m_neighbours: max_elements, m_neighbours,
index_filter, index_filter,
extend_candidates, extend_candidates,
keep_pruned_connections, keep_pruned_connections,

Loading…
Cancel
Save