Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Meilisearch

Set up Meilisearch to enable conversation search in LibreChat

Meilisearch is an open-source search engine that powers LibreChat's conversation search, adding full-text search, typo tolerance, and instant results across past conversations. For a feature overview, see Search in LibreChat.

How it connects

LibreChat talks to Meilisearch over HTTP using a few environment variables. The Docker setup ships Meilisearch as a service for you. A source install points LibreChat at a Meilisearch process you run yourself.

Configure Meilisearch

The default docker-compose.yml already includes a meilisearch service, so you only need to enable search and set a master key in your .env file.

Generate a master key. Use any sufficiently long, random string (16 bytes or more). For example:

openssl rand -base64 32

Add the search variables to .env. The Compose file sets MEILI_HOST to the internal service address for the api container, so you don't set the host here. Keep the master key identical to the one the meilisearch service uses.

SEARCH=true
MEILI_NO_ANALYTICS=true
MEILI_MASTER_KEY=<your_master_key>

Pass the master key to the Meilisearch service. The bundled meilisearch service does not read .env, so add it through docker-compose.override.yml. This keeps both LibreChat and Meilisearch using the same key.

services:
  meilisearch:
    environment:
      - MEILI_MASTER_KEY=${MEILI_MASTER_KEY}

See Docker Override for how override files are merged.

Start the stack. Compose merges the override automatically and starts Meilisearch alongside LibreChat.

docker compose up -d

Keep the port internal

Containers reach Meilisearch over the internal Docker network, so there is no need to publish port 7700 to the host. Exposing it publicly can leave your search data vulnerable.

Once configured, LibreChat indexes conversations and messages into Meilisearch, and the search bar returns full-text results with typo tolerance.

Environment Variables

VariableDescription
SEARCHEnables the conversation search feature. Set to true.
MEILI_HOSTURL where LibreChat reaches Meilisearch. In Docker this is http://meilisearch:7700 (set by Compose); from source it is typically http://localhost:7700.
MEILI_MASTER_KEYShared secret used to authenticate with Meilisearch. Must match the key Meilisearch starts with.
MEILI_NO_ANALYTICSDisables Meilisearch's anonymous telemetry. Set to true.
MEILI_NO_SYNCSee multi-node setups.

Disable Sync in a Multi-node Setup

If you run LibreChat as a node cluster or multi-node deployment, set MEILI_NO_SYNC to true so only one instance handles indexing. This prevents redundant syncing of database documents across instances and the unnecessary resource use that comes with it.

MEILI_NO_SYNC=true

Reset Synchronization

If Meilisearch data is deleted or corrupted, or LibreChat treats everything as synced when it isn't (for example after upgrading Meilisearch or deleting its data files), use the reset script to force a full re-sync. It resets the synchronization flags in MongoDB, which triggers LibreChat to re-index all conversations and messages on the next startup or sync check.

Run the reset script. Use the command that matches your setup.

# Local development
npm run reset-meili-sync
 
# Docker (default setup)
docker compose exec api npm run reset-meili-sync
 
# Docker (deployment setup)
docker exec -it LibreChat-API /bin/sh -c "cd .. && npm run reset-meili-sync"

Restart LibreChat. Re-synchronization begins once the app restarts.

The script resets the _meiliIndex flag to false for all messages and conversations in MongoDB, then reports how many documents were reset and how many remain to be synced.

When to use it:

  • After deleting Meilisearch data files
  • When upgrading Meilisearch to a version that requires reindexing
  • When LibreChat shows conversations as fully synced but Meilisearch is missing data
  • After restoring a MongoDB backup without matching Meilisearch data

Advanced sync options. After resetting, control the sync behavior with these environment variables:

VariableDefaultDescription
MEILI_SYNC_BATCH_SIZE100Number of documents synced per batch.
MEILI_SYNC_DELAY_MS100Delay between sync batches, in milliseconds.
MEILI_SYNC_THRESHOLD1000Minimum number of unsynced documents before a sync is triggered.

How is this guide?