Creates and initializes a new Orama database instance with the specified schema and configuration.
Function Signature
function create <
OramaSchema extends AnySchema ,
TIndex = IIndex < Index >,
TDocumentStore = IDocumentsStore < DocumentsStore >,
TSorter = ISorter < Sorter >,
TPinning = any
>({
schema ,
sort ,
language ,
components ,
id ,
plugins
} : CreateArguments < OramaSchema , TIndex , TDocumentStore , TSorter , TPinning >) : Orama <
OramaSchema ,
TIndex ,
TDocumentStore ,
TSorter ,
TPinning
>
Parameters
The schema definition for the database. Defines the structure and types of documents that can be stored. {
title : 'string' ,
description : 'string' ,
price : 'number' ,
categories : 'string[]' ,
rating : 'number'
}
Configuration for sorting functionality. Whether sorting is enabled for this database. Default: true
Array of property names that should not be sortable.
The language to use for tokenization and stemming. Default: 'english' Cannot be used together with a custom tokenizer in components. Examples: 'english', 'spanish', 'french', 'italian', etc.
Custom components to replace default implementations. tokenizer
Tokenizer | DefaultTokenizerConfig
Custom tokenizer or tokenizer configuration.
Custom index implementation.
Custom documents store implementation.
Custom sorter implementation.
Custom pinning implementation.
getDocumentIndexId
(doc: AnyDocument) => string
Custom function to extract document ID.
getDocumentProperties
(doc: AnyDocument, paths: string[]) => Record<string, any>
Custom function to extract document properties.
validateSchema
(doc: AnyDocument, schema: OramaSchema) => string | undefined
Custom schema validation function.
formatElapsedTime
(time: bigint) => ElapsedTime
Custom time formatting function.
Array of plugins to extend Orama functionality. Plugins can provide custom components and hooks for various database operations.
Custom ID for the database instance. If not provided, a unique ID will be generated automatically.
Return Value
Orama
Orama<OramaSchema, TIndex, TDocumentStore, TSorter, TPinning>
A fully initialized Orama database instance ready to accept documents and perform searches. The schema definition for the database.
Internal data structures for index, documents, sorting, and pinning.
The tokenizer instance used for text processing.
The index implementation.
The documents store implementation.
The sorter implementation.
The unique identifier for this database instance.
Examples
Basic Usage
import { create } from '@orama/orama'
const db = await create ({
schema: {
title: 'string' ,
description: 'string' ,
price: 'number' ,
inStock: 'boolean'
}
})
With Language Configuration
import { create } from '@orama/orama'
const db = await create ({
schema: {
titulo: 'string' ,
descripcion: 'string'
},
language: 'spanish'
})
With Sorting Configuration
import { create } from '@orama/orama'
const db = await create ({
schema: {
title: 'string' ,
price: 'number' ,
rating: 'number' ,
internal_id: 'string'
},
sort: {
enabled: true ,
unsortableProperties: [ 'internal_id' ]
}
})
With Vector Search
import { create } from '@orama/orama'
const db = await create ({
schema: {
title: 'string' ,
description: 'string' ,
embedding: 'vector[1536]'
}
})
With Plugins
import { create } from '@orama/orama'
import { pluginSecureProxy } from '@orama/plugin-secure-proxy'
const db = await create ({
schema: {
title: 'string' ,
embedding: 'vector[1536]'
},
plugins: [
await pluginSecureProxy ({
apiKey: 'your-api-key' ,
defaultProperty: 'embedding'
})
]
})
With Custom Components
import { create } from '@orama/orama'
const db = await create ({
schema: {
title: 'string' ,
description: 'string'
},
components: {
tokenizer: {
language: 'english' ,
stemming: true ,
stopWords: true
},
getDocumentIndexId : ( doc ) => doc . customId || doc . id
}
})
Error Handling
The create function may throw errors in the following cases:
COMPONENT_MUST_BE_FUNCTION : When a component is provided but is not a function
UNSUPPORTED_COMPONENT : When an unsupported component key is provided
PLUGIN_COMPONENT_CONFLICT : When a plugin tries to override a component that is already defined
NO_LANGUAGE_WITH_CUSTOM_TOKENIZER : When both language and a custom tokenizer are provided
try {
const db = await create ({
schema: { title: 'string' },
language: 'english' ,
components: {
tokenizer: customTokenizer // Error: cannot specify both
}
})
} catch ( error ) {
console . error ( 'Failed to create database:' , error )
}
Notes
The schema cannot be modified after the database is created
Component conflicts between plugins and manual configuration will throw errors
The afterCreate hooks from plugins are executed after the database is fully initialized
All internal data structures (index, documents store, sorter, pinning) are created during initialization