The Data Layer encompasses all persistent storage mechanisms in Immich, including the PostgreSQL database with vector extensions, Redis for caching and job queuing, and the file system for storing media assets and their derivatives.
Immich's data layer consists of three primary storage systems that work together to provide efficient asset management, search capabilities, and background processing:
Kysely as the query builder server/src/repositories/search.repository.ts2 It utilizes specialized extensions for vector similarity search server/src/constants.ts22-27BullMQ server/src/repositories/config.repository.ts52-55StorageRepository server/src/app.module.ts30The following diagram bridges the high-level storage concepts with the specific code entities that manage them.
Diagram: Data Layer Entity Mapping
Sources: server/src/repositories/search.repository.ts181-182 server/src/repositories/database.repository.ts55-65 server/src/app.module.ts23-40
Immich requires PostgreSQL (version >=14.0.0) server/src/constants.ts15 It is the source of truth for all metadata, user configurations, and asset relationships.
To power "Smart Search" (semantic search) and face recognition, Immich leverages vector similarity search. It supports two primary extensions:
vchord): The preferred extension for high performance and quality docs/docs/administration/postgres-standalone.md79-81vector): Required as a prerequisite for VectorChord to provide the base vector data types docs/docs/administration/postgres-standalone.md13-15The DatabaseRepository manages these extensions, including creation, version checks, and reindexing server/src/repositories/database.repository.ts109-157
| Extension | Code Identifier | Version Range |
|---|---|---|
| pgvector | DatabaseExtension.Vector | >=0.5 <1 |
| VectorChord | DatabaseExtension.VectorChord | >=0.3 <2 |
Sources: server/src/constants.ts15-27 server/src/repositories/database.repository.ts75-97
Immich uses Kysely to interact with the database schema defined in DB server/src/schema/index.ts Key search operations are centralized in SearchRepository, which builds complex queries for metadata, random assets, and large files server/src/repositories/search.repository.ts181-265
Smart search utilizes the <=> operator for cosine distance in SQL server/src/queries/search.repository.sql93
Sources: server/src/repositories/search.repository.ts196-206 server/src/queries/search.repository.sql75-98 server/src/repositories/database.repository.ts50-53
Redis is essential for managing the asynchronous nature of photo processing.
The ConfigRepository parses Redis connection details from environment variables server/src/repositories/config.repository.ts102 It supports standard host/port configurations or a full REDIS_URL docs/docs/install/environment-variables.md70-75
Background jobs are managed via BullModule server/src/app.module.ts64
QueueName (e.g., thumbnail-generation, metadata-extraction) server/src/enum.tsIMMICH_WORKERS_INCLUDE or IMMICH_WORKERS_EXCLUDE docs/docs/install/environment-variables.md61-62Sources: server/src/repositories/config.repository.ts52-55 server/src/app.module.ts64-65
Immich stores assets on the host file system, mapped into the container.
UPLOAD_LOCATION on the host, mapped to /data inside the container docs/docs/install/environment-variables.md23-38The data layer also includes a specialized MapRepository that manages offline reverse geocoding using cities500.txt and Natural Earth data server/src/repositories/map.repository.ts8-70
Geocoding Flow:
earth_distance and earth_box on the geodata_places table server/src/repositories/map.repository.ts150-162naturalearth_countries using point-in-polygon logic server/src/repositories/map.repository.ts174-183Sources: server/src/repositories/map.repository.ts42-201 server/src/constants.ts50-51
The behavior of the data layer is heavily influenced by environment variables defined in EnvSchema server/src/repositories/config.repository.ts174
| Variable | Description | Default |
|---|---|---|
DB_URL | Full Postgres connection string | N/A |
REDIS_HOSTNAME | Redis server address | immich_redis |
UPLOAD_LOCATION | Root path for all media | N/A |
IMMICH_MEDIA_LOCATION | Internal container path for data | /data |
IMMICH_PROCESS_INVALID_IMAGES | Attempt thumbnailing for corrupt files | false |
Sources: docs/docs/install/environment-variables.md20-48 server/src/dtos/env.dto.ts
Refresh this wiki