Layer 5: Storage
Persistent storage for face embeddings and attendance logs
The Storage Layer provides persistent storage for face embeddings and attendance records.
Overview
- Purpose: Persist face embeddings and attendance records
- Database: PostgreSQL with pgvector extension
- Data: Face embeddings, attendance records, unknown faces
PostgreSQL with pgvector
The system uses PostgreSQL as the primary database with the pgvector extension for efficient vector similarity search.
| Feature | Benefit |
|---|---|
| ACID Compliance | Reliable data integrity |
| pgvector Extension | Fast 512-d embedding search |
| JSON Support | Flexible configuration storage |
| Indexing | Efficient query performance |
Data Schema
Person Table
Store enrolled persons with their face embeddings.
| Field | Type | Description |
|---|---|---|
| ID | UUID | Unique identifier |
| Employee ID | String | External identifier |
| First Name | String | Person's first name |
| Last Name | String | Person's last name |
| String | Contact email | |
| Department | String | Organization unit |
| Enrolled At | Timestamp | Enrollment date |
| Is Active | Boolean | Active status |
Face Embeddings Table
Store face embeddings for recognition.
| Field | Type | Description |
|---|---|---|
| ID | UUID | Unique identifier |
| Person ID | UUID | Reference to person |
| Embedding | Vector(512) | Face embedding |
| Created At | Timestamp | Creation date |
Attendance Table
Store attendance records.
| Field | Type | Description |
|---|---|---|
| ID | UUID | Unique identifier |
| Person ID | UUID | Reference to person |
| Camera ID | String | Source camera |
| Timestamp | DateTime | Attendance time |
| Confidence | Float | Recognition confidence |
| Snapshot Path | String | Path to face snapshot |
Camera Table
Store camera configuration.
| Field | Type | Description |
|---|---|---|
| ID | String | Camera identifier |
| Name | String | Display name |
| Location | String | Physical location |
| Stream URL | String | Video stream URL |
| Is Active | Boolean | Active status |
Database Operations
Core Functions
| Operation | Description |
|---|---|
| Add Person | Register new person in system |
| Add Embedding | Store face embedding for person |
| Find Similar | Search for matching faces |
| Log Attendance | Record attendance entry |
| Get Report | Query attendance data |
Vector Search
PostgreSQL with pgvector enables fast similarity search:
- HNSW indexing for efficient nearest neighbor search
- Cosine similarity for face matching
- Optimized for 512-dimensional embeddings
Configuration
PostgreSQL Settings
| Setting | Description |
|---|---|
| Host | PostgreSQL server address |
| Port | Database port (default: 5432) |
| Database | Database name |
| User | Connection username |
| Password | Connection password |
| Pool Size | Connection pool size |
Backup and Recovery
Backup Strategy
| Component | Method | Frequency |
|---|---|---|
| Face Embeddings | pg_dump | Daily |
| Attendance Records | pg_dump | Daily |
| Full Database | pg_dump | Weekly |
Data Retention
Consider policies for:
- Archiving old attendance records
- Cleaning up temporary data
- Snapshot image management
Performance Optimization
Indexing Strategy
Create indexes for:
- Person lookups by employee ID
- Attendance queries by date
- Active person filtering
- Vector similarity search
Connection Pooling
Use connection pooling for production:
- Reduces connection overhead
- Manages concurrent access
- Improves response times
Summary
The Storage Layer provides:
- Person Management - Store enrolled persons and face embeddings
- Attendance Logging - Record attendance with timestamps
- Vector Search - Fast face matching capability
- Reporting - Query attendance data for reports
.png)