use super::types::*;
use crate::ast::{FilterExpr, Value};
use alloc::string::String;
use alloc::vec::Vec;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EmbedKind {
Dense {
model: Option<String>,
},
Sparse {
model: Option<String>,
},
Multi {
model: Option<String>,
},
Image {
model: Option<String>,
},
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EmbedDirective {
pub source_field: String,
pub target_vector: String,
pub kind: EmbedKind,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EmbeddingSpec {
Dense {
model: Option<String>,
vector: Option<String>,
field: Option<String>,
},
Sparse {
model: Option<String>,
vector: Option<String>,
field: Option<String>,
},
Hybrid {
dense_model: Option<String>,
dense_vector: Option<String>,
dense_field: Option<String>,
sparse_model: Option<String>,
sparse_vector: Option<String>,
sparse_field: Option<String>,
},
MultiVector {
model: Option<String>,
vector: Option<String>,
field: Option<String>,
},
Image {
model: Option<String>,
vector: Option<String>,
field: Option<String>,
},
Multi(Vec<EmbeddingSpec>),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpsertPoint {
pub id: PointId,
pub vectors: Option<PointVectors>,
pub payload: Vec<(String, Value)>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
pub enum PointEntry {
Inline(UpsertPoint),
Param(
String,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
Option<alloc::boxed::Box<crate::error::Span>>,
),
PositionalParam(
usize,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
Option<alloc::boxed::Box<crate::error::Span>>,
),
}
impl PointEntry {
pub fn as_inline(&self) -> Option<&UpsertPoint> {
match self {
PointEntry::Inline(point) => Some(point),
PointEntry::Param(..) | PointEntry::PositionalParam(..) => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpsertStmt {
pub collection: String,
pub points: Vec<PointEntry>,
pub embedding: Option<EmbeddingSpec>,
pub embed: Vec<EmbedDirective>,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub update_filter: Option<FilterExpr>,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub update_mode: Option<UpsertUpdateMode>,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum UpsertUpdateMode {
InsertOnly,
UpdateOnly,
Upsert,
}
#[cfg(feature = "serde")]
fn is_false(value: &bool) -> bool {
!*value
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClearPayloadStmt {
pub collection: String,
pub selector: PointSelector,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DeleteVectorStmt {
pub collection: String,
pub selector: PointSelector,
pub vector_names: Vec<String>,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PointSelector {
Id(PointId),
Ids(Vec<PointId>),
Filter(Box<FilterExpr>),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DeleteStmt {
pub collection: String,
pub selector: PointSelector,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateVectorPoint {
pub id: PointId,
pub vectors: PointVectors,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateVectorStmt {
pub collection: String,
pub points: Vec<UpdateVectorPoint>,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DeletePayloadStmt {
pub collection: String,
pub keys: Vec<String>,
pub selector: PointSelector,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdatePayloadStmt {
pub collection: String,
pub selector: PointSelector,
pub payload: Vec<(String, Value)>,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub key: Option<String>,
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "is_false"))]
pub overwrite: bool,
pub shard_key: Option<super::ShardKey>,
pub wait: Option<bool>,
}