You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow the steps below to connect PhotoPrism directly to an Ollama instance and replace (or augment) the default Nasnet classifier with labels generated by a vision-capable LLM.
Step 1: Install Ollama
Add the ollama service to your compose.yaml (or docker-compose.yml) next to PhotoPrism, or use one of our prebuilt examples from the download server. Start the stack with:
docker compose --profile ollama up -d
Remove profiles: ["ollama"] if you want the service to start automatically without --profile. When deploying on a separate host, expose the Ollama API on a network route accessible to PhotoPrism (e.g., http://ollama:11434/).
Ollama does not enforce authentication by default. Only expose port 11434 inside trusted networks or behind a reverse proxy that adds access control.
Step 2: Download Models
Pull at least one multimodal model that can return structured JSON (for example, gemma3:latest):
Other viable options already validated in our tests include qwen2.5vl:3b, qwen2.5vl:3b-q8_0, and qwen2.5vl:3b-fp16. Stick to lightweight quantizations when running on CPUs and reserve FP16 variants for GPUs.
Step 3: Configure PhotoPrism
Create or update the vision.yml file in the PhotoPrism storage directory (inside the container: /photoprism/storage/config/vision.yml). Reuse your existing TensorFlow defaults but add an Ollama-based label model as shown below:
Models:
- Type: labelsDefault: true
- Type: nsfwDefault: true
- Type: faceDefault: true
- Type: labelsName: gemma3:latestEngine: ollamaService:
Uri: "http://ollama:11434/api/generate"
- Type: captionName: gemma3:latestEngine: ollamaPrompt: | Create a caption with exactly one sentence in the active voice that describes the main visual content. Begin with the main subject and clear action. Avoid text formatting, meta-language, and filler words.Service:
Uri: "http://ollama:11434/api/generate"Thresholds:
Confidence: 10
The Format: json field ensures PhotoPrism requests structured data, while Schema can provide a custom inline template the adapter injects into the prompt.
Keep the base instructions in English and append the desired language e.g., “Respond in German”). This mirrors our recommendation for caption prompts and tends to be more reliable than asking the model to output multiple languages simultaneously.
Step 4: Restart PhotoPrism
Apply the new settings or toggle the model at runtime:
docker compose stop photoprism
docker compose up -d
If the command finishes without errors, inspect the updated labels in the UI or via photoprism vision ls.
Troubleshooting
Verify Active Configuration
docker compose exec photoprism photoprism vision ls
Ensure the output lists both Nasnet (default) and your Ollama label model. If the custom entry is missing, double-check the YAML indentation, file name (vision.yml, not .yaml), or environment overrides.
Schema or JSON Errors
If PhotoPrism logs vision: invalid label payload from ollama, the model returned data that didn’t match the expected structure. Confirm that:
Format: json is set in the model definition.
The prompt instructs the model to follow the schema.
The schema itself is valid JSON. Use jq . vision-schema.json to validate external files.
PhotoPrism falls back to the existing TensorFlow Nasnet model whenever the Ollama response cannot be parsed.
Latency & Timeouts
Structured responses introduce additional parsing overhead. If you encounter timeouts:
Increase the global service timeout (e.g., ServiceTimeout in advanced deployments) if needed.
Keep Options.Temperature low to encourage deterministic output.
GPU Considerations
When Ollama uses GPUs, long-running sessions might degrade over time due to VRAM fragmentation. Restart the Ollama container to recover performance:
docker compose down ollama
docker compose up -d ollama
Tested Models
We validated the following Ollama visions models with the default prompt and schema:
gemma3:latest — emits broader industrial labels (industrial equipment, maintenance, inspection) in ~16.7 s and honors the JSON schema.
Both variants respect Format: json without additional tuning, making them good starting points when operating on limited hardware or mobile connections.
Prompt Variations & Localization
Default prompt vs. domain prompt: Qwen 2.5 VL handled both the baseline schema prompt and a more domain-specific instruction, producing water-infrastructure labels in each case. Gemma 3 worked with the baseline prompt but returned an empty JSON object once when asked for “at most five domain-specific labels,” so keep fallback logic enabled.
German output: Appending “Respond in German” preserved schema compliance. Qwen continued to output English nouns (with correct structure), while Gemma returned localized strings (Betrieb, Pumpen, Inspektion).
Recommendation: Start with the default prompt and adjust wording gradually. Always monitor for empty objects or mixed-language responses and fall back to TensorFlow-based labels when parsing fails.
Activity
AI: Generate Labels using the Ollama API #5232
lastzero commentedon Sep 28, 2025
This can now be tested using our development preview build:
Follow the steps below to connect PhotoPrism directly to an Ollama instance and replace (or augment) the default Nasnet classifier with labels generated by a vision-capable LLM.
Step 1: Install Ollama
Add the
ollamaservice to yourcompose.yaml(ordocker-compose.yml) next to PhotoPrism, or use one of our prebuilt examples from the download server. Start the stack with:Remove
profiles: ["ollama"]if you want the service to start automatically without--profile. When deploying on a separate host, expose the Ollama API on a network route accessible to PhotoPrism (e.g.,http://ollama:11434/).Step 2: Download Models
Pull at least one multimodal model that can return structured JSON (for example,
gemma3:latest):docker compose exec ollama ollama pull gemma3:latestOther viable options already validated in our tests include
qwen2.5vl:3b,qwen2.5vl:3b-q8_0, andqwen2.5vl:3b-fp16. Stick to lightweight quantizations when running on CPUs and reserve FP16 variants for GPUs.Step 3: Configure PhotoPrism
Create or update the
vision.ymlfile in the PhotoPrism storage directory (inside the container:/photoprism/storage/config/vision.yml). Reuse your existing TensorFlow defaults but add an Ollama-based label model as shown below:The
Format: jsonfield ensures PhotoPrism requests structured data, whileSchemacan provide a custom inline template the adapter injects into the prompt.Step 4: Restart PhotoPrism
Apply the new settings or toggle the model at runtime:
Test the integration with:
docker compose exec photoprism photoprism vision run -m labels --count 5 --force --source visionIf the command finishes without errors, inspect the updated labels in the UI or via
photoprism vision ls.Troubleshooting
Verify Active Configuration
docker compose exec photoprism photoprism vision lsEnsure the output lists both Nasnet (default) and your Ollama label model. If the custom entry is missing, double-check the YAML indentation, file name (
vision.yml, not.yaml), or environment overrides.Schema or JSON Errors
If PhotoPrism logs
vision: invalid label payload from ollama, the model returned data that didn’t match the expected structure. Confirm that:Format: jsonis set in the model definition.jq . vision-schema.jsonto validate external files.PhotoPrism falls back to the existing TensorFlow Nasnet model whenever the Ollama response cannot be parsed.
Latency & Timeouts
Structured responses introduce additional parsing overhead. If you encounter timeouts:
ServiceTimeoutin advanced deployments) if needed.Options.Temperaturelow to encourage deterministic output.GPU Considerations
When Ollama uses GPUs, long-running sessions might degrade over time due to VRAM fragmentation. Restart the Ollama container to recover performance:
Tested Models
We validated the following Ollama visions models with the default prompt and schema:
gemma3:latest— emits broader industrial labels (industrial equipment,maintenance,inspection) in ~16.7 s and honors the JSON schema.Both variants respect
Format: jsonwithout additional tuning, making them good starting points when operating on limited hardware or mobile connections.Prompt Variations & Localization
Betrieb,Pumpen,Inspektion).AI: Add source "ollama" for labels generated with Ollama models #5232
AI: Add ApiFormat constants to vision/ollama and vision/openai #5232
17 remaining items
AI: Fix and improve label normalization in vision package #5232
Config: Disable image classification independently of TensorFlow #5232
AI: Allow users to use a custom source for TensorFlow labels #5011 #5232
AI: Add internal/ai/vision/ollama/README.md #5322 #5123 #5232
AI: Link engine docs in AGENTS.md and CODEMAP.md files #5322 #5123 #5232
AI: Add schema/README.md as labels schema reference #5322 #5123 #5232
AI: Read Qwen3-VL Ollama model response from Thinking field #5123 #5232
AI: Update internal/ai/vision/ollama/README.md #5123 #5232
AI: Improve model configuration and documentation #5123 #5232 #5322