Skip to main content
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

schema
OramaSchema
required
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'
}
sort
SorterConfig
Configuration for sorting functionality.
language
string
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.
components
Components
Custom components to replace default implementations.
plugins
OramaPlugin[]
Array of plugins to extend Orama functionality.Plugins can provide custom components and hooks for various database operations.
id
string
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.

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']
  }
})
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

Build docs developers (and LLMs) love