pub struct VectorStoreCollectionDefinition { /* private fields */ }Expand description
The shape of one vector-store collection: its fields, and the accessors a provider needs to build requests from them.
fields is private and every constructor validates, including
deserialization: Self::key_field and friends are documented as
infallible, and they can only honour that if an invalid definition cannot
exist. A definition loaded from configuration goes through the same checks
as one built in code, so a missing key field is a deserialization error
rather than a panic at first use.
Implementations§
Source§impl VectorStoreCollectionDefinition
impl VectorStoreCollectionDefinition
Sourcepub fn new(
fields: Vec<VectorStoreField>,
) -> Result<VectorStoreCollectionDefinition, Error>
pub fn new( fields: Vec<VectorStoreField>, ) -> Result<VectorStoreCollectionDefinition, Error>
Build and validate a definition.
Validation is at construction rather than at first use because every
failure it catches — no key, two keys, duplicate names, a vector field
with no dimensions — produces a collection that cannot work at all,
and a provider would otherwise surface it as an opaque error from the
service on the first upsert. Mirrors upstream’s _validate.
Sourcepub fn fields(&self) -> &[VectorStoreField]
pub fn fields(&self) -> &[VectorStoreField]
The declared fields, in declaration order.
Read-only: mutating them could invalidate the definition, which the
infallible accessors below rely on not happening. Build a new
definition with Self::new instead.
Sourcepub fn try_get_field(&self, name: &str) -> Option<&VectorStoreField>
pub fn try_get_field(&self, name: &str) -> Option<&VectorStoreField>
The field declared under name, or None when the collection has no
such field.
Lookup is by logical name, which is what a
filters::Filter carries.
Sourcepub fn storage_name_for(&self, name: &str) -> Option<String>
pub fn storage_name_for(&self, name: &str) -> Option<String>
Map a logical field name onto the storage name a record is keyed by,
for FilterExpression::matches.
Returns None for a field the collection does not declare, which
matches reports as an error rather than a non-match.
Sourcepub fn storage_names(&self) -> Vec<&str>
pub fn storage_names(&self) -> Vec<&str>
Every storage name, in declaration order.
Sourcepub fn key_field(&self) -> &VectorStoreField
pub fn key_field(&self) -> &VectorStoreField
The key field. Infallible: Self::new rejects a definition without
exactly one.
Sourcepub fn key_field_storage_name(&self) -> &str
pub fn key_field_storage_name(&self) -> &str
The key field’s storage name.
Sourcepub fn vector_fields(&self) -> Vec<&VectorStoreField>
pub fn vector_fields(&self) -> Vec<&VectorStoreField>
Every vector field.
Sourcepub fn data_fields(&self) -> Vec<&VectorStoreField>
pub fn data_fields(&self) -> Vec<&VectorStoreField>
Every data field.
Sourcepub fn try_get_vector_field(
&self,
name: Option<&str>,
) -> Option<&VectorStoreField>
pub fn try_get_vector_field( &self, name: Option<&str>, ) -> Option<&VectorStoreField>
Look up a vector field by name, or the only one when name is None.
Returns None when the name does not match a vector field, and also
when name is None and the collection has several — there is no
safe default to pick, and searching the wrong embedding returns
confident nonsense rather than an error.
Sourcepub fn get_names(
&self,
include_vector_fields: bool,
include_key_field: bool,
) -> Vec<&str>
pub fn get_names( &self, include_vector_fields: bool, include_key_field: bool, ) -> Vec<&str>
Field names, filtered. Mirrors upstream’s get_names.
Sourcepub fn get_storage_names(
&self,
include_vector_fields: bool,
include_key_field: bool,
) -> Vec<&str>
pub fn get_storage_names( &self, include_vector_fields: bool, include_key_field: bool, ) -> Vec<&str>
Storage names, filtered. Mirrors upstream’s get_storage_names.
Sourcepub fn to_storage(&self, record: &Value) -> Result<Value, Error>
pub fn to_storage(&self, record: &Value) -> Result<Value, Error>
Rename a record’s fields from logical names to storage names.
Fields the definition does not declare are dropped rather than passed through, so a stray key cannot reach the store and be rejected (or, worse, silently persisted outside the schema).
Trait Implementations§
Source§impl Clone for VectorStoreCollectionDefinition
impl Clone for VectorStoreCollectionDefinition
Source§fn clone(&self) -> VectorStoreCollectionDefinition
fn clone(&self) -> VectorStoreCollectionDefinition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more