Set Up Medoids for Crop Anomaly Detection with n8n & Qdrant

Discover how to automate setting medoid points and threshold scores in Qdrant cloud for anomaly detection in agricultural crop image data. This n8n workflow leverages HTTP requests, Python code, and multimodal embeddings to identify representative cluster centers, saving hours in data preparation for reliable anomaly detection.
httpRequest
manualTrigger
code
+4
Workflow Identifier: 2219
NODES in Use: Manual Trigger, HTTP Request, Code, Set, Split Out, Merge, Sticky Note
Automate medoid setup with n8n and Qdrant

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

Learn how to Build this Workflow with AI:

What this workflow does

This workflow finds cluster centers (medoids) and sets threshold scores for anomaly detection in an agricultural crops dataset stored in Qdrant Cloud.
It solves the problem of manually picking cluster points and thresholds, which is slow and error-prone.
After running, it updates Qdrant with the best medoid points and matching threshold scores, helping accurate anomaly detection.


Who should use this workflow

Anyone working with large crop image datasets in Qdrant Cloud who needs to automate finding cluster centers and thresholds.
This is useful for agricultural AI that detects unusual or defective crops automatically.


Tools and services used

  • Qdrant Cloud: Hosts the vector database of crops.
  • n8n automation platform: Runs this workflow.
  • Voyage AI API: Used for generating text embeddings.
  • Python environment in n8n: Runs scipy code to process distance matrices.
  • REST API credentials: For accessing Qdrant Cloud and Voyage AI.


Inputs → Processing → Output

Inputs

  • Total points count from Qdrant collection.
  • Unique crop types (cluster names) with their counts.
  • Crop descriptions for text embeddings.

Processing Steps

  1. Get total crop points count from Qdrant.
  2. Retrieve counts of each crop type facet.
  3. For each crop cluster, call Qdrant distance matrix API to get point distances.
  4. Use Python scipy coo_array to find the cluster medoid — the point most similar to others.
  5. Set the medoid’s payload in Qdrant to mark it as a cluster center.
  6. Embed crop descriptions using Voyage AI to find text-based medoids.
  7. Calculate threshold scores by searching for furthest points from medoids using cosine similarity.
  8. Store threshold scores in Qdrant payloads for anomaly detection.

Output

Cluster centers labeled as medoids with associated threshold scores in Qdrant collection payload.
These results enable reliable anomaly detection on crop image vectors.


Beginner step-by-step: How to build this in n8n

Import and setup

  1. Download this workflow file using the Download button.
  2. Open n8n editor already running.
  3. Use n8n’s “Import from File” option to load the downloaded workflow.
  4. Go to Qdrant cluster variables node and enter your Qdrant Cloud URL and collection name.
  5. Fill in your Voyage AI API Key in the Embed text HTTP Request node.
  6. Set any variables like furthestFromCenter in the Medoids Variables nodes as needed.
  7. Check that your REST API credentials for Qdrant and Voyage are active in n8n.

Test and activate

  1. Run the workflow with the manual trigger by clicking Webhook node or test button.
  2. Watch the workflow run without errors and verify medoid IDs and threshold scores are properly set in Qdrant.
  3. Activate the workflow in n8n for production use to run on schedule or manual triggers.

For users self hosting n8n, consult self-host n8n for reliable setup options.


Edge cases and failures

  • If API requests return 401 errors, check the Qdrant API credentials and tokens.
  • Python code errors about missing scipy mean the Python environment in n8n lacks scipy package.
  • Distance matrix calls can fail if sample size is larger than actual cluster size.
  • Threshold scores might be wrong if cosine similarity signs or calculations are mishandled.


Customization ideas

  • Adjust furthestFromCenter values to change how strict or loose anomaly detection thresholds are.
  • Add more crop type descriptions or use ChatGPT API within n8n to generate crop descriptions dynamically.
  • Change the embed model in the Voyage API HTTP node to try different vector representations.
  • Increase maxClusterSize to handle bigger clusters, watching out for API limits.


Summary of results

✓ Cluster medoids marked accurately in Qdrant collection.
✓ Threshold scores calculated and saved for each cluster.
✓ Manual medoid setup replaced with automated processing.
✓ Enables better anomaly detection quality on crop image data.


Automate medoid 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

Yes, but the HTTP requests must be changed to match the new database’s API features, especially for distance matrix and query functions.
The n8n Python environment is missing the scipy package. Installing scipy or using JavaScript alternatives is needed.
Check the calculation formula for threshold scores. Make sure the cosine similarity value is multiplied by -1 as required.
This workflow is designed for moderate cluster sizes. For very large datasets, split processing into smaller batches to manage performance.

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.