Block 1 - Receive Vectors
- Type / Role
- n8n-nodes-base.webhook - webhook
- Config choices
- Version 2
This workflow is provided as-is. Please review and test before using in production.
n8n Workflow: Calculate the Centroid of a Set of Vectors Overview This workflow receives an array of vectors in JSON format, validates that all vectors have the same dimensions, and computes the ce...
n8n-nodes-base.webhook, n8n-nodes-base.set, n8n-nodes-base.code, n8n-nodes-base.respondtowebhook, n8n-nodes-base.stickynote
This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Mauricio Perera.
Original n8n.io sourceThis workflow receives an array of vectors in JSON format, validates that all vectors have the same dimensions, and computes the centroid. It is designed to be reusable across different projects.
Receive Vectors (Webhook): Accepts a GET request containing an array of vectors in the vectors parameter.
vectors parameter in JSON format./webhook/centroid?vectors=[[2,3,4],[4,5,6],[6,7,8]]Extract & Parse Vectors (Set Node): Converts the input string into a proper JSON array for processing.
vectors is a valid array.{
"vectors": [[2,3,4],[4,5,6],[6,7,8]]
}
Validate & Compute Centroid (Code Node): Validates vector dimensions and calculates the centroid.
{
"centroid": [4,5,6]
}
{
"error": "Vectors have inconsistent dimensions."
}
Return Centroid Response (Respond to Webhook Node): Sends the final response back to the client.
{
"centroid": [4, 5, 6]
}
{
"vectors": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
}
Receive Vectors) to receive JSON input.Extract & Parse Vectors) to extract and convert the data.Validate & Compute Centroid) to:Return Centroid Response) to return the result.const input = items[0].json;
const vectors = input.vectors;
if (!Array.isArray(vectors) || vectors.length === 0) {
return [{ json: { error: "Invalid input: Expected an array of vectors." } }];
}
const dimension = vectors[0].length;
if (!vectors.every(v => v.length === dimension)) {
return [{ json: { error: "Vectors have inconsistent dimensions." } }];
}
const centroid = new Array(dimension).fill(0);
vectors.forEach(vector => {
vector.forEach((val, index) => {
centroid[index] += val;
});
});
for (let i = 0; i < dimension; i++) {
centroid[i] /= vectors.length;
}
return [{ json: { centroid } }];
This workflow provides a simple yet flexible solution for vector centroid computation, ensuring validation and reliability.
This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.
| Workflow | Calculate the centroid of a set of vectors |
|---|---|
| Complexity | intermediate |
| Nodes | 8 |
| Categories | Engineering |
| Author | Mauricio Perera |
| Published | 03 Feb 2025 |
Use the JSON export at /data/workflows/2839/2839.json as the source template for this automation.
Open n8n, import the downloaded JSON, and review each node before activating the workflow.
Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.
Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.
Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.
Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.
Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.
n8n Workflow: Calculate the Centroid of a Set of Vectors Overview This workflow receives an array of vectors in JSON format, validates that all vectors have the same dimensions, and computes the ce...
Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.
Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering use case.