Image Classifier using KNN, Qdrant, and Multimodal Embeddings - n8n Workflow

Implement a robust K-Nearest Neighbors (KNN) image classifier using this advanced n8n workflow. Integrate Voyage AI multimodal embeddings and Qdrant vector storage to automate visual classification tasks.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Data Scientists building visual classification tools.

  • Developers seeking ready-made n8n templates for multimodal AI integration.

  • Automation specialists needing a robust classification system with tie-breaking logic.

  • Users looking to leverage vector databases like Qdrant within their n8n projects.

Overview

This sophisticated n8n workflow addresses the challenge of real-time image classification without relying on heavy deep learning models for inference. By utilizing the K-Nearest Neighbors (KNN) algorithm implemented via a Qdrant vector database, the n8n workflow quickly finds the closest neighbors to an input image's vector embedding.

The logic incorporates a crucial element: a tie-breaking loop. If the initial majority vote among neighbors results in a tie between the top two classes (e.g., 5 'forest' and 5 'beach'), the n8n template automatically increases the number of neighbors (limitKNN) and re-queries the database, ensuring accurate and definitive classification. This robust n8n node combination makes deploying highly accurate visual recognition systems simple and efficient.

How it Works

This specialized n8n template starts when the Execute Workflow Trigger receives an image URL, typically called as a tool from another automation.


  1. Embed Generation: The input image URL is sent to the Voyage AI Multimodal API using an n8n node to generate a high-dimensional vector embedding representing the image content.

  2. Qdrant Configuration: A subsequent n8n node sets the necessary Qdrant URL, the target collection name (land-use), and the initial K value (limitKNN, set to 10).

  3. Vector Search: The Query Qdrant n8n node performs a nearest neighbor search using the generated vector, retrieving the top limitKNN closest pre-labeled data points and their associated payloads (class labels).

  4. Majority Vote: A Python Code n8n node tallies the classes of the retrieved neighbors to perform a majority vote and determine the most frequent class.

  5. Tie Check Loop: The Check tie n8n node evaluates if the top two results have an equal number of votes. If a tie is detected and the search limit is under 100, the n8n workflow enters a self-correction loop.

  6. Loop Iteration: Inside the loop, the Increase limitKNN n8n node increments the neighbor count by 5, and the process repeats (Step 3). This increases the sample size until a clear majority is established.

  7. Final Output: Once the tie is resolved or the limit is reached, the workflow exits the loop, and the Return class n8n node outputs the definitive classification result to the calling n8n workflow.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON data and import it into your n8n instance using the "New -> Import from JSON" option.

  2. Voyage AI Credential: Set up a "HTTP Header Auth" credential named Voyage API for the Embed image n8n node. This requires your Voyage AI API key for access to the multimodal embedding service.

  3. Qdrant Credential: Configure a "QdrantApi" credential named QdrantApi account for the Query Qdrant n8n node, ensuring it has access to your cloud cluster.

  4. Dataset Preparation: This n8n template requires a pre-populated Qdrant collection (named land-use in the included settings) containing image embeddings and their corresponding class labels (payload: landscape_name). You must run a prior n8n workflow or script to upload your image dataset (such as the lands dataset) and generate embeddings beforehand.

  5. Execution: The n8n workflow is designed to be executed via an Execute Workflow Trigger, receiving the image URL in the input payload from a parent n8n automation.

Node Details

Execute Workflow Trigger: The initial n8n trigger for this tool, designed to receive input data, specifically the imageURL.
Embed image (HTTP Request): Utilizes the Voyage AI multimodal API (voyage-multimodal-3) to generate a vector embedding for the input image URL. This critical n8n node uses custom authentication.
Qdrant variables + embedding + KNN neigbours (Set): An n8n node that combines the generated ImageEmbedding with the necessary Qdrant configuration parameters, including the collection name and the initial number of neighbors (limitKNN=10).
Query Qdrant (HTTP Request): Queries the specified Qdrant collection using the embedding vector. It performs the nearest neighbor search and ensures that the classification payload data is returned.
Propagate loop variables (Set): Prepares the data structure for the loop and passes the search results to the classification logic.
Majority Vote (Code - Python): A custom Python n8n node implementing the KNN classification logic. It uses Python's collections.Counter to perform a majority vote on the returned landscape_name payloads.
Check tie (If): The flow control n8n node that determines if a tie exists between the top two classes. If a tie is found and the iteration limit (100) is not reached, it redirects the flow to increase K.
Increase limitKNN (Set): If a tie is detected, this n8n node increases the limitKNN value by 5 before looping back to re-query Qdrant.


  • Return class (Set): The final output n8n node, which extracts and returns the winning classification category, concluding the n8n workflow execution.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

Qdrant DevRel, ML/NLP/math nerd with yapping skills

Featured*