Set Medoids for Anomaly Detection with n8n & Qdrant

This n8n workflow sets representative medoids and threshold scores for clusters in a crop image dataset using Qdrant and Voyage AI. It prepares your data for precise anomaly detection by identifying cluster centers and their boundaries, saving hours of manual analysis and boosting detection accuracy.
httpRequest
set
code
+4
Workflow Identifier: 1930
NODES in Use: ManualTrigger, Set, HTTP Request, Split Out, Merge, Code, Sticky Note
Automate medoids setup with n8n and Qdrant

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Automation Does ⚙️

This workflow helps find central points called medoids for each crop cluster from images using Qdrant and Voyage AI.
It solves the problem of slow and hard manual work to find cluster centers and thresholds so anomaly detection works better.
The output is medoid points flagged in Qdrant and threshold scores set to detect unusual crop images accurately.

The workflow gets data from Qdrant, calculates similarities inside each crop cluster, finds the medoid using Python with SciPy, then gets medoids by comparing image vectors and crop text descriptions.
It marks these medoids in Qdrant and finds threshold scores to define anomaly boundaries.
This makes later detection faster and more precise.


Inputs, Processing Steps & Outputs

Inputs

  • Qdrant Cloud URL and Collection Name: Needed to connect and query crop image vectors.
  • Qdrant API Credentials: Required to access collection data securely.
  • Voyage AI API Key: Used to embed crop textual descriptions for semantic medoid searches.

Processing Steps

  • Fetch total points and number of unique crop clusters from Qdrant.
  • Query counts of images per crop using Qdrant facet API.
  • Split clusters to process each crop group separately.
  • Get pairwise distance matrix of points within each cluster from Qdrant.
  • Use Python code to find medoid (most central point) from sparse matrix of cosine similarities.
  • Flag the medoid point in Qdrant payload.
  • Retrieve medoid’s vector and payload from Qdrant.
  • Calculate opposite vector to medoid center for searching threshold point.
  • Find point furthest from medoid (by similarity) within cluster for threshold score.
  • Assign the threshold score to medoid point payload in Qdrant.
  • Embed textual descriptions of crops with Voyage AI.
  • Find closest image point to each text embedding for text-based medoid.
  • Flag text medoids and calculate thresholds similarly to vector medoids.

Outputs

  • Qdrant collection updated with flags marking medoids as central points by vector and text methods.
  • Threshold similarity scores saved per medoid to define cluster bounds.
  • Ready medoids and threshold data for accurate anomaly detection.


Tools & Services Used

  • Qdrant Cloud: Stores crop image vectors and supports distance matrix and point queries.
  • Voyage AI API: Provides multimodal embeddings to get textual similarity medoids.
  • n8n Workflow Automation: Orchestrates API calls, data processing, and status updates.
  • Python SciPy Sparse Matrix: Calculates medoid from cosine similarity matrix programmatically.


Beginner Step-by-step: How to Use This Workflow in n8n

Step 1: Download and Import

  1. Download the workflow file by clicking the Download button on this page.
  2. Open n8n editor where the workflow should run.
  3. Select “Import from File” option and upload the downloaded workflow .json file.

Step 2: Set Credentials and Variables

  1. Open the Qdrant cluster variables node.
    Update qdrantCloudURL and collectionName with your correct Qdrant details.
  2. Add your Qdrant API credentials in n8n credentials manager and link them in HTTP Request nodes.
  3. Add your Voyage AI API key in n8n’s HTTP credential settings and link it in the Embed text node.
  4. If needed, edit Textual (visual) crop descriptions node to match your crop names and descriptions.
  5. Adjust furthestFromCenter variables in Medoids Variables and Text Medoids Variables nodes to tune sensitivity.

Step 3: Test the Workflow

  1. Click on the Manual Trigger node and press Execute to run the workflow once.
    Check logs to verify medoids and thresholds set correctly.

Step 4: Activate the Workflow

  1. Once tested, activate the workflow to run automatically in production.
  2. You can schedule runs after batch uploads or periodic updates.
  3. Monitor results and adjust parameters as crop data grows.

Using this simple import and config way, you get production-ready medoid and threshold setup without building from scratch.


Customization Ideas ✏️

  • Change collectionName in Qdrant cluster variables to work with different image sets.
  • Modify furthestFromCenter numbers to make anomaly detection stricter or looser.
  • Add or improve crop descriptions for better text medoid accuracy.
  • Switch Voyage AI embedding model URL or API key for different embedding approaches.


Troubleshooting ????

  • 401 Unauthorized Error: Fix API Keys in n8n credentials and try again.
  • SciPy Module Not Found: Make sure n8n runs where SciPy is installed or execute Python code externally.
  • Medoid IDs or Payload Updates Fail: Double-check JSON paths and node outputs using n8n execution logs.


Deployment Notes

Turn on the workflow to update medoids and thresholds after new data arrives.
This keeps anomaly detection accurate with fresh clusters.

Check medoids flags and thresholds visually in Qdrant using the UI.
Change thresholds as the cluster shapes and sizes change over time.

For stable run times and less downtime, consider self-host n8n on a reliable server.


Summary

✓ Builds cluster medoids and thresholds for crop image anomaly detection.
✓ Automates manual work saving hours or days.
✓ Uses Qdrant distance matrices and Voyage AI text embeddings.
✓ Sets flags in Qdrant for vector-based and text-based cluster centers.
✓ Provides clear threshold scores to detect anomalies effectively.
✓ Easy to import and configure in n8n for production.
✓ Allows adjusting sensitivity and adding new crops.


Automate medoids setup with n8n and Qdrant

Visit through Desktop to Interact with the Workflow.

Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.
Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

Frequently Asked Questions

The workflow uses Qdrant APIs and features like distance matrix that are specific. Adapting to other databases requires changing API calls and may not work the same.
The workflow makes multiple API calls to Qdrant and Voyage AI. Frequent runs on large datasets can use more credits, but calls are optimized per cluster to reduce usage.
Data security depends on Qdrant account restrictions and API Key management. Use secure storage for API keys in n8n and avoid sharing keys publicly.
For very large clusters, the distance matrix API may slow down or be limited. Sampling or batch processing is recommended for large datasets.

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.