Schema Basics
Learn how to create and use Schema to configure indexes on your Chroma collections.Schema Structure
A Schema has two main components that work together to control indexing behavior:Defaults
Defaults define index configuration for all keys of a given data type. When you add metadata to your collection, Chroma looks at the value type (string, int, float, etc.) and applies the default index configuration for that type. For example, if you disable string inverted indexes globally, no string metadata fields will be indexed unless you create a key-specific override.Keys
Keys define index configuration for specific metadata fields. These override the defaults for individual fields, giving you fine-grained control. For example, you might disable string indexing globally but enable it specifically for a “category” field that you frequently filter on.How They Work Together
When determining whether to index a field, Chroma follows this precedence:- Key-specific configuration (if exists) - highest priority
- Default configuration (for that value type) - fallback
- Built-in defaults (if no Schema provided) - final fallback
Default Index Behavior
Without providing a Schema, collections use built-in defaults for indexing. For a complete overview of all value types, index types, and their defaults, see the Index Configuration Reference.Special Keys
Chroma uses two reserved key names:K.DOCUMENT (#document) stores document text content with FTS enabled and String Inverted Index disabled. This allows full-text search while avoiding redundant indexing.
K.EMBEDDING (#embedding) stores dense vector embeddings with Vector Index enabled, sourcing from K.DOCUMENT. This enables semantic similarity search.
Use
K.DOCUMENT and K.EMBEDDING in your code (they correspond to internal keys #document and #embedding). These special keys are automatically configured and cannot be manually modified. See the Search API field reference for more details.Example: Using Defaults
Creating Schema Objects
Create a Schema object to customize index configuration:Creating Indexes
The create_index() Method
Usecreate_index() to enable or configure indexes. The method takes:
config: An index configuration object (orNoneto enable all indexes for a key)key: Optional - specify a metadata field name for key-specific configuration
Creating Global Indexes
Create indexes that apply globally. This example shows configuring the vector index with custom settings:Creating Key-Specific Indexes
Configure indexes for specific metadata fields. This example shows configuring the sparse vector index with custom settings:This example uses
ChromaCloudSpladeEmbeddingFunction, but you can use other sparse embedding functions like HuggingFaceSparseEmbeddingFunction or FastembedSparseEmbeddingFunction depending on your needs.Disabling Indexes
The delete_index() Method
Usedelete_index() to disable indexes. Like create_index(), it takes:
config: An index configuration object (orNoneto disable all indexes for a key)key: Optional - specify a metadata field name for key-specific configuration
Examples
Method Chaining
Bothcreate_index() and delete_index() return the Schema object, enabling fluent method chaining:
Using Schema with Collections
Pass the configured schema tocreate_collection() or get_or_create_collection():
Schema Persistence
Schema configuration is automatically saved with the collection. When you retrieve a collection withget_collection() or get_or_create_collection(), the schema is loaded automatically. You don’t need to provide the schema again.
Next Steps
- Set up sparse vector search with sparse vectors
- Browse the complete index configuration reference