mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-15 04:20:39 +00:00
feat: impl vector index query (#7564)
* feat: impl vector index query Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat: remove VectorSearchRule and merge it into scan hint rule Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor: vector search hint Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: join and subquery Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix: clippy when feature disabled Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix: push hint only when column is non-nullable or an explicit IS NOT NULL filter exists Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix: transformed = true Co-authored-by: Yingwen <realevenyag@gmail.com> Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * chore: remove adpater vector hint Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * chore: revert transformed Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> Co-authored-by: Yingwen <realevenyag@gmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
mod convert;
|
||||
mod distance;
|
||||
pub mod distance;
|
||||
mod elem_avg;
|
||||
mod elem_product;
|
||||
mod elem_sum;
|
||||
@@ -33,6 +33,7 @@ use std::borrow::Cow;
|
||||
|
||||
use datafusion_common::{DataFusionError, Result, ScalarValue, utils};
|
||||
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs};
|
||||
use datatypes::arrow::array::new_empty_array;
|
||||
|
||||
use crate::function_registry::FunctionRegistry;
|
||||
use crate::scalars::vector::impl_conv::as_veclit;
|
||||
@@ -128,6 +129,11 @@ where
|
||||
}
|
||||
|
||||
let len = ensure_same_length(&[arg0, arg1])?;
|
||||
if len == 0 {
|
||||
return Ok(ColumnarValue::Array(new_empty_array(
|
||||
args.return_field.data_type(),
|
||||
)));
|
||||
}
|
||||
let mut results = Vec::with_capacity(len);
|
||||
for i in 0..len {
|
||||
let v0 = try_get_scalar_value!(arg0, i);
|
||||
@@ -155,6 +161,11 @@ where
|
||||
}
|
||||
|
||||
let len = ensure_same_length(&[arg0, arg1])?;
|
||||
if len == 0 {
|
||||
return Ok(ColumnarValue::Array(new_empty_array(
|
||||
args.return_field.data_type(),
|
||||
)));
|
||||
}
|
||||
let mut results = Vec::with_capacity(len);
|
||||
|
||||
match (arg0, arg1) {
|
||||
@@ -210,6 +221,11 @@ where
|
||||
};
|
||||
|
||||
let len = arg0.len();
|
||||
if len == 0 {
|
||||
return Ok(ColumnarValue::Array(new_empty_array(
|
||||
args.return_field.data_type(),
|
||||
)));
|
||||
}
|
||||
let mut results = Vec::with_capacity(len);
|
||||
for i in 0..len {
|
||||
let v = ScalarValue::try_from_array(arg0, i)?;
|
||||
|
||||
@@ -16,6 +16,10 @@ mod cos;
|
||||
mod dot;
|
||||
mod l2sq;
|
||||
|
||||
pub const VEC_COS_DISTANCE: &str = "vec_cos_distance";
|
||||
pub const VEC_L2SQ_DISTANCE: &str = "vec_l2sq_distance";
|
||||
pub const VEC_DOT_PRODUCT: &str = "vec_dot_product";
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Display;
|
||||
|
||||
@@ -109,9 +113,9 @@ macro_rules! define_distance_function {
|
||||
};
|
||||
}
|
||||
|
||||
define_distance_function!(CosDistanceFunction, "vec_cos_distance", cos::cos);
|
||||
define_distance_function!(L2SqDistanceFunction, "vec_l2sq_distance", l2sq::l2sq);
|
||||
define_distance_function!(DotProductFunction, "vec_dot_product", dot::dot);
|
||||
define_distance_function!(CosDistanceFunction, VEC_COS_DISTANCE, cos::cos);
|
||||
define_distance_function!(L2SqDistanceFunction, VEC_L2SQ_DISTANCE, l2sq::l2sq);
|
||||
define_distance_function!(DotProductFunction, VEC_DOT_PRODUCT, dot::dot);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
Reference in New Issue
Block a user