AI

Although AI is not ready for selfhost using, you can still enable the AI features by importing AI config to your server.

Enable AI in self-hosted AFFiNE

create a config.json and put it under $CONFIG_LOCATION you set in your .env file. Remember to restart the containers to make the config taking effects.

config.json
{
  "$schema": "https://github.com/toeverything/affine/releases/latest/download/config.schema.json",
  "copilot": {
    "enabled": true,
    "providers.openai": {
      "apiKey": "your key",
      "baseUrl": "open-ai-compatitable.example.com"
    }
  }
}

The above only demonstrate you to set openai provider.

If you prefer using other ai providers, checkout this discussion.

Embedding

Starting from version 0.21, AFFiNE added support for AI doc embedding, which requires PostgreSQL vector extension, and pgvector was choosen.

You need to update the images used in compose.yml or manually install pgvector extension to your own Postgres server if you use standalone one.

Prepare

::: wanring BACKUP!

Do backup before any database regarding updates.

:::

Backup data

  • Perform a full backup of the PostgreSQL database to ensure data can be recovered in case of issues during the upgrade. Learn how to do the backup.

Stop existing services

  • Stop running services using the Docker Compose command:
docker compose -f compose.yml down
  • Confirm that all relevant containers have stopped running to avoid data write conflicts.

Update container

Download the latest compose.yml file

wget -O compose.yml \
  https://github.com/toeverything/AFFiNE/releases/latest/download/docker-compose.yml

Update docker compose to use pgvector

Major version match

Be noticed that the major version of replacer pgvector/pgvector:pg{version} must be the same as old postgres image postgres:{version}

compose.yml
services:
  # ...
  postgres:
    image: postgres:16 
    image: pgvector/pgvector:pg16 
  #...

Pull the new image and start the service

# pull the latest image
docker compose -f compose.yml pull
# start service
docker compose -f compose.yml up -d