query_planning/plan/vector_algorithm/
common.rs1use std::fmt;
2
3use crate::plan::DenseVectorBinding;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub enum VectorRowIdBinding {
8 RowIndex,
10 Column(String),
12}
13
14impl VectorRowIdBinding {
15 pub fn column(name: impl Into<String>) -> Self {
17 Self::Column(name.into())
18 }
19
20 pub(crate) fn diagnostic_label(&self) -> &str {
22 match self {
23 Self::RowIndex => "row_index",
24 Self::Column(name) => name,
25 }
26 }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct VectorRelationBinding {
32 pub input: usize,
34 pub row_id: VectorRowIdBinding,
36 pub vector: DenseVectorBinding,
38}
39
40impl VectorRelationBinding {
41 pub fn new(
43 input: usize,
44 row_id: VectorRowIdBinding,
45 feature_columns: impl IntoIterator<Item = impl Into<String>>,
46 ) -> Self {
47 Self { input, row_id, vector: DenseVectorBinding::columns(feature_columns) }
48 }
49
50 pub fn new_vector_column(input: usize, row_id: VectorRowIdBinding, column: impl Into<String>) -> Self {
52 Self { input, row_id, vector: DenseVectorBinding::vector_column(column) }
53 }
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
58pub enum VectorDistanceMetric {
59 L2Expanded,
61 L2SqrtExpanded,
63 CosineExpanded,
65 InnerProduct,
67}
68
69impl VectorDistanceMetric {
70 pub(crate) const fn as_str(self) -> &'static str {
72 match self {
73 Self::L2Expanded => "l2_expanded",
74 Self::L2SqrtExpanded => "l2_sqrt_expanded",
75 Self::CosineExpanded => "cosine_expanded",
76 Self::InnerProduct => "inner_product",
77 }
78 }
79}
80
81impl fmt::Display for VectorDistanceMetric {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 f.write_str(self.as_str())
84 }
85}