Schema

Struct Schema 

Source
pub struct Schema {
    pub defaults: ValueTypes,
    pub keys: HashMap<String, ValueTypes>,
    pub cmek: Option<Cmek>,
    pub source_attached_function_id: Option<String>,
}
Expand description

Schema representation for collection index configurations

This represents the server-side schema structure used for index management

Fields§

§defaults: ValueTypes

Default index configurations for each value type

§keys: HashMap<String, ValueTypes>

Key-specific index overrides TODO(Sanket): Needed for backwards compatibility. Should remove after deploy.

§cmek: Option<Cmek>

Customer-managed encryption key for collection data

§source_attached_function_id: Option<String>

ID of the attached function that created this output collection (if applicable)

Implementations§

Source§

impl Schema

Source§

impl Schema

Source

pub fn new_default(default_knn_index: KnnIndex) -> Self

Create a new Schema with strongly-typed default configurations

Source

pub fn get_internal_spann_config(&self) -> Option<InternalSpannConfiguration>

Source

pub fn get_internal_hnsw_config(&self) -> Option<InternalHnswConfiguration>

Source

pub fn get_internal_hnsw_config_with_legacy_fallback( &self, segment: &Segment, ) -> Result<Option<InternalHnswConfiguration>, HnswParametersFromSegmentError>

Source

pub fn reconcile_with_defaults( user_schema: Option<&Schema>, knn_index: KnnIndex, ) -> Result<Self, SchemaError>

Reconcile user-provided schema with system defaults

This method merges user configurations with system defaults, ensuring that:

  • User overrides take precedence over defaults
  • Missing user configurations fall back to system defaults
  • Field-level merging for complex configurations (Vector, HNSW, SPANN, etc.)
Source

pub fn merge(&self, other: &Schema) -> Result<Schema, SchemaError>

Merge two schemas together, combining key overrides when possible.

Source

pub fn reconcile_with_collection_config( schema: &Schema, collection_config: &InternalCollectionConfiguration, default_knn_index: KnnIndex, ) -> Result<Schema, SchemaError>

Reconcile Schema with InternalCollectionConfiguration

Simple reconciliation logic:

  1. If collection config is default → return schema (schema is source of truth)
  2. If collection config is non-default and schema is default → override schema with collection config

Note: The case where both are non-default is validated earlier in reconcile_schema_and_config

Source

pub fn reconcile_schema_and_config( schema: Option<&Schema>, configuration: Option<&InternalCollectionConfiguration>, knn_index: KnnIndex, ) -> Result<Schema, SchemaError>

Source

pub fn default_with_embedding_function( embedding_function: EmbeddingFunctionConfiguration, ) -> Schema

Source

pub fn is_default(&self) -> bool

Check if schema is default by checking each field individually

Source

pub fn is_metadata_type_index_enabled( &self, key: &str, value_type: MetadataValueType, ) -> Result<bool, SchemaError>

Check if a specific metadata key-value should be indexed based on schema configuration

Source

pub fn is_metadata_where_indexing_enabled( &self, where_clause: &Where, ) -> Result<(), FilterValidationError>

Source

pub fn is_knn_key_indexing_enabled( &self, key: &str, query: &QueryVector, ) -> Result<(), FilterValidationError>

Source

pub fn ensure_key_from_metadata( &mut self, key: &str, value_type: MetadataValueType, ) -> bool

Source

pub fn create_index( self, key: Option<&str>, config: IndexConfig, ) -> Result<Self, SchemaBuilderError>

Create an index configuration (builder pattern)

This method allows fluent, chainable configuration of indexes on a schema. It matches the Python API’s .create_index() method.

§Arguments
  • key - Optional key name for per-key index. None applies to defaults/special keys
  • config - Index configuration to create
§Returns

Self for method chaining

§Errors

Returns error if:

  • Attempting to create index on special keys (#document, #embedding)
  • Invalid configuration (e.g., vector index on non-embedding key)
  • Conflicting with existing indexes (e.g., multiple sparse vector indexes)
§Examples
use chroma_types::{Schema, VectorIndexConfig, StringInvertedIndexConfig, Space, SchemaBuilderError};

let schema = Schema::default()
    .create_index(None, VectorIndexConfig {
        space: Some(Space::Cosine),
        embedding_function: None,
        source_key: None,
        hnsw: None,
        spann: None,
    }.into())?
    .create_index(Some("category"), StringInvertedIndexConfig {}.into())?;
Source

pub fn delete_index( self, key: Option<&str>, config: IndexConfig, ) -> Result<Self, SchemaBuilderError>

Delete/disable an index configuration (builder pattern)

This method allows disabling indexes on a schema. It matches the Python API’s .delete_index() method.

§Arguments
  • key - Optional key name for per-key index. None applies to defaults
  • config - Index configuration to disable
§Returns

Self for method chaining

§Errors

Returns error if:

  • Attempting to delete index on special keys (#document, #embedding)
  • Attempting to delete vector, FTS, or sparse vector indexes (not currently supported)
§Examples
use chroma_types::{Schema, StringInvertedIndexConfig, SchemaBuilderError};

let schema = Schema::default()
    .delete_index(Some("category"), StringInvertedIndexConfig {}.into())?;
Source

pub fn with_cmek(self, cmek: Cmek) -> Self

Set customer-managed encryption key for the collection (builder pattern)

This method allows setting CMEK on a schema for fluent, chainable configuration.

§Arguments
  • cmek - Customer-managed encryption key configuration
§Returns

Self for method chaining

§Examples
use chroma_types::{Schema, Cmek};

let schema = Schema::default()
    .with_cmek(Cmek::gcp("projects/my-project/locations/us/keyRings/my-ring/cryptoKeys/my-key".to_string()));

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Self

Create a default Schema that matches Python’s behavior exactly.

Python creates a Schema with:

  • All inverted indexes enabled by default (string, int, float, bool)
  • Vector and FTS indexes disabled in defaults
  • Special keys configured: #document (FTS enabled) and #embedding (vector enabled)
  • Vector config has space=None, hnsw=None, spann=None (deferred to backend)
§Examples
use chroma_types::Schema;

let schema = Schema::default();
assert!(schema.keys.contains_key("#document"));
assert!(schema.keys.contains_key("#embedding"));
Source§

impl<'de> Deserialize<'de> for Schema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Schema

Source§

fn eq(&self, other: &Schema) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Schema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&InternalCollectionConfiguration> for Schema

Source§

type Error = SchemaError

The type returned in the event of a conversion error.
Source§

fn try_from( config: &InternalCollectionConfiguration, ) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Schema> for InternalCollectionConfiguration

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

fn try_from(schema: &Schema) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for Schema

Auto Trait Implementations§

§

impl Freeze for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnwindSafe for Schema

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T