# Keystone — Open-Source Local AI Key for UniFi Protect # Copy to config.yaml and edit controller.host + vision.base_url. state_dir: /state log_level: INFO controller: host: 192.168.1.1 trusted_peers: [] # Extra Protect source IPs/CIDRs (NAT, or a console routing Keystone's VLAN). Docker: KEYSTONE_CONTROLLER_TRUSTED_PEERS control_port: 7442 search_port: 7443 media_port: 7444 control_profile: device-service # "device-service" for Protect 7.3+, "ucp4" for strict subprotocol auto_pin_tls: true # Pins Protect's TLS SHA-256 certs on first connect # api_key: "" # Optional Protect integration key for paired camera names # api_fingerprint: "" # Optional SHA-256 pin for the console's HTTPS certificate on TCP 443 device: # enabled: true # Set false for a standalone AI-Port-only instance (no AI Key or PostgreSQL) hostname: keystone mgmt_port: 8080 discovery_enabled: true username: ubnt password: ubnt # Initial adoption password (Protect rotates it on adoption) sync_postgres_password: false # Sync rotated password to PostgreSQL 'unifi-protect' role (for Find Anything) # postgres_admin_url: postgresql://postgres:keystone@127.0.0.1:5432/postgres # Used with docker-compose pgvector service aiport: enabled: false # Enable built-in virtual UP AI PORT X (0xa5f5) for ONVIF cameras hostname: keystone-aiport mgmt_port: 443 # Protect hardcodes TCP 443 for AI Port adoption; move conflicting host services off 443 or use a dedicated LAN IP restream_tls: false # Pull paired UniFi cameras from Protect's RTSPS restream (TCP 7441) instead of plain RTSP (7447) # bind_host: "" # Optional dedicated IP to bind :443 (defaults to device.bind_host) # advertise_ip: "" # Optional dedicated LAN IP advertised to Protect (defaults to device.advertise_ip) detector_variant: yolox_m # yolox_tiny (416px) | yolox_s / yolox_m / yolox_l (640px) detector_threads: 2 detect_fps: 1.0 # camera_clock: ALL # Experimental: ALL or one camera device ID analyze_max_width: 960 # Analyzer frame width cap (never upscales, min 320); 640 saves CPU on small hosts snapshot_max_width: 1920 # Width snapshots are cropped from (never upscales); at or below analyze_max_width (or 0), analyzer frames are used confidence_threshold: 0.55 # Minimum YOLOX score (0.55 reduces IR-night foliage/shadow false positives) stationary_timeout_seconds: 12.0 # People and animals that have moved can pause for twice this long # Optional: keep an event open after everything leaves view, for a return in the same colors at the # spot or frame edge it left by. Seconds from last sighting (0 disables, max 60). Try 25 for a path # that passes below the camera. Similar clothes at the same entrance can be grouped together; under # infrared a return starts a new event. This delays finalization of every event that ends this way. reentry_seconds: 0 # Speech detection (Protect alrmSpeak / EventSmartAudio) with the ~2 MB MIT Silero VAD model. # Unlocks Protect's speech detection + native Speech-to-Text for audio-capable paired cameras. # Nothing runs (no audio ffmpeg, no model download) until Protect enables speech or audio alarm # detection for a camera with a microphone; then one shared 16 kHz audio decoder runs per camera. audio_vad_enabled: true audio_vad_model_dir: "" # Defaults to /models/silero-vad audio_vad_auto_download: true # Fetch the pinned, SHA-256-verified model on first use audio_vad_threads: 1 # One shared ONNX session for all cameras audio_vad_threshold: 0.55 # Speech probability needed to start (and keep, minus 0.15) an event audio_vad_min_speech_ms: 600 # Sustained speech before "enter" (start time is backdated by this) audio_vad_hangover_ms: 2000 # Silence that ends a speech event audio_vad_max_event_seconds: 90 # Split very long conversations into separate events audio_vad_min_dbfs: -45.0 # Noise-floor gate (dBFS; -90 disables) skipping quiet mic hiss audio_vad_yamnet_verify: true # Confirm Silero VAD candidates with YAMNet (rejects birds/animals/wind) audio_vad_yamnet_threshold: 0.20 # Minimum YAMNet human-speech score required to confirm alrmSpeak # Smart Audio alarms (bark, baby cry, smoke, CO, siren, burglar/car alarm, car horn, glass break) # via the ~16 MB Apache-2.0 Google YAMNet ONNX model. Shares the same 16 kHz PCM stream as Silero # VAD and loads lazily when Protect enables an audio alarm or when confirming a Silero speech candidate. audio_alarms_enabled: true audio_alarms_model_dir: "" # Defaults to /models/yamnet audio_alarms_auto_download: true # Fetch the pinned, SHA-256-verified model on first use audio_alarms_threads: 1 # One shared ONNX session for all cameras audio_alarms_threshold: 0.35 # Baseline alarm score threshold (per-alarm rules adjust for CO/horn/glass) audio_alarms_hop_ms: 480 # Sliding hop (ms) across the 975 ms YAMNet window audio_alarms_hangover_ms: 3500 # Quiet time before ending an active alarm event audio_alarms_cooldown_ms: 5000 # Per-alarm cooldown after an event closes audio_alarms_max_event_seconds: 90 audio_alarms_min_dbfs: -42.0 # Noise-floor gate (dBFS; -90 disables) skipping silent YAMNet windows flv_audio_header_timeout: 15 # Initial FLV audio header wait (s) before video-only fallback (retried on reconnect) # Native Protect Package Detection ("package" + "packageMaincam") via Apache-2.0 D-FINE Small # Objects365 ONNX (~11 MB int8) + optional zero-shot CLIP verification. Lazy: nothing downloads # or loads until Protect enables Package Detection for at least one paired camera. package_enabled: true package_quantization: int8 # int8 (~11 MB, default) | fp16 (~21 MB) | fp32 (~42 MB) package_model_dir: "" # Defaults to /models/dfine-package package_auto_download: true # Fetch the pinned, SHA-256-verified ONNX weights on first use package_confidence_threshold: 0.45 # Minimum D-FINE Objects365 Storage box score (+0.10 without CLIP) package_clip_verify: true # Confirm candidate crops with shared CLIP (rejects bins/planters/chairs) package_clip_min_margin: 0.02 # Required CLIP positive-vs-negative cosine margin package_scan_interval_seconds: 2.0 # Minimum seconds between scans per camera during motion/activity package_threads: 2 # Shared ONNX CPU threads for D-FINE package inference vision: provider: ollama # ollama | openai | openai-compatible | anthropic | disabled base_url: http://192.0.2.20:11434 # Address of your Ollama server (or http://127.0.0.1:11434 if local) model: qwen3.5:9b # Any vision-capable model (e.g. qwen3.5:9b, qwen3.5:4b, gpt-4o) language: "" # Caption and AI Summary language (e.g. French). Empty, English, or en uses the default. # Override with KEYSTONE_VISION_LANGUAGE. Structured fields stay English. # For oMLX, LM Studio, or another OpenAI-compatible server, set provider to openai-compatible, # use its API base URL (e.g. http://192.0.2.20:1234/v1), and set model to the served model ID. # api_key: "${MY_VISION_KEY}" # Supply this variable in the service environment if auth is required # extra_body: # Optional request fields for openai and openai-compatible # reasoning_effort: "none" # Disable reasoning on servers that support it # chat_template_kwargs: {enable_thinking: false} # On servers that support this option # response_format: null # Skip requesting JSON mode keep_alive: 30m timeout_seconds: 75 max_tokens: 220 reasoning_first: false # Start with the reasoning budget on known reasoning models reasoning_max_tokens: 2048 # Retry budget when reasoning uses up max_tokens (0 disables) num_ctx: 4096 max_image_side: 960 max_frames: 3 frame_layout: separate # separate (default) | strip (1 labeled tiled image) | hybrid (motion strip + full-res keyframe) max_concurrency: 1 process_past_deadline: true # Finish late video and image event captions for local history cross_camera_context_seconds: 90 # Share cross-camera sightings within this window (0 disables) cross_camera_min_similarity: 0.62 # Strong CLIP cosine similarity match across cameras cross_camera_relaxed_similarity: 0.35 # Lower same-class floor for angle/lighting shifts (e.g. front->rear, outdoor->indoor/IR) cross_camera_max_sightings: 3 # Max chronological other-camera sightings included in the prompt # Hardware acceleration for ONNX Runtime and AI Port FFmpeg decode. # Install OpenVINO support with: pip install -e ".[openvino]" (or replace onnxruntime with onnxruntime-openvino). acceleration: enabled: true # Set false for CPU inference and software video decode provider: auto # auto | cpu | openvino | coreml | cuda | migraphx (CUDA and MIGraphX require an explicit selection) cpu_models: [] # Optional model labels from /api/status inference, e.g. ["face:w600k_r50"] openvino_device: "AUTO:GPU,CPU" # GPU | NPU | CPU | AUTO:GPU,CPU | AUTO:NPU,GPU,CPU (use GPU directly on Intel xe GPUs with OpenVINO 2025.4) # openvino_cache_dir: /state/ov_cache # Defaults to /ov_cache (persists compiled GPU/NPU blobs) openvino_precision: FP16 # FP16 | FP32 | ACCURACY (applied on GPU/NPU; omitted on CPU) openvino_gpu_large_allocations: true # Sets GPU_ENABLE_LARGE_ALLOCATIONS=YES to avoid Intel xe CCS CAT errors from NEO USM pooling coreml_compute_units: CPUAndNeuralEngine # CPUAndNeuralEngine | ALL | CPUAndGPU | CPUOnly coreml_model_format: MLProgram # MLProgram | NeuralNetwork # coreml_cache_dir: /state/coreml_cache # Persistent .mlmodelc cache, defaults to /coreml_cache migraphx_precision: FP32 # FP32 | FP16 (AMD MIGraphX) # migraphx_cache_dir: /state/migraphx_cache # Compiled MIGraphX programs, defaults to /migraphx_cache ffmpeg_hwaccel: auto # none | auto | vaapi | videotoolbox (AI Port analyzer decode) ffmpeg_device: /dev/dri/renderD128 # VA-API only # If the GPU context is lost (e.g. an Intel xe engine reset), every GPU model keeps failing until # Keystone restarts. With this on, Keystone exits (code 75) so systemd Restart=on-failure or the # Docker restart policy brings it back with a fresh GPU context. restart_on_gpu_loss: true gpu_loss_max_restarts: 3 # after this many GPU-loss restarts... gpu_loss_window_minutes: 30 # ...within this window, start on the CPU instead (no restart loop) # Optional per-camera spatial hints (keyed by UniFi Protect camera ID). # Helps the vision model tell entering vs. exiting, toward vs. away from the house, or passing street traffic. # Find camera IDs in the Keystone status dashboard or Protect URLs. # cameras: # cam_driveway_gate: # name: Driveway Gate # hint: "Bottom foreground near the gate leads toward the house; top road is the public street. Moving bottom-to-top is exiting; top-to-bottom is entering; moving across the top is driving past on the street." # cam_front_yard: # name: Front Yard # hint: "House is on the left/foreground; uphill driveway at top-center leads away from the house toward the gate." # Optional known vehicle license-plate mapping (normalized uppercase plate -> friendly description). # Protect LPR forwards raw plate strings without console vehicle names; mapped plates appear naturally in captions. # vehicles: # ABC1234: "Alice's white sedan" embeddings: enabled: true backend: clip # clip (768-dim CLIP ViT-L/14 ONNX) | ollama (nomic-embed-text) auto_download: true # Downloads Xenova/clip-vit-large-patch14 ONNX weights once quantization: fp32 # fp32 | int8 (recommended for 2-4 GiB hosts, ~1.2 GB less RAM) | fp16 (GPU EPs only) # coreai_vision_model: /path/to/image_encoder.aimodel # Optional, macOS 27+ Apple Silicon, default fp32 CLIP # coreai_python: /path/to/venv/bin/python # Optional for Homebrew, installed with coreai-core lazy_text_model: true # Load the CLIP text encoder on the first Find Anything / reverify query text_model_idle_unload_seconds: 0 # >0 frees the idle text encoder again (reloads in <1s on next query) threads: 4 # Retroactive processing (Protect 7.3.74+): opt-in backfill of Find Anything embeddings for # events recorded before Keystone was adopted. Protect then sends historical events in batches # of up to 50; this can take hours on large NVRs. Live events always run first. retroactive_processing: false retroactive_max_queued: 32 # Retroactive events held at once (separate from max_queue_size) retroactive_batch_delay_ms: 0 # Pause after each retroactive event (e.g. 200 on low-power hosts) max_objects_per_event: 8 # Optional local face recognition (SCRFD + 512-dim ArcFace). Disabled by default. # Gallery layout: //*.jpg|png|webp (5-10 clear photos each; chmod 700). # NOTE: InsightFace model weights are downloaded at runtime and licensed for non-commercial research only. faces: enabled: false # gallery_dir: /state/faces # Defaults to /faces # model_dir: /state/models/face # Defaults to /models/face auto_download: true detector: scrfd_2.5g # scrfd_2.5g | scrfd_500m recognizer: w600k_r50 # w600k_r50 (accurate) | w600k_mbf (lightweight) threads: 2 min_det_score: 0.6 min_face_px: 40 # Faces smaller than this (short side, px) are never matched min_similarity: 0.45 # Conservative: strangers should score well below this min_margin: 0.10 # Required gap over the second-best person propagate: true # Carry recognized names across cameras (person CLIP + companion-object continuity) propagation_seconds: 90 propagation_min_similarity: 0.85 propagation_companion_min_similarity: 0.40 # Companion-object (vehicle/animal/package) CLIP floor when unambiguous # Native Protect Face Recognition (Protect Faces / Known Faces), reusing the same models (no # extra RAM). AI Key: advertises supportFaceRecognition for legacy G4/G5 cameras (enable # Legacy Camera Enhancement -> Face Recognition in Protect). AI Port: adds "face" smart # detections for paired ONVIF cameras. Works with an empty gallery. Env: KEYSTONE_FACES_NATIVE_PROTECT native_protect: true enhance: # Native Protect "Face Image Enhancement" (supportFaceEnhancement / enhanceImage). Protect sends # face crops; Keystone restores them and posts the JPEG back to Protect's enhancedImages table. enabled: false backend: gfpgan # gfpgan (GFPGAN v1.4 ONNX, Apache-2.0, ~340 MB download, ~1 s/face # on 2 CPU threads) | pillow (zero-download Lanczos + sharpen; 2 GiB hosts) # model_dir: /state/models/gfpgan # Defaults to /models/gfpgan auto_download: true # Pinned HF commit, SHA-256 verified before loading preload: false # false = load on the first enhanceImage request threads: 2 max_output_side: 512 # Keeps Protect's enhancedImages rows lean jpeg_quality: 92 idle_unload_seconds: 300 # Free the model's RAM after 5 idle minutes (0 = keep resident) # Native Protect Speech-to-Text (event transcripts; Protect featureFlags "supportTts" & "supportStt"). # Off by default. The onnx backend runs OpenAI Whisper locally on CPU with the existing # onnxruntime/numpy/tokenizers deps; weights are pinned + SHA-256 verified on first use. stt: enabled: false backend: onnx # onnx (local Whisper) | openai (POST /v1/audio/transcriptions) model: whisper-base # onnx: whisper-tiny | whisper-base | whisper-small quantization: int8 # onnx: int8 (base ~77 MB, ~0.3 GiB RAM) | fp32 # model_dir: /state/models/whisper-base # Defaults to /models/ auto_download: true language: "" # "" = auto-detect, or an ISO code such as "en" threads: 2 # base_url: http://gpu-box:8000/v1 # openai backend (speaches, whisper.cpp server, OpenAI…) # api_key: "" timeout_seconds: 90 max_audio_seconds: 120 # Native UniFi Protect License Plate Recognition (local YOLOX plate detector + fast-plate-ocr). # AI Key: advertises supportLicensePlateRecognition, so Legacy Camera Enhancement -> License Plate # Recognition works for older G4/G5 cameras (plates land on the vehicle detection and in # "Known Vehicles"). AI Port: advertises "licensePlate" for paired ONVIF/Nest cameras. Both share # one ~25 MB model set (Apache-2.0 detector + MIT OCR), downloaded once and SHA-256 verified. # Recognized plates are also mapped through `vehicles:` above so captions can say "Alice's sedan". lpr: enabled: false native_protect: true # false = only use plates for captions/identities, never sent to Protect detector: yolox_tiny # yolox_tiny (open-lpr, 20 MB) | yolox_s (US plates, 36 MB, more accurate) ocr_model: cct_s_v2 # cct_s_v2 (5 MB) | cct_xs_v2 (3 MB, faster) # model_dir: /state/models/lpr # Defaults to /models/lpr auto_download: true threads: 2 min_det_score: 0.45 # Plate detector score min_ocr_confidence: 0.65 # Geometric-mean character confidence of the best read min_plate_chars: 3 max_plate_chars: 10 min_plate_px: 24 # Ignore plates whose short side is smaller (source pixels) max_frames: 6 # Vehicle frames scanned per AI Key event notifier: webhook_url: "" # Optional HTTP webhook receiving rich JSON captions + tags mqtt_host: "" # Optional MQTT broker (requires `pip install -e ".[mqtt]"`) mqtt_port: 1883 mqtt_topic_prefix: keystone web: enabled: true bind_host: 127.0.0.1 # Localhost by default; set to 0.0.0.0 or put behind a reverse proxy for LAN access port: 8088 allowed_clients: [] # Optional IPs/CIDRs allowed to open the dashboard; empty allows any client