nodedb_physical/physical_plan/vector/write.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Row-existence and row-targeting shapes of the vector-primary direct
4//! writes.
5
6use nodedb_types::Surrogate;
7
8/// Row-existence semantics of a vector-primary direct write, as the three
9/// insert-family ops carry them on the durable record.
10#[derive(
11 Debug,
12 Clone,
13 Copy,
14 PartialEq,
15 Eq,
16 serde::Serialize,
17 serde::Deserialize,
18 zerompk::ToMessagePack,
19 zerompk::FromMessagePack,
20)]
21pub enum VectorDirectWriteIntent {
22 /// [`VectorOp::DirectInsert`](super::VectorOp::DirectInsert): an existing
23 /// key is a `unique_violation`.
24 Insert,
25 /// [`VectorOp::DirectInsertIfAbsent`](super::VectorOp::DirectInsertIfAbsent):
26 /// an existing key is left alone.
27 InsertIfAbsent,
28 /// [`VectorOp::DirectUpsert`](super::VectorOp::DirectUpsert): an existing
29 /// key is replaced or patched.
30 Upsert,
31}
32
33/// One row of a [`VectorOp::DirectBatchWrite`](super::VectorOp::DirectBatchWrite)
34/// page. The fields mean what the same-named fields of
35/// [`VectorOp::DirectUpsert`](super::VectorOp::DirectUpsert) mean.
36#[derive(
37 Debug,
38 Clone,
39 PartialEq,
40 serde::Serialize,
41 serde::Deserialize,
42 zerompk::ToMessagePack,
43 zerompk::FromMessagePack,
44)]
45pub struct VectorDirectRow {
46 /// Global surrogate the Control Plane bound to `pk_bytes`.
47 pub surrogate: Surrogate,
48 /// UTF-8 of the declared primary-key value.
49 pub pk_bytes: Vec<u8>,
50 /// FP32 vector values.
51 pub vector: Vec<f32>,
52 /// Pre-encoded MessagePack of every non-vector column the row supplied.
53 pub payload: Vec<u8>,
54}
55
56/// The rows a vector-primary `DELETE` / `UPDATE` targets.
57#[derive(
58 Debug,
59 Clone,
60 PartialEq,
61 serde::Serialize,
62 serde::Deserialize,
63 zerompk::ToMessagePack,
64 zerompk::FromMessagePack,
65)]
66pub enum VectorWriteTargets {
67 /// Surrogates the Control Plane resolved from primary-key equalities. A
68 /// key with no binding contributes no entry.
69 Surrogates(Vec<Surrogate>),
70 /// Serialized `Vec<ScanFilter>` the Data Plane evaluates against every
71 /// payload sidecar row. Empty bytes match every row.
72 Predicate(Vec<u8>),
73}