docs/mintlify/cloud/schema/overview.mdx
import { Callout } from '/snippets/callout.mdx';
Schema enables fine-grained control over index configuration on collections. Control which indexes are created, optimize for your workload, and enable advanced capabilities like hybrid search.
Schema allows you to configure which indexes are created for different data types in your Chroma collections. You can enable or disable indexes globally or per-field, configure vector index parameters, and set up sparse vector indexes for keyword-based search.
Here's a simple example creating a collection with a custom schema:
<CodeGroup> ```python Python import chromadb from chromadb import Schema, StringInvertedIndexConfigclient = chromadb.CloudClient( tenant="your-tenant", database="your-database", api_key="your-api-key" )
schema = Schema() schema.delete_index(config=StringInvertedIndexConfig())
collection = client.create_collection( name="my_collection", schema=schema )
collection.add( ids=["id1", "id2"], documents=["Document 1", "Document 2"], metadatas=[ {"category": "science", "year": 2024}, {"category": "tech", "year": 2023} ] )
try: collection.query( query_texts=["query"], where={"category": "science"} # Error: string index is disabled ) except Exception as e: print(f"Error: {e}")
```typescript TypeScript
import { CloudClient, Schema, StringInvertedIndexConfig } from 'chromadb';
// Connect to Chroma Cloud
const client = new CloudClient({
tenant: "your-tenant",
database: "your-database",
apiKey: "your-api-key"
});
// Create a schema and disable string indexing globally
const schema = new Schema();
schema.deleteIndex(new StringInvertedIndexConfig());
// Create collection with the schema
const collection = await client.createCollection({
name: "my_collection",
schema: schema
});
// Add data - string metadata won't be indexed
await collection.add({
ids: ["id1", "id2"],
documents: ["Document 1", "Document 2"],
metadatas: [
{ category: "science", year: 2024 },
{ category: "tech", year: 2023 }
]
});
// Querying on disabled index will raise an error
try {
await collection.query({
queryTexts: ["query"],
where: { category: "science" } // Error: string index is disabled
});
} catch (e) {
console.log(`Error: ${e}`);
}