Skip to content
BotServBotServ
NextcloudOllamaIntegrationDocumentsAI

Integrate Nextcloud with Ollama

Integrate Nextcloud with Ollama for document summarization, intelligent search, tagging and practical examples.

S

schutzgeist

5 min read
Integrate Nextcloud with Ollama

Integrating Nextcloud with Ollama

What This Article Covers

  • How to connect Nextcloud with Ollama.
  • How document summarization, intelligent search, and automatic tagging work.
  • How to use Nextcloud apps and custom scripts with Ollama.
  • Practical examples for document processing, knowledge search, and automation.
  • Best practices for performance, security, and data privacy.

Introduction: Understanding Nextcloud with Ollama

Nextcloud is a self-hosted cloud platform for files, calendars, contacts, and more. Ollama is a local AI model server. When you connect them together, you can process documents in Nextcloud with AI: automatically summarize them, search intelligently, assign tags, all locally and without cloud services.

This article is aimed at users who want to extend Nextcloud with local AI. You should understand how Nextcloud works and how Ollama runs. Basic Python programming knowledge is available at IRC-Coding.de.

Why Do You Need Nextcloud with Ollama?

Imagine you have hundreds of documents in Nextcloud: contracts, reports, invoices. You want to search them, summarize them, classify them. Without AI, you have to read each document manually. With Ollama in Nextcloud, the AI does it automatically, locally, and your documents never leave your infrastructure.

Nextcloud with Ollama in a Nutshell

Nextcloud stores documents, Ollama processes them with AI. Integration happens through Nextcloud apps, custom scripts, or webhooks. All data stays local.

The core idea is simple: Nextcloud stores, Ollama understands.

Who Should Read This?

  • Nextcloud users who want AI capabilities.
  • Self-hosters looking to extend Nextcloud with AI.
  • Organizations that need to process documents automatically.
  • Teams that want to automate knowledge management.

Familiarity with Nextcloud and Ollama is helpful but not required.

Key Concepts

  • Nextcloud - Self-hosted cloud platform. Useful for: document management.
  • Ollama - Local model server. Useful for: the AI backend.
  • Nextcloud App - Extension for Nextcloud. Useful for: native integration.
  • Webhook - HTTP callback. Useful for: event-driven processing.
  • RAG - Retrieval-Augmented Generation. Useful for: intelligent search.
  • Embeddings - Vector representations. Useful for: semantic search.
  • Docker - Containers. Useful for: running both services.

Integration Methods

1. Nextcloud Apps

Several community apps integrate Ollama into Nextcloud:

  • Nextcloud Assistant: AI assistant for Nextcloud.
  • Nextcloud Talk AI: AI integration for Nextcloud Talk.
  • Nextcloud Mail AI: AI for email processing.

2. Custom Scripts

Write your own scripts that are triggered by specific events:

# When a new document arrives: generate a summary
# nextcloud-occ files:scan --path="/user/files/dokumente" --post-process

3. Webhooks

Nextcloud can send webhooks when events occur:

# nextcloud webhook configuration
webhook:
  - event: "file.created"
    url: "http://localhost:8000/process-document"

4. Flow App

Nextcloud Flow is a workflow tool within Nextcloud:

# Flow: New document → Ollama → Tags
trigger: file.created
actions:
  - ollama_summarize
  - add_tags

Setup: Docker Compose

version: "3.8"

services:
  nextcloud:
    image: nextcloud:latest
    container_name: nextcloud
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - nextcloud_data:/var/www/html
      - ./apps:/var/www/html/custom_apps
    networks:
      - ai-network

  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama_data:/root/.ollama
    networks:
      - ai-network

volumes:
  nextcloud_data:
  ollama_data:

networks:
  ai-network:
    driver: bridge

Practical Example 1: Document Summarization

# Script: Generate a summary when a new document is created
import requests

def on_document_created(file_path, file_id):
    """Called when a new document is uploaded"""
    # 1. Read document from Nextcloud
    response = requests.get(
        f"http://nextcloud/remote.php/dav/files/user/{file_path}",
        auth=("user", "password")
    )
    content = response.text

    # 2. Summarize with Ollama
    summary = call_ollama([
        {"role": "system", "content": "Summarize in 3 sentences."},
        {"role": "user", "content": content[:4000]}
    ])

    # 3. Save summary as a comment
    add_comment(file_id, summary["message"]["content"])

Practical Example 2: Intelligent Search with RAG

def semantic_search(query):
    """Semantic search across Nextcloud documents"""
    # 1. Create query embedding
    query_embedding = get_embedding(query)

    # 2. Find similar documents
    results = vector_db.search(query_embedding, limit=5)

    # 3. Build context
    context = "\n".join(r.content for r in results)

    # 4. Generate answer
    response = call_ollama([
        {"role": "system", "content": "Answer based on the provided documents."},
        {"role": "user", "content": f"Documents:\n{context}\n\nQuestion: {query}"}
    ])
    return response["message"]["content"]

Practical Example 3: Automatic Tagging

def auto_tag_document(file_id, content):
    """Automatically tag a document"""
    # Generate tags
    response = call_ollama([
        {"role": "system", "content": "Assign 3-5 tags. Reply as a JSON array."},
        {"role": "user", "content": content[:3000]}
    ], format="json")

    tags = json.loads(response["message"]["content"])

    # Set tags in Nextcloud
    for tag in tags:
        add_tag(file_id, tag)

Practical Example 4: Document Classification

def classify_document(file_id, content):
    """Classify a document"""
    response = call_ollama([
        {"role": "system", "content": """Classify as one of:
- invoice
- contract
- report
- quote
- other

Reply with only the category."""},
        {"role": "user", "content": content[:3000]}
    ])

    category = response["message"]["content"].strip().lower()

    # Move to corresponding folder
    move_to_folder(file_id, f"documents/{category}")

Security Considerations

  • Secure Nextcloud: Use HTTPS, strong passwords, and 2FA. See Authentication.
  • Secure Ollama: Don’t expose it to the internet. See API Keys.
  • Network Isolation: Run Nextcloud and Ollama in their own network. See Docker Network Isolation.
  • Audit Logging: Log all AI processing activities. See Audit Logging.
  • Access Control: Not everyone should be able to see all documents. See Access Control.

Common Pitfalls

  • Docker networking: Nextcloud and Ollama must be on the same network.
  • Performance: Large documents take time. Use asynchronous processing.
  • Context length: Large documents need to be chunked.
  • OCR: Scanned documents require OCR before AI processing.
  • Error handling: If Ollama becomes unavailable, Nextcloud should not crash.

Further Reading

Key Takeaways:

  • Nextcloud + Ollama: Store documents, AI processes them.
  • Integration options: apps, custom scripts, webhooks, Flow.
  • Use cases: summarization, search, tagging, classification.
  • Everything runs locally, no cloud, no API costs.
  • Security: HTTPS, authentication, network isolation.

FAQ

How do I connect Nextcloud to Ollama?

Use Nextcloud apps, custom scripts, webhooks, or the Flow app. Both services should run on the same Docker network.

Which Nextcloud apps are available?

Nextcloud Assistant for AI support, Nextcloud Talk AI for chat, and Nextcloud Mail AI for email. Availability depends on your Nextcloud version.

How do I create automatic summaries?

Use a custom script or webhook. When a new document arrives, extract its text, send it to Ollama, and store the summary as a comment or custom field.

How do I build intelligent search?

Use RAG: store documents in a vector database, find similar documents when a search query arrives, then generate an answer with context.

How does automatic tagging work?

Ollama analyzes the document content and generates tags. These are then stored in Nextcloud as tags or categories.

Is this secure?

Yes, if both run locally. Nextcloud stores documents locally, Ollama processes them locally. No data leaves your server.

What does this cost?

Nextcloud and Ollama are open source. You only pay for hardware. No API costs, no subscriptions.

How performant is this?

It depends on the model and document size. Small documents take seconds. Large documents take minutes. For many documents, use asynchronous processing.

Can I process scanned documents?

Yes, but you need OCR before AI processing. Use Tesseract or similar OCR tools to extract text from scans.

Which model should I use?

For summarization: llama3.1:8b. For complex analysis: qwen2.5:32b. For embeddings: nomic-embed-text. For translation: qwen2.5.

Sources and Further Reading

Back to Blog
Share:

Related Posts