Skip to main content

Schema

Struct Schema 

Source
pub struct Schema {
    pub defaults: ValueTypes,
    pub keys: HashMap<String, ValueTypes>,
    pub cmek: Option<Cmek>,
}
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

Implementations§

Source§

impl Schema

Source

pub fn update(&mut self, configuration: &InternalUpdateCollectionConfiguration)

Source

pub fn apply_update_configuration( &mut self, config: &UpdateCollectionConfiguration, ) -> Result<(), SchemaError>

Apply updates from UpdateCollectionConfiguration.

Only supports updating:

  • spann: SPANN configuration parameters (search_nprobe, ef_search)
  • embedding_function: Embedding function configuration

Returns an error if:

  • hnsw is provided (HNSW updates are not supported)
  • Schema is missing expected structure (defaults/embedding vector index or spann config)
Source

pub fn is_sparse_index_enabled(&self) -> bool

Source

pub fn is_maxscore_enabled(&self) -> bool

Check if any sparse index is configured to use MaxScore.

Source

pub fn enabled_sparse_keys(&self) -> Vec<String>

Metadata keys that have an enabled sparse vector index, in sorted order for deterministic iteration. Each key owns one independent sparse index.

Source

pub fn is_key_maxscore_enabled(&self, key: &str) -> bool

Whether the sparse index on a specific metadata key uses MaxScore. Falls back to the schema defaults when the key has no explicit config. Defaults to WAND (false) when nothing is configured.

Source

pub fn set_sparse_algorithm(&mut self, algorithm: SparseIndexAlgorithm)

Set the sparse index algorithm on all sparse index configs (defaults and every key-specific config).

Source

pub fn is_fts_enabled(&self) -> bool

Source

pub fn is_token_bitmap_fts_enabled(&self) -> bool

Check if the FTS index is configured to use TokenBitmap.

Source

pub fn set_fts_algorithm(&mut self, algorithm: FtsAlgorithm)

Set the FTS index algorithm on all FTS index configs (defaults and every key-specific config).

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 new_record_only() -> Self

Create a record-only Schema with all indexing disabled.

Suitable for output collections that are never queried via vector search, metadata filtering, or full-text search Records are stored but no inverted, vector, FTS, or sparse indexes are built at query-planning time.

Source

pub fn get_spann_config(&self) -> Option<(SpannIndexConfig, Space)>

Source

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

Source

pub fn is_quantization_enabled(&self) -> bool

Check if quantization is enabled in the SPANN index configuration

Source

pub fn get_spann_config_mut(&mut self) -> Option<&mut SpannIndexConfig>

Get a mutable reference to the SPANN index configuration Checks the #embedding key first, then falls back to defaults

Source

pub fn quantize(&mut self, variant: Quantization)

Set the quantization variant and apply impl-specific SPANN config defaults. Note: this intentionally skips SpannIndexConfig::validate() because the hardcoded quantization defaults (e.g. split_threshold=512) exceed the user-facing validation ranges. Those ranges gate user input only; programmatic defaults set here are known-good constants.

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_key_unindexed( &self, key: &str, value_type: MetadataValueType, ) -> bool

Returns true if the inverted index is disabled for the given key and value type. Used to determine if the larger document size quota should apply for unindexed fields.

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 (const: unstable) · Source§

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 (const: unstable) · Source§

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 StructuralPartialEq for Schema

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

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

Source§

impl<T> From<T> for T

Source§

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
Source§

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

Source§

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<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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.
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
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