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: ValueTypesDefault 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
impl Schema
pub fn update(&mut self, configuration: &InternalUpdateCollectionConfiguration)
pub fn is_sparse_index_enabled(&self) -> bool
Source§impl Schema
impl Schema
Sourcepub fn new_default(default_knn_index: KnnIndex) -> Self
pub fn new_default(default_knn_index: KnnIndex) -> Self
Create a new Schema with strongly-typed default configurations
pub fn get_internal_spann_config(&self) -> Option<InternalSpannConfiguration>
pub fn get_internal_hnsw_config(&self) -> Option<InternalHnswConfiguration>
pub fn get_internal_hnsw_config_with_legacy_fallback( &self, segment: &Segment, ) -> Result<Option<InternalHnswConfiguration>, HnswParametersFromSegmentError>
Sourcepub fn reconcile_with_defaults(
user_schema: Option<&Schema>,
knn_index: KnnIndex,
) -> Result<Self, SchemaError>
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.)
Sourcepub fn merge(&self, other: &Schema) -> Result<Schema, SchemaError>
pub fn merge(&self, other: &Schema) -> Result<Schema, SchemaError>
Merge two schemas together, combining key overrides when possible.
Sourcepub fn reconcile_with_collection_config(
schema: &Schema,
collection_config: &InternalCollectionConfiguration,
default_knn_index: KnnIndex,
) -> Result<Schema, SchemaError>
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:
- If collection config is default → return schema (schema is source of truth)
- 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
pub fn reconcile_schema_and_config( schema: Option<&Schema>, configuration: Option<&InternalCollectionConfiguration>, knn_index: KnnIndex, ) -> Result<Schema, SchemaError>
pub fn default_with_embedding_function( embedding_function: EmbeddingFunctionConfiguration, ) -> Schema
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Check if schema is default by checking each field individually
Sourcepub fn is_metadata_type_index_enabled(
&self,
key: &str,
value_type: MetadataValueType,
) -> Result<bool, SchemaError>
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
pub fn is_metadata_where_indexing_enabled( &self, where_clause: &Where, ) -> Result<(), FilterValidationError>
pub fn is_knn_key_indexing_enabled( &self, key: &str, query: &QueryVector, ) -> Result<(), FilterValidationError>
pub fn ensure_key_from_metadata( &mut self, key: &str, value_type: MetadataValueType, ) -> bool
Sourcepub fn create_index(
self,
key: Option<&str>,
config: IndexConfig,
) -> Result<Self, SchemaBuilderError>
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.Noneapplies to defaults/special keysconfig- 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())?;Sourcepub fn delete_index(
self,
key: Option<&str>,
config: IndexConfig,
) -> Result<Self, SchemaBuilderError>
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.Noneapplies to defaultsconfig- 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())?;Sourcepub fn with_cmek(self, cmek: Cmek) -> Self
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 Default for Schema
impl Default for Schema
Source§fn default() -> Self
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
impl<'de> Deserialize<'de> for Schema
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>,
Source§impl TryFrom<&InternalCollectionConfiguration> for Schema
impl TryFrom<&InternalCollectionConfiguration> for Schema
Source§type Error = SchemaError
type Error = SchemaError
Source§impl TryFrom<&Schema> for InternalCollectionConfiguration
impl TryFrom<&Schema> for InternalCollectionConfiguration
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.