Docs
⚙️ Configuration
Meilisearch

Setting up MeiliSearch for LibreChat

MeiliSearch is a powerful, open-source search engine that enhances LibreChat’s functionality by enabling full-text search, typo tolerance, and instant search results for past conversations.

Follow these steps to set up MeiliSearch for LibreChat:

1. Download MeiliSearch

  • Go to the MeiliSearch GitHub releases page: https://github.com/meilisearch/meilisearch/releases
  • Download the latest version of MeiliSearch for your operating system (e.g., meilisearch-linux-amd64.tar.gz for Linux, meilisearch-macos-amd64 for macOS, or meilisearch-windows-amd64.zip for Windows).

2. Extract/Install MeiliSearch

  • Linux/macOS: Extract the downloaded archive to a directory of your choice.
  • Windows: Extract the ZIP file to a directory of your choice.

3. Make the MeiliSearch Binary Executable (Linux/macOS)

  • Open a terminal and navigate to the directory where you extracted MeiliSearch.
  • Run the following command to make the binary executable:
    Make the MeiliSearch Binary Executable
    chmod +x meilisearch

4. Generate a Master Key

  • Open a terminal (or Command Prompt on Windows) and navigate to the MeiliSearch directory.
  • Run the following command to generate a Master Key:
    Generate a Master Key
    ./meilisearch --generate-master-key
  • Copy the generated Master Key as you’ll need it later.

5. Start MeiliSearch

  • In the same terminal, run the following command to start MeiliSearch, replacing <your_master_key> with the Master Key you generated in the previous step:
    Start MeiliSearch
    ./meilisearch --master-key=<your_master_key>
  • MeiliSearch will now start running on the default port (7700).

6. Update LibreChat’s Environment Variables

  • Open the .env file in the root directory of your LibreChat project.

  • Add or update the following lines with your MeiliSearch configuration:

    .env
    SEARCH=true
    MEILI_NO_ANALYTICS=true
    MEILI_HOST=http://localhost:7700
    MEILI_MASTER_KEY=<your_master_key>
  • Replace <your_master_key> with the Master Key you generated earlier.

7. Start/Restart LibreChat

  • Start or restart your LibreChat application.

That’s it! With MeiliSearch set up and configured, LibreChat should now have the Conversation search feature enabled, allowing users to perform full-text searches, benefit from typo tolerance, and experience instant search results for their past conversations.

Note: Make sure to keep the MeiliSearch process running in the background for the search functionality to work correctly. You may want to set up a script or service to keep MeiliSearch running persistently.

8. Optional: Disable Meilisearch/Database Sync in a Multi-node Setup

If you’re running LibreChat in a node cluster, or multi-node setup, and want to disable the MeiliSearch indexing sync, you can set the MEILI_NO_SYNC environment variable to true in your .env file. This will prevent your database documents from syncing redundantly across multiple LibreChat instances, which can also lead to unnecessary resource consumption, as only one instance should be responsible for indexing.

.env
MEILI_NO_SYNC=true

9. Resetting MeiliSearch Synchronization

If you encounter issues where MeiliSearch data has been deleted or corrupted, or if LibreChat believes all data has been synchronized when it hasn’t (for example, after upgrading MeiliSearch or deleting its data files), you can use the reset sync script to force a full re-synchronization.

This script resets the synchronization flags in MongoDB, which will trigger LibreChat to re-index all conversations and messages into MeiliSearch on the next startup or sync check.

Running the Reset Script

To reset MeiliSearch synchronization flags, run:
# 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"

What the Script Does

  1. Resets the _meiliIndex flag to false for all messages and conversations in MongoDB
  2. Shows you how many documents were reset and the total number of documents to be synced
  3. Provides advanced options for controlling the sync behavior

When to Use This Script

  • After deleting MeiliSearch data files
  • When upgrading MeiliSearch to a new version that requires reindexing
  • If LibreChat shows conversations as “fully synced” but MeiliSearch is missing data
  • After restoring a MongoDB backup without corresponding MeiliSearch data

Advanced Sync Options

After running the reset script, you can control the sync behavior with these environment variables:

  • MEILI_SYNC_BATCH_SIZE: Number of documents to sync per batch (default: 100)
  • MEILI_SYNC_DELAY_MS: Delay between sync batches in milliseconds (default: 100ms)
  • MEILI_SYNC_THRESHOLD: Minimum number of unsynced documents before triggering a sync (default: 1000)

Note: After resetting the sync flags, you’ll need to restart LibreChat for the re-synchronization to begin.