← All N8N workflows
Automation & utilitiesCodeExecute Workflow TriggerHTTP RequestIfEdit Fields

[2/2] KNN classifier (lands dataset)

Configured with Execute Workflow Trigger, HTTP Request. Review the connections and setup before adapting this template.

Workflow preview
Web / APIEmbed imageHTTP RequestWeb / APIQuery QdrantHTTP RequestCodeMajority VoteCodeTransformIncrease limitKNNEdit FieldsTransformPropagate loopvariablesEdit FieldsTransformImage Test URLEdit FieldsTransformReturn classEdit FieldsRoutingCheck tieIfTransformQdrant variables +embedding + KNN…Edit FieldsTriggerExecute WorkflowTriggerExecute Workflow Trigger

Node categories in this workflow

  • Web / API
  • Code
  • Transform
  • Routing
  • Trigger

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
Embed imageWeb / APIHTTP RequestPOST
Query QdrantWeb / APIHTTP RequestPOST
Majority VoteCodeCodeSee node parameters
Increase limitKNNTransformEdit FieldsSee node parameters
Propagate loop variablesTransformEdit FieldsSee node parameters
Image Test URLTransformEdit FieldsSee node parameters
Return classTransformEdit FieldsSee node parameters
Check tieRoutingIfSee node parameters
Qdrant variables + embedding + KNN neigboursTransformEdit FieldsSee node parameters
Execute Workflow TriggerTriggerExecute Workflow TriggerSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • httpHeaderAuth
  • qdrantApi

Workflow notes

Sticky Note

Here we're classifying existing types of satellite imagery of land types:

  • 'agricultural',
  • 'airplane',
  • 'baseballdiamond',
  • 'beach',
  • 'buildings',
  • 'chaparral',
  • 'denseresidential',
  • 'forest',
  • 'freeway',
  • 'golfcourse',
  • 'harbor',
  • 'intersection',
  • 'mediumresidential',
  • 'mobilehomepark',
  • 'overpass',
  • 'parkinglot',
  • 'river',
  • 'runway',
  • 'sparseresidential',
  • 'storagetanks',
  • 'tenniscourt'
Sticky Note1

I tested this KNN classifier on a whole test set of a dataset (it's not a part of the collection, only validation + train parts). Accuracy of classification on test is 93.24%, no fine-tuning, no metric learning.

KNN classification workflow-tool

KNN classification workflow-tool

This n8n template takes an image URL (as anomaly detection tool does), and as output, it returns a class of the object on the image (out of land types list)

  • An image URL is received via the Execute Workflow Trigger, which is then sent to the Voyage.ai Multimodal Embeddings API to fetch its embedding.
  • The image's embedding vector is then used to query Qdrant, returning a set of X similar images with pre-labeled classes.
  • Majority voting is done for classes of neighbouring images.
  • A loop is used to resolve scenarios where there is a tie in Majority Voting (for example, we have 5 "forest" and 5 "beach"), and we increase the number of neighbours to retrieve.
  • When the loop finally resolves, the identified class is returned to the calling workflow.
Sticky Note3

Variables define another Qdrant's collection with landscapes (uploaded similarly as the crops collection, don't forget to switch it with your data) + amount of neighbours limitKNN in the database we'll use for an input image classification.

Sticky Note4

Similarly to anomaly detection tool, we're embedding input image with the Voyage model

Tie loop

Tie loop

Here we're querying Qdrant, getting limitKNN nearest neighbours to our image <Query Qdrant node>, parsing their classes from payloads (images were pre-labeled & uploaded with their labels to Qdrant) & calculating the most frequent class name <Majority Vote node>. If there is a tie <check tie node> in 2 most common classes, for example, we have 5 "forest" and 5 "harbor", we repeat the procedure with the number of neighbours increased by 5 <propagate loop variables node and increase limitKNN node>. If there is no tie, or we have already checked 100 neighbours, we exit the loop <check tie node> and return the class-answer.

Sticky Note6

Here, we extract the name of the input image class decided by the Majority Vote

KNN (k nearest neighbours) classification

KNN (k nearest neighbours) classification

  1. The first pipeline is uploading (lands) dataset to Qdrant's collection.
  2. This is the KNN classifier tool, which takes any image as input and classifies it based on queries to the Qdrant (lands) collection.

To recreate it

You'll have to upload lands dataset from Kaggle to your own Google Storage bucket, and re-create APIs/connections to Qdrant Cloud (you can use Free Tier cluster), Voyage AI API & Google Cloud Storage

In general, pipelines are adaptable to any dataset of images

[2/2] KNN classifier (lands dataset)

[2/2] KNN classifier (lands dataset)

Purpose and structure

This folder contains the [2/2] KNN classifier (lands dataset) workflow. Its executable nodes use code, executeWorkflowTrigger, httpRequest, if, set. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Execute Workflow Trigger

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Http/1730_HTTP_Executeworkflow_Automation_Webhook.json MIT; preserve source notices.

More in Automation & utilities