pub struct VectorConfig {
pub dimensions: u32,
pub index_type: VectorIndexType,
pub distance_metric: DistanceMetric,
}Expand description
Configuration for a vector field (pgvector).
This represents the configuration for a vector embedding field, including dimensions, index type, and distance metric.
The same config describes both vector field types: for
FieldType::Vector dimensions counts float components, for
FieldType::BitVector it counts bits. Which distance metrics are
legal follows from the field type — see VectorConfig::validate_for.
§Example
use fraiseql_core::schema::{VectorConfig, VectorIndexType, DistanceMetric};
let config = VectorConfig {
dimensions: 1536,
index_type: VectorIndexType::Hnsw,
distance_metric: DistanceMetric::Cosine,
};Fields§
§dimensions: u32Number of dimensions in the vector: float components for
FieldType::Vector, bits for FieldType::BitVector
(e.g., 1536 for OpenAI embeddings).
index_type: VectorIndexTypeType of index to use for similarity search.
distance_metric: DistanceMetricDistance metric for similarity calculations.
Implementations§
Source§impl VectorConfig
impl VectorConfig
Sourcepub fn new(dimensions: u32) -> Self
pub fn new(dimensions: u32) -> Self
Create a new vector config with default index and distance metric.
Sourcepub const fn openai() -> Self
pub const fn openai() -> Self
Create a vector config for OpenAI embeddings (1536 dimensions, cosine).
Sourcepub const fn openai_small() -> Self
pub const fn openai_small() -> Self
Create a vector config for OpenAI small embeddings (512 dimensions, cosine).
Sourcepub const fn with_index(self, index_type: VectorIndexType) -> Self
pub const fn with_index(self, index_type: VectorIndexType) -> Self
Set the index type.
Sourcepub const fn with_distance(self, distance_metric: DistanceMetric) -> Self
pub const fn with_distance(self, distance_metric: DistanceMetric) -> Self
Set the distance metric.
Sourcepub const fn binary(bits: u32) -> Self
pub const fn binary(bits: u32) -> Self
Create a binary-vector config (bit(N), hamming distance, HNSW).
bits is the bit width of the column, e.g. 768 for a
binary_quantize(embedding)::bit(768) fingerprint.
Sourcepub fn validate_for(&self, field_type: &FieldType) -> Result<()>
pub fn validate_for(&self, field_type: &FieldType) -> Result<()>
Check that this config is coherent with the field type carrying it (#959).
The three refusals are all cases pgvector cannot execute, and each one
fails at a different moment when it is not caught here: a float metric
on a bit(N) column is an operator that does not exist, a binary metric
on a vector(N) column is the same in reverse, and ivfflat +
jaccard is DDL CREATE INDEX rejects — pgvector 0.8 ships
bit_jaccard_ops for hnsw only.
§Errors
Returns FraiseQLError::Validation when dimensions is zero, when the
metric and the field type disagree about float versus binary vectors, or
when the index type has no operator class for the metric.
Trait Implementations§
Source§impl Clone for VectorConfig
impl Clone for VectorConfig
Source§impl Debug for VectorConfig
impl Debug for VectorConfig
Source§impl Default for VectorConfig
impl Default for VectorConfig
Source§impl<'de> Deserialize<'de> for VectorConfig
impl<'de> Deserialize<'de> for VectorConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for VectorConfig
Source§impl PartialEq for VectorConfig
impl PartialEq for VectorConfig
Source§impl Serialize for VectorConfig
impl Serialize for VectorConfig
impl StructuralPartialEq for VectorConfig
Auto Trait Implementations§
impl Freeze for VectorConfig
impl RefUnwindSafe for VectorConfig
impl Send for VectorConfig
impl Sync for VectorConfig
impl Unpin for VectorConfig
impl UnsafeUnpin for VectorConfig
impl UnwindSafe for VectorConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.