Skip to content

AI: Generate Labels using the Ollama API #5232

Closed
Closed

Description

@graciousgrey

As a user, I would like to generate labels directly through the Ollama service API, so that I get more accurate labels in my preferred language

Acceptance Criteria:

  • It MUST be possible to configure a Ollama model to generate labels using a custom prompt in the vision.yml file.
  • The vision run command MUST use the configured Ollama model and prompt to generate labels when run with the -m labels flag.
  • Code changes MUST include unit tests.
  • Related documentation has been updated.

Activity

  1. added
    ideaFeedback wanted / feature request
    aiArtificial Intelligence, Machine Learning (ML)
    on Sep 28, 2025
  2. moved this to Development 🐝 in Roadmap 🚀✨on Sep 28, 2025
  3. added theissue type on Sep 28, 2025
  4. moved this from Development 🐝 to Preview 🐳 in Roadmap 🚀✨on Sep 28, 2025
  5. lastzero commented on Sep 28, 2025

    @lastzero
    Member

    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 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):

    docker compose exec ollama ollama pull 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: labels
      Default: true
    - Type: nsfw
      Default: true
    - Type: face
      Default: true
    - Type: labels
      Name: gemma3:latest
      Engine: ollama
      Service:
        Uri: "http://ollama:11434/api/generate"
    - Type: caption
      Name: gemma3:latest
      Engine: ollama
      Prompt: |
        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

    Test the integration with:

    docker compose exec photoprism photoprism vision run -m labels --count 5 --force --source vision

    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.
  6. added
    labelsRelated to labels assigned manually or from metadata
    on Sep 28, 2025
  7. 17 remaining items

  8. added
    testedChanges have been tested successfully
    and removed
    please-testReady for manual testing & feedback
    on Nov 22, 2025
  9. moved this from Preview 🐳 to Release 🌈 in Roadmap 🚀✨on Dec 1, 2025
  10. added
    releasedAvailable in a stable release
    and removed
    testedChanges have been tested successfully
    on Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

aiArtificial Intelligence, Machine Learning (ML)ideaFeedback wanted / feature requestlabelsRelated to labels assigned manually or from metadatareleasedAvailable in a stable release

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions