Skip to main content

linkrs_query/executor/streaming/operators/spec/
vector.rs

1//! Immutable configuration for vector search operators.
2
3use crate::parser::ast::vector::VectorDistance;
4
5/// Payload filter type for vector search.
6///
7/// Mirrors the planning-layer alias: the real `simvec::VectorFilter`
8/// when the vector feature is on, and an uninhabited-in-practice stub
9/// otherwise (vector search itself is feature-gated).
10#[cfg(feature = "vector")]
11pub use simvec::types::VectorFilter as SpecVectorFilter;
12
13#[cfg(not(feature = "vector"))]
14#[derive(Debug, Clone)]
15pub struct SpecVectorFilter;
16
17/// Vector index DDL command payload.
18#[derive(Debug, Clone)]
19pub enum VectorManageCommand {
20    Create {
21        index_name: String,
22        tag_name: String,
23        field_name: String,
24        vector_size: usize,
25        distance: VectorDistance,
26        space_id: u64,
27        hnsw_m: Option<usize>,
28        hnsw_ef_construct: Option<usize>,
29        quantization: Option<crate::parser::ast::vector::QuantizationKind>,
30        quantile: Option<f32>,
31        compression: Option<crate::parser::ast::vector::CompressionRatioKind>,
32        always_ram: Option<bool>,
33    },
34    Drop {
35        index_name: String,
36        if_exists: bool,
37        /// Pre-resolved coordinator location (space_id/tag/field); empty
38        /// tag/field means the location could not be resolved at planning
39        /// time and the executor reports a clear error or an `IF EXISTS`
40        /// no-op status row.
41        space_id: u64,
42        tag_name: String,
43        field_name: String,
44    },
45}
46
47/// Immutable config for vector search operators.
48#[derive(Debug, Clone)]
49pub enum VectorSpec {
50    VectorManage {
51        space_name: String,
52        command: VectorManageCommand,
53    },
54    VectorSearch {
55        space_name: String,
56        space_id: u64,
57        index_name: String,
58        query_vector: Vec<f32>,
59        /// Raw text for TEXT queries; resolved to a vector at execution time
60        /// via the embedding service. `None` for Vector/Parameter queries
61        /// where the vector is already resolved.
62        query_text: Option<String>,
63        top_k: u32,
64        tag_name: String,
65        field_name: String,
66        /// Minimum similarity score a result must reach.
67        threshold: Option<f32>,
68        /// Payload filter derived from the WHERE clause.
69        filter: Option<SpecVectorFilter>,
70        /// Number of leading result rows to skip after the engine returns
71        /// `top_k + offset` candidates (OFFSET semantics).
72        offset: usize,
73        /// Read-your-writes consistency config; `None` = eventual.
74        ryw_config: Option<linkrs_core::types::ReadYourWritesConfig>,
75    },
76    VectorLookup {
77        space_name: String,
78        space_id: u64,
79        index_name: String,
80        query_vector: Vec<f32>,
81        /// Raw text for TEXT queries; resolved to a vector at execution time.
82        query_text: Option<String>,
83        top_k: u32,
84        tag_name: String,
85        field_name: String,
86        /// Read-your-writes consistency config; `None` = eventual.
87        ryw_config: Option<linkrs_core::types::ReadYourWritesConfig>,
88    },
89    VectorMatch {
90        space_name: String,
91        pattern: String,
92        field: String,
93        query_vector: Vec<f32>,
94        /// Raw text for TEXT queries; resolved to a vector at execution time.
95        query_text: Option<String>,
96        threshold: Option<f32>,
97        tag_name: String,
98        field_name: String,
99        space_id: u64,
100        /// Read-your-writes consistency config; `None` = eventual.
101        ryw_config: Option<linkrs_core::types::ReadYourWritesConfig>,
102    },
103}
104
105impl VectorSpec {
106    /// Return the RYW consistency config, if any.
107    pub fn ryw_config(&self) -> Option<linkrs_core::types::ReadYourWritesConfig> {
108        match self {
109            Self::VectorManage { .. } => None,
110            Self::VectorSearch { ryw_config, .. }
111            | Self::VectorLookup { ryw_config, .. }
112            | Self::VectorMatch { ryw_config, .. } => *ryw_config,
113        }
114    }
115}