Use your own PostgreSQL
Run Lore against an existing PostgreSQL with pgvector and Chinese full-text search.
Use your own PostgreSQL when you already run a database service, need its backups, or want the database outside the Compose stack. Follow the steps below to prepare the extensions and roles, then point the stack at your database.
What Lore needs from the database
| Capability | Required | Why |
|---|---|---|
| PostgreSQL with pgvector | Yes | Memory views store embedding vectors. The first start creates the vector extension. |
| Schema privileges (create tables, indexes, and extensions) | Yes | The first start creates the schema and the extensions. |
pg_jieba | Recommended | Preferred tokenizer for Chinese full-text search. It must be preloaded. |
zhparser | Optional | Fallback Chinese tokenizer, used when pg_jieba can't be created. |
Install the extensions
-
Install pgvector for your PostgreSQL major version, following the pgvector installation guide.
-
Install
pg_jiebafor Chinese full-text search. Installzhparseras a fallback.zhparseralso needs the SCWS segmentation library. -
Preload
pg_jieba. Inpostgresql.conf, add this line. If you already preload other libraries, addpg_jiebato that comma-separated list instead:shared_preload_libraries = 'pg_jieba' -
Restart PostgreSQL. A change to the preload list takes effect only after a restart.
-
Confirm the setting:
SHOW shared_preload_libraries;
On its first start, Lore creates vector, then tries pg_jieba, then zhparser. If neither Chinese extension can be created, Lore uses PostgreSQL's simple text search. Lore still runs, but Chinese matching is weaker.
Note
The Lore image fffattiger/pgvector-zhparser:pg16 includes pgvector, pg_jieba, and zhparser. It preloads pg_jieba in new data directories. Use it unless you run your own PostgreSQL.
Create a role and a database
CREATE ROLE lore WITH LOGIN PASSWORD 'replace-with-a-long-random-password';
CREATE DATABASE lore OWNER lore;On the first start, the role must be able to create the schema and the extensions. Use a role with that permission for the first start, for example a superuser in your environment. After the first start succeeds, you can switch DATABASE_URL to a more restricted role that can work with the Lore tables.
Set DATABASE_URL
DATABASE_URL=postgresql://lore:replace-with-a-long-random-password@db.example.com:5432/lorepostgresql://andpostgres://both work.- For hosts that aren't local, Lore uses SSL by default. Add
?sslmode=disableto the URL only when the database has no TLS and the network is one you trust. - URL-encode special characters in the password. For example, write
@as%40.
Run the Compose web and Redis containers against your database
Keep the web and redis services, and point DATABASE_URL at your database. The stock file makes web wait for the bundled postgres service, so choose one of these options:
-
Keep the file as it is. The bundled
postgrescontainer still starts and Lore doesn't use it. Firewall its port (POSTGRES_PORT). -
Remove the database service. Delete the whole
postgres:service block, and delete its entry underwebindepends_on. Thewebservice then looks like this:web: depends_on: redis: condition: service_healthy
If you run an external Redis, set REDIS_URL to it and remove the redis service the same way.
Then start the stack:
docker compose up -dWarning
The CLI replaces the Compose file in ~/.lore/docker when you run update or install --docker. If the CLI manages that directory, re-apply the edit after each update, or keep your own Compose directory.
Verify
Export DATABASE_URL in your shell, or substitute the URL, then run:
curl -fsS http://127.0.0.1:18901/api/health
psql "$DATABASE_URL" -c '\dx'\dx should list vector, plus pg_jieba or zhparser if you installed them. The health check confirms that the server is running. It doesn't prove that recall works, so open /setup and finish it before you rely on recall.