linkrs-query 0.1.0

Query engine, parser, and executor for Linkrs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
use std::sync::Arc;

use parking_lot::RwLock;

use crate::executor::streaming::chunk::DataChunk;
use crate::executor::streaming::executor::StreamingExecutor;
use crate::executor::streaming::operators::source_operator::OperatorConfig;
use crate::executor::streaming::operators::spec::VectorManageCommand;
use crate::executor::streaming::runtime::ExecutionRuntime;
use crate::executor::streaming::slot::SlotLayout;
use crate::storage::QueryStorage;
use linkrs_core::error::QueryError;
#[cfg(feature = "vector")]
use linkrs_core::Value;
#[cfg(feature = "vector")]
use linkrs_sync::VectorSyncCoordinator;

#[cfg(feature = "vector")]
fn make_manage_result(
    output_layout: Arc<SlotLayout>,
    action: &str,
    name: Option<&str>,
    status: &str,
) -> DataChunk {
    let name_val = name
        .map(Value::string)
        .unwrap_or(Value::Null(linkrs_core::NullType::Null));
    DataChunk::new_with_layout(
        vec![vec![Value::string(action), name_val, Value::string(status)]],
        output_layout,
    )
}

/// Candidate count for MATCH VECTOR searches.
///
/// The `MATCH VECTOR` grammar has no LIMIT clause yet (see the parser AST),
/// so a fixed candidate window is used; wire this to syntax once LIMIT is
/// added to the statement form.
#[cfg(feature = "vector")]
const DEFAULT_MATCH_TOP_K: usize = 100;

#[derive(Debug)]
pub enum VectorOperatorKind {
    VectorManage {
        storage: Option<Arc<RwLock<dyn QueryStorage>>>,
        space_name: String,
        command: VectorManageCommand,
        #[cfg(feature = "vector")]
        vector_coordinator: Option<Arc<VectorSyncCoordinator>>,
    },
    VectorSearch {
        storage: Option<Arc<RwLock<dyn QueryStorage>>>,
        space_name: String,
        space_id: u64,
        index_name: String,
        query_vector: Vec<f32>,
        /// Raw text for TEXT queries; resolved to a vector at execution time.
        query_text: Option<String>,
        top_k: u32,
        tag_name: String,
        field_name: String,
        threshold: Option<f32>,
        filter: Option<super::spec::SpecVectorFilter>,
        offset: usize,
        #[cfg(feature = "vector")]
        ryw_config: Option<linkrs_core::types::ReadYourWritesConfig>,
        #[cfg(feature = "vector")]
        vector_coordinator: Option<Arc<VectorSyncCoordinator>>,
    },
    VectorLookup {
        storage: Option<Arc<RwLock<dyn QueryStorage>>>,
        space_name: String,
        space_id: u64,
        index_name: String,
        query_vector: Vec<f32>,
        /// Raw text for TEXT queries; resolved to a vector at execution time.
        query_text: Option<String>,
        top_k: u32,
        tag_name: String,
        field_name: String,
        #[cfg(feature = "vector")]
        ryw_config: Option<linkrs_core::types::ReadYourWritesConfig>,
        #[cfg(feature = "vector")]
        vector_coordinator: Option<Arc<VectorSyncCoordinator>>,
    },
    VectorMatch {
        storage: Option<Arc<RwLock<dyn QueryStorage>>>,
        space_name: String,
        pattern: String,
        field: String,
        query_vector: Vec<f32>,
        /// Raw text for TEXT queries; resolved to a vector at execution time.
        query_text: Option<String>,
        threshold: Option<f32>,
        tag_name: String,
        field_name: String,
        space_id: u64,
        #[cfg(feature = "vector")]
        ryw_config: Option<linkrs_core::types::ReadYourWritesConfig>,
        #[cfg(feature = "vector")]
        vector_coordinator: Option<Arc<VectorSyncCoordinator>>,
    },
}

/// Vector operator.
///
/// Wraps [`VectorOperatorKind`] with the runtime context injected at `open()`.
/// Lifecycle state is owned exclusively by the executor; operators never
/// write it.
#[derive(Debug)]
pub struct VectorOperator {
    pub kind: VectorOperatorKind,
    pub runtime: Option<Arc<ExecutionRuntime>>,
    pub output_layout: Arc<SlotLayout>,
    pub config: OperatorConfig,
}

impl VectorOperator {
    /// Create a VectorOperator from an immutable spec.
    pub fn from_spec(
        spec: &super::spec::VectorSpec,
        storage: Option<Arc<RwLock<dyn QueryStorage>>>,
        #[cfg(feature = "vector")] vector_coordinator: Option<Arc<VectorSyncCoordinator>>,
        output_layout: Arc<SlotLayout>,
    ) -> Self {
        let kind = match spec {
            super::spec::VectorSpec::VectorManage {
                space_name,
                command,
            } => VectorOperatorKind::VectorManage {
                storage: storage.clone(),
                space_name: space_name.clone(),
                command: command.clone(),
                #[cfg(feature = "vector")]
                vector_coordinator: vector_coordinator.clone(),
            },
            super::spec::VectorSpec::VectorSearch {
                space_name,
                space_id,
                index_name,
                query_vector,
                query_text,
                top_k,
                tag_name,
                field_name,
                threshold,
                filter,
                offset,
                ..
            } => VectorOperatorKind::VectorSearch {
                storage: storage.clone(),
                space_name: space_name.clone(),
                space_id: *space_id,
                index_name: index_name.clone(),
                query_vector: query_vector.clone(),
                query_text: query_text.clone(),
                top_k: *top_k,
                tag_name: tag_name.clone(),
                field_name: field_name.clone(),
                threshold: *threshold,
                filter: filter.clone(),
                offset: *offset,
                #[cfg(feature = "vector")]
                ryw_config: spec.ryw_config(),
                #[cfg(feature = "vector")]
                vector_coordinator: vector_coordinator.clone(),
            },
            super::spec::VectorSpec::VectorLookup {
                space_name,
                space_id,
                index_name,
                query_vector,
                query_text,
                top_k,
                tag_name,
                field_name,
                ..
            } => VectorOperatorKind::VectorLookup {
                storage: storage.clone(),
                space_name: space_name.clone(),
                space_id: *space_id,
                index_name: index_name.clone(),
                query_vector: query_vector.clone(),
                query_text: query_text.clone(),
                top_k: *top_k,
                tag_name: tag_name.clone(),
                field_name: field_name.clone(),
                #[cfg(feature = "vector")]
                ryw_config: spec.ryw_config(),
                #[cfg(feature = "vector")]
                vector_coordinator: vector_coordinator.clone(),
            },
            super::spec::VectorSpec::VectorMatch {
                space_name,
                pattern,
                field,
                query_vector,
                query_text,
                threshold,
                tag_name,
                field_name,
                space_id,
                ..
            } => VectorOperatorKind::VectorMatch {
                storage: storage.clone(),
                space_name: space_name.clone(),
                pattern: pattern.clone(),
                field: field.clone(),
                query_vector: query_vector.clone(),
                query_text: query_text.clone(),
                threshold: *threshold,
                tag_name: tag_name.clone(),
                field_name: field_name.clone(),
                space_id: *space_id,
                #[cfg(feature = "vector")]
                ryw_config: spec.ryw_config(),
                #[cfg(feature = "vector")]
                vector_coordinator: vector_coordinator.clone(),
            },
        };
        Self::new(kind, output_layout)
    }

    pub fn new(kind: VectorOperatorKind, output_layout: Arc<SlotLayout>) -> Self {
        Self {
            kind,
            runtime: None,
            output_layout,
            config: OperatorConfig::default(),
        }
    }

    /// Inject the runtime and execution config (called once by the executor
    /// before this operator produces any data).
    pub fn inject_context(
        &mut self,
        runtime: Option<&Arc<ExecutionRuntime>>,
        config: OperatorConfig,
    ) {
        if let Some(rt) = runtime {
            self.runtime = Some(rt.clone());
        }
        self.config = config;
    }

    pub fn open(&mut self, input: &mut StreamingExecutor) -> Result<(), QueryError> {
        match &mut self.kind {
            VectorOperatorKind::VectorManage { .. }
            | VectorOperatorKind::VectorSearch { .. }
            | VectorOperatorKind::VectorLookup { .. }
            | VectorOperatorKind::VectorMatch { .. } => {
                input.open()?;
                Ok(())
            }
        }
    }

    pub fn next(&mut self, input: &mut StreamingExecutor) -> Result<Option<DataChunk>, QueryError> {
        match &mut self.kind {
            VectorOperatorKind::VectorManage {
                storage,
                space_name,
                command,
                #[cfg(feature = "vector")]
                vector_coordinator,
            } => {
                #[cfg(feature = "vector")]
                let _ = (&storage, &space_name);

                match command {
                    VectorManageCommand::Create {
                        index_name,
                        tag_name,
                        field_name,
                        vector_size,
                        distance,
                        space_id,
                        hnsw_m,
                        hnsw_ef_construct,
                        quantization,
                        quantile,
                        compression,
                        always_ram,
                    } => {
                        #[cfg(feature = "vector")]
                        {
                            if let Some(coordinator) = vector_coordinator {
                                // Vector indexes are vertex-only: point IDs,
                                // payloads, and rebuild sources are all modeled
                                // per vertex. Reject edge type names here as well
                                // so the no-metadata query path cannot create an
                                // index that can never receive data. A storage
                                // error fails open: the planner already rejects
                                // known edge types, and an unreadable catalog
                                // must not block vertex index creation.
                                if let Some(storage) = storage.as_ref() {
                                    if !tag_name.is_empty() {
                                        if let Ok(edge) =
                                            storage.read().get_edge_type(space_name, tag_name)
                                        {
                                            if edge.is_some() {
                                                return Err(QueryError::execution(format!(
                                                    "Vector indexes are vertex-only: '{}' is an edge type, create the index on a vertex tag instead",
                                                    tag_name
                                                )));
                                            }
                                        }
                                    }
                                }
                                let distance = match distance {
                                    crate::parser::ast::vector::VectorDistance::Cosine => {
                                        simvec::DistanceMetric::Cosine
                                    }
                                    crate::parser::ast::vector::VectorDistance::Euclidean => {
                                        simvec::DistanceMetric::Euclid
                                    }
                                    crate::parser::ast::vector::VectorDistance::Dot => {
                                        simvec::DistanceMetric::Dot
                                    }
                                    crate::parser::ast::vector::VectorDistance::Manhattan => {
                                        simvec::DistanceMetric::Manhattan
                                    }
                                };
                                // Build CollectionConfig with optional HNSW and quantization
                                // (mirrors Qdrant scalar/product/binary builders).
                                let mut config =
                                    simvec::CollectionConfig::new(*vector_size, distance);
                                if hnsw_m.is_some() || hnsw_ef_construct.is_some() {
                                    let mut hnsw = simvec::HnswConfig::default();
                                    if let Some(m) = hnsw_m {
                                        hnsw.m = *m;
                                    }
                                    if let Some(ef) = hnsw_ef_construct {
                                        hnsw.ef_construct = *ef;
                                    }
                                    hnsw.validate().map_err(|e| {
                                        QueryError::execution(format!(
                                            "invalid HNSW parameters: {}",
                                            e
                                        ))
                                    })?;
                                    config = config.with_hnsw(hnsw);
                                }
                                if let Some(qkind) = quantization {
                                    if compression.is_some()
                                        && !matches!(
                                            qkind,
                                            crate::parser::ast::vector::QuantizationKind::Product
                                        )
                                    {
                                        return Err(QueryError::execution(format!(
                                            "compression requires quantization=PRODUCT, got quantization={:?}; omit compression or use PRODUCT",
                                            qkind
                                        )));
                                    }
                                    let quant_cfg = match qkind {
                                        crate::parser::ast::vector::QuantizationKind::Scalar => {
                                            let mut cfg = simvec::QuantizationConfig::scalar(
                                                quantile.unwrap_or(0.99),
                                            );
                                            if let Some(ar) = always_ram {
                                                cfg = cfg.with_always_ram(*ar);
                                            }
                                            cfg
                                        }
                                        crate::parser::ast::vector::QuantizationKind::Binary => {
                                            let mut cfg = simvec::QuantizationConfig::binary();
                                            if let Some(ar) = always_ram {
                                                cfg = cfg.with_always_ram(*ar);
                                            }
                                            cfg
                                        }
                                        crate::parser::ast::vector::QuantizationKind::Product => {
                                            let ratio = match compression {
                                                Some(crate::parser::ast::vector::CompressionRatioKind::X4) => {
                                                    simvec::CompressionRatio::X4
                                                }
                                                Some(crate::parser::ast::vector::CompressionRatioKind::X8) => {
                                                    simvec::CompressionRatio::X8
                                                }
                                                Some(crate::parser::ast::vector::CompressionRatioKind::X16) => {
                                                    simvec::CompressionRatio::X16
                                                }
                                                Some(crate::parser::ast::vector::CompressionRatioKind::X32) => {
                                                    simvec::CompressionRatio::X32
                                                }
                                                Some(crate::parser::ast::vector::CompressionRatioKind::X64) => {
                                                    simvec::CompressionRatio::X64
                                                }
                                                None => simvec::CompressionRatio::X4,
                                            };
                                            let mut cfg =
                                                simvec::QuantizationConfig::product(ratio);
                                            if let Some(ar) = always_ram {
                                                cfg = cfg.with_always_ram(*ar);
                                            }
                                            cfg
                                        }
                                    };
                                    quant_cfg.validate(*vector_size).map_err(|e| {
                                        QueryError::execution(format!(
                                            "invalid quantization parameters: {}",
                                            e
                                        ))
                                    })?;
                                    config = config.with_quantization(quant_cfg);
                                }
                                let res = if config.quantization_config.is_some()
                                    || config.hnsw_config.is_some()
                                {
                                    crate::executor::streaming::helpers::runtime_bridge::wait(
                                        "Vector create",
                                        coordinator.create_index_with_config(
                                            *space_id, tag_name, field_name, config,
                                        ),
                                    )
                                } else {
                                    crate::executor::streaming::helpers::runtime_bridge::wait(
                                        "Vector create",
                                        coordinator.create_vector_index(
                                            *space_id,
                                            tag_name,
                                            field_name,
                                            *vector_size,
                                            distance,
                                        ),
                                    )
                                };
                                match res {
                                    Ok(_) => {
                                        // Record the statement-level name so
                                        // later SEARCH/LOOKUP/DROP statements
                                        // resolve it back to (space, tag, field).
                                        coordinator.set_index_name(
                                            *space_id, tag_name, field_name, index_name,
                                        );
                                        Ok(Some(make_manage_result(
                                            Arc::clone(&self.output_layout),
                                            "create_vector_index",
                                            Some(index_name.as_str()),
                                            "created",
                                        )))
                                    }
                                    Err(e) => Err(e),
                                }
                            } else {
                                Err(QueryError::execution(
                                    "CREATE VECTOR INDEX cannot execute: no vector coordinator is configured",
                                ))
                            }
                        }
                        #[cfg(not(feature = "vector"))]
                        {
                            let _ = (
                                storage,
                                space_name,
                                index_name,
                                tag_name,
                                field_name,
                                vector_size,
                                distance,
                                space_id,
                                hnsw_m,
                                hnsw_ef_construct,
                                quantization,
                                quantile,
                                compression,
                                always_ram,
                            );
                            Err(QueryError::feature_disabled(
                                "vector",
                                "CREATE VECTOR INDEX",
                            ))
                        }
                    }
                    VectorManageCommand::Drop {
                        index_name,
                        if_exists,
                        space_id,
                        tag_name,
                        field_name,
                    } => {
                        #[cfg(feature = "vector")]
                        {
                            // The drop API is addressed by (space_id, tag,
                            // field). An unresolved location means the index
                            // was not found at planning time: `IF EXISTS`
                            // degrades to a no-op status row, otherwise it is
                            // a clear error.
                            if tag_name.is_empty() || field_name.is_empty() {
                                if *if_exists {
                                    return Ok(Some(make_manage_result(
                                        Arc::clone(&self.output_layout),
                                        "drop_vector_index",
                                        Some(index_name.as_str()),
                                        "not_exists",
                                    )));
                                }
                                return Err(QueryError::execution(format!(
                                    "Vector index '{}' cannot be dropped: index location (tag/field) is not resolved",
                                    index_name
                                )));
                            }
                            match vector_coordinator {
                                Some(coordinator) => {
                                    crate::executor::streaming::helpers::runtime_bridge::wait(
                                        "Vector drop",
                                        coordinator
                                            .drop_vector_index(*space_id, tag_name, field_name),
                                    )?;
                                    Ok(Some(make_manage_result(
                                        Arc::clone(&self.output_layout),
                                        "drop_vector_index",
                                        Some(index_name.as_str()),
                                        "dropped",
                                    )))
                                }
                                None => Err(QueryError::execution(
                                    "DROP VECTOR INDEX cannot execute: no vector coordinator is configured",
                                )),
                            }
                        }
                        #[cfg(not(feature = "vector"))]
                        {
                            let _ = (
                                storage, space_name, index_name, if_exists, space_id, tag_name,
                                field_name,
                            );
                            Err(QueryError::feature_disabled("vector", "DROP VECTOR INDEX"))
                        }
                    }
                }
            }

            VectorOperatorKind::VectorSearch {
                storage: _,
                space_name: _,
                space_id,
                index_name: _,
                query_vector,
                query_text,
                top_k,
                tag_name,
                field_name,
                threshold,
                filter,
                offset,
                #[cfg(feature = "vector")]
                ryw_config,
                #[cfg(feature = "vector")]
                vector_coordinator,
                ..
            } => {
                #[cfg(feature = "vector")]
                {
                    if let Some(coordinator) = vector_coordinator {
                        // The planner resolves index_name to (tag, field)
                        // via the index registry; an empty location is an
                        // unknown index, not an empty match set.
                        if tag_name.is_empty() || field_name.is_empty() {
                            return Err(QueryError::execution(
                                "SEARCH VECTOR cannot execute: index location (tag/field) is not resolved",
                            ));
                        }
                        // Resolve TEXT query to a vector at execution time via
                        // the embedding service (deferred embed pattern).
                        let resolved_vector = if let Some(text) = query_text {
                            #[cfg(feature = "embedding")]
                            {
                                let embedded =
                                    crate::executor::streaming::helpers::runtime_bridge::wait(
                                        "TEXT vector embed",
                                        coordinator.embed_text(text),
                                    )
                                    .map_err(|e| {
                                        QueryError::execution(format!(
                                            "TEXT vector embed failed: {}",
                                            e
                                        ))
                                    })?;
                                embedded
                            }
                            #[cfg(not(feature = "embedding"))]
                            {
                                let _ = text;
                                return Err(QueryError::execution(
                                    "TEXT vector query requires the 'embedding' feature to be enabled",
                                ));
                            }
                        } else {
                            query_vector.clone()
                        };
                        // Fetch enough candidates so skipping `offset` rows
                        // still leaves up to `top_k` results. An active
                        // rerank stage widens recall inside the coordinator
                        // and truncates back to this limit.
                        let recall_limit = (*top_k as usize).saturating_add(*offset);
                        let mut options = linkrs_sync::vector_sync::SearchOptions::new(
                            *space_id,
                            tag_name.clone(),
                            field_name.clone(),
                            resolved_vector,
                            recall_limit,
                        );
                        options.query_text = query_text.clone();
                        // A zero threshold is vacuous for similarity scores;
                        // keep it unset so behavior matches the no-THRESHOLD
                        // statement form.
                        match threshold {
                            Some(t) if *t > 0.0 => options.threshold = Some(*t),
                            _ => {}
                        }
                        if let Some(filter) = filter {
                            options.filter = Some(filter.clone());
                        }
                        if let Some(cfg) = ryw_config {
                            options.consistency =
                                linkrs_sync::vector_sync::SearchConsistency::ReadYourWrites {
                                    timeout_ms: cfg.timeout_ms,
                                };
                            options.minimum_lsn = cfg.minimum_lsn;
                        }
                        let search_results =
                            crate::executor::streaming::helpers::runtime_bridge::wait(
                                "Vector search",
                                coordinator.search_with_options(options),
                            )?;
                        let mut rows = Vec::new();
                        for result in search_results.into_iter().skip(*offset) {
                            rows.push(vec![
                                Value::string(result.id.to_string()),
                                Value::Double(result.score as f64),
                            ]);
                        }
                        return if rows.is_empty() {
                            Ok(None)
                        } else {
                            Ok(Some(DataChunk::new_with_layout(
                                rows,
                                self.output_layout.clone(),
                            )))
                        };
                    }

                    // A missing coordinator is a configuration error, not an
                    // empty result: fail loudly instead of silently returning
                    // nothing (or unrelated input rows).
                    let _ = input;
                    Err(QueryError::execution(
                        "SEARCH VECTOR cannot execute: no vector coordinator is configured",
                    ))
                }

                #[cfg(not(feature = "vector"))]
                {
                    let _ = (
                        &space_id,
                        &tag_name,
                        &field_name,
                        &query_vector,
                        query_text.as_deref(),
                        &top_k,
                        &threshold,
                        &filter,
                        &offset,
                        input,
                    );
                    Err(QueryError::feature_disabled("vector", "VECTOR SEARCH"))
                }
            }

            VectorOperatorKind::VectorLookup {
                storage: _,
                space_name: _,
                space_id,
                index_name: _,
                query_vector,
                query_text,
                top_k,
                tag_name,
                field_name,
                #[cfg(feature = "vector")]
                ryw_config,
                #[cfg(feature = "vector")]
                vector_coordinator,
                ..
            } => {
                #[cfg(feature = "vector")]
                {
                    if let Some(coordinator) = vector_coordinator {
                        // LOOKUP VECTOR resolves to the same index location
                        // as SEARCH VECTOR and reuses the identical search
                        // path, producing (id, score) rows.
                        if tag_name.is_empty() || field_name.is_empty() {
                            return Err(QueryError::execution(
                                "LOOKUP VECTOR cannot execute: index location (tag/field) is not resolved",
                            ));
                        }
                        // Resolve TEXT query to a vector at execution time.
                        let resolved_vector = if let Some(text) = query_text {
                            #[cfg(feature = "embedding")]
                            {
                                let embedded =
                                    crate::executor::streaming::helpers::runtime_bridge::wait(
                                        "TEXT vector embed",
                                        coordinator.embed_text(text),
                                    )
                                    .map_err(|e| {
                                        QueryError::execution(format!(
                                            "TEXT vector embed failed: {}",
                                            e
                                        ))
                                    })?;
                                embedded
                            }
                            #[cfg(not(feature = "embedding"))]
                            {
                                let _ = text;
                                return Err(QueryError::execution(
                                    "TEXT vector query requires the 'embedding' feature to be enabled",
                                ));
                            }
                        } else {
                            query_vector.clone()
                        };
                        // The coordinator widens recall for an active rerank
                        // stage and truncates back to `top_k`.
                        let mut options = linkrs_sync::vector_sync::SearchOptions::new(
                            *space_id,
                            tag_name.clone(),
                            field_name.clone(),
                            resolved_vector,
                            *top_k as usize,
                        );
                        options.query_text = query_text.clone();
                        if let Some(cfg) = ryw_config {
                            options.consistency =
                                linkrs_sync::vector_sync::SearchConsistency::ReadYourWrites {
                                    timeout_ms: cfg.timeout_ms,
                                };
                            options.minimum_lsn = cfg.minimum_lsn;
                        }
                        let search_results =
                            crate::executor::streaming::helpers::runtime_bridge::wait(
                                "Vector lookup",
                                coordinator.search_with_options(options),
                            )?;
                        let mut rows = Vec::new();
                        for result in search_results {
                            rows.push(vec![
                                Value::string(result.id.to_string()),
                                Value::Double(result.score as f64),
                            ]);
                        }
                        return if rows.is_empty() {
                            Ok(None)
                        } else {
                            Ok(Some(DataChunk::new_with_layout(
                                rows,
                                self.output_layout.clone(),
                            )))
                        };
                    }

                    let _ = input;
                    Err(QueryError::execution(
                        "LOOKUP VECTOR cannot execute: no vector coordinator is configured",
                    ))
                }

                #[cfg(not(feature = "vector"))]
                {
                    let _ = (
                        &space_id,
                        &tag_name,
                        &field_name,
                        &query_vector,
                        query_text.as_deref(),
                        &top_k,
                    );
                    Err(QueryError::feature_disabled("vector", "VECTOR LOOKUP"))
                }
            }

            VectorOperatorKind::VectorMatch {
                storage: _,
                space_name: _,
                pattern: _,
                field: _,
                query_vector,
                query_text,
                threshold,
                tag_name,
                field_name,
                space_id,
                #[cfg(feature = "vector")]
                ryw_config,
                #[cfg(feature = "vector")]
                vector_coordinator,
                ..
            } => {
                #[cfg(feature = "vector")]
                {
                    if let Some(coordinator) = vector_coordinator {
                        // Resolve TEXT query to a vector at execution time.
                        let resolved_vector = if let Some(text) = query_text {
                            #[cfg(feature = "embedding")]
                            {
                                let embedded =
                                    crate::executor::streaming::helpers::runtime_bridge::wait(
                                        "TEXT vector embed",
                                        coordinator.embed_text(text),
                                    )
                                    .map_err(|e| {
                                        QueryError::execution(format!(
                                            "TEXT vector embed failed: {}",
                                            e
                                        ))
                                    })?;
                                embedded
                            }
                            #[cfg(not(feature = "embedding"))]
                            {
                                let _ = text;
                                return Err(QueryError::execution(
                                    "TEXT vector query requires the 'embedding' feature to be enabled",
                                ));
                            }
                        } else {
                            query_vector.clone()
                        };
                        let thr = threshold.unwrap_or(0.5);
                        // Threshold filtering and optional RYW consistency
                        // ride the shared search options; an active rerank
                        // stage is applied by the coordinator.
                        let mut options = linkrs_sync::vector_sync::SearchOptions::new(
                            *space_id,
                            tag_name.clone(),
                            field_name.clone(),
                            resolved_vector,
                            DEFAULT_MATCH_TOP_K,
                        )
                        .with_threshold(thr);
                        options.query_text = query_text.clone();
                        if let Some(cfg) = ryw_config {
                            options.consistency =
                                linkrs_sync::vector_sync::SearchConsistency::ReadYourWrites {
                                    timeout_ms: cfg.timeout_ms,
                                };
                            options.minimum_lsn = cfg.minimum_lsn;
                        }
                        let search_results =
                            crate::executor::streaming::helpers::runtime_bridge::wait(
                                "Vector match",
                                coordinator.search_with_options(options),
                            )?;
                        let mut rows = Vec::new();
                        for result in search_results {
                            rows.push(vec![
                                Value::string(result.id.to_string()),
                                Value::Double(result.score as f64),
                            ]);
                        }
                        return if rows.is_empty() {
                            Ok(None)
                        } else {
                            Ok(Some(DataChunk::new_with_layout(
                                rows,
                                self.output_layout.clone(),
                            )))
                        };
                    }

                    let _ = input;
                    Err(QueryError::execution(
                        "MATCH VECTOR cannot execute: no vector coordinator is configured",
                    ))
                }

                #[cfg(not(feature = "vector"))]
                {
                    let _ = (
                        &space_id,
                        &tag_name,
                        &field_name,
                        &query_vector,
                        query_text.as_deref(),
                        &threshold,
                        input,
                    );
                    Err(QueryError::feature_disabled("vector", "VECTOR MATCH"))
                }
            }
        }
    }

    pub fn stop(&mut self) -> Result<(), QueryError> {
        Ok(())
    }

    pub fn close(&mut self) -> Result<(), QueryError> {
        Ok(())
    }
}