You've already forked pgvecto.rs
mirror of
https://github.com/tensorchord/pgvecto.rs.git
synced 2025-07-29 08:21:12 +03:00
feat: deny unknown field in options (#184)
* fix: deny unknown options Signed-off-by: usamoi <usamoi@outlook.com> * test: deny unknown options Signed-off-by: usamoi <usamoi@outlook.com> --------- Signed-off-by: usamoi <usamoi@outlook.com>
This commit is contained in:
@ -15,6 +15,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum QuantizationOptions {
|
||||
Trivial(TrivialQuantizationOptions),
|
||||
|
@ -16,6 +16,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ProductQuantizationOptions {
|
||||
#[serde(default = "ProductQuantizationOptions::default_sample")]
|
||||
pub sample: u32,
|
||||
@ -40,6 +41,7 @@ impl Default for ProductQuantizationOptions {
|
||||
|
||||
#[repr(u16)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ProductQuantizationOptionsRatio {
|
||||
X4 = 1,
|
||||
|
@ -11,6 +11,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ScalarQuantizationOptions {}
|
||||
|
||||
impl Default for ScalarQuantizationOptions {
|
||||
|
@ -9,6 +9,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TrivialQuantizationOptions {}
|
||||
|
||||
impl Default for TrivialQuantizationOptions {
|
||||
|
@ -3,6 +3,7 @@ use crate::utils::file_wal::FileWal;
|
||||
use dashmap::mapref::entry::Entry;
|
||||
use dashmap::DashMap;
|
||||
use parking_lot::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -79,7 +80,7 @@ impl Delete {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Log {
|
||||
key: Pointer,
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct FlatIndexingOptions {
|
||||
#[serde(default)]
|
||||
#[validate]
|
||||
|
@ -10,6 +10,7 @@ use std::{path::PathBuf, sync::Arc};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct HnswIndexingOptions {
|
||||
#[serde(default = "HnswIndexingOptions::default_m")]
|
||||
#[validate(range(min = 4, max = 128))]
|
||||
|
@ -11,6 +11,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct IvfIndexingOptions {
|
||||
#[serde(default = "IvfIndexingOptions::default_least_iterations")]
|
||||
#[validate(range(min = 1, max = 1_000_000))]
|
||||
|
@ -16,6 +16,7 @@ use std::sync::Arc;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum IndexingOptions {
|
||||
Flat(FlatIndexingOptions),
|
||||
|
@ -37,6 +37,7 @@ use validator::Validate;
|
||||
pub struct OutdatedError(#[from] pub Option<GrowingSegmentInsertError>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct VectorOptions {
|
||||
#[validate(range(min = 1, max = 65535))]
|
||||
#[serde(rename = "dimensions")]
|
||||
@ -48,6 +49,7 @@ pub struct VectorOptions {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct IndexOptions {
|
||||
#[validate]
|
||||
pub vector: VectorOptions,
|
||||
@ -467,7 +469,7 @@ impl<S: G> IndexView<S> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct IndexStartup {
|
||||
sealeds: HashSet<Uuid>,
|
||||
growings: HashSet<Uuid>,
|
||||
|
@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct OptimizingOptions {
|
||||
#[serde(default = "OptimizingOptions::default_sealing_secs")]
|
||||
#[validate(range(min = 0, max = 60))]
|
||||
|
@ -7,6 +7,7 @@ use crate::prelude::*;
|
||||
use crate::utils::dir_ops::sync_dir;
|
||||
use crate::utils::file_wal::FileWal;
|
||||
use parking_lot::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::UnsafeCell;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::path::PathBuf;
|
||||
@ -199,7 +200,7 @@ impl<S: G> Drop for GrowingSegment<S> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct Log<S: G> {
|
||||
vector: Vec<S::Scalar>,
|
||||
payload: Payload,
|
||||
|
@ -9,6 +9,7 @@ use validator::Validate;
|
||||
use validator::ValidationError;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[validate(schema(function = "Self::validate_0"))]
|
||||
pub struct SegmentsOptions {
|
||||
#[serde(default = "SegmentsOptions::default_max_growing_segment_size")]
|
||||
|
@ -87,7 +87,7 @@ pub trait FloatCast: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum DynamicVector {
|
||||
F32(Vec<F32>),
|
||||
F16(Vec<F16>),
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::prelude::*;
|
||||
use std::ops::{Deref, DerefMut, Index, IndexMut};
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Vec2<S: G> {
|
||||
dims: u16,
|
||||
v: Vec<S::Scalar>,
|
||||
|
@ -10,6 +10,7 @@ use crate::utils::dir_ops::sync_dir;
|
||||
use crate::utils::file_atomic::FileAtomic;
|
||||
use arc_swap::ArcSwap;
|
||||
use parking_lot::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::DisplayFromStr;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@ -172,7 +173,7 @@ impl WorkerProtect {
|
||||
}
|
||||
|
||||
#[serde_with::serde_as]
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct WorkerStartup {
|
||||
#[serde_as(as = "HashMap<DisplayFromStr, _>")]
|
||||
indexes: HashMap<Id, IndexOptions>,
|
||||
|
Reference in New Issue
Block a user