OpenAI Analytics icon

OpenAI Analytics

Use OpenAI Analytics API

Overview

The "Embedding Based Classify" operation in this node enables classification of input text by leveraging vector embeddings and similarity comparison. It works by embedding the target text and comparing it against embeddings of predefined categories to find the best matching category or multiple categories above a similarity threshold.

This approach is useful when you want to classify text based on semantic similarity rather than keyword matching, making it effective for nuanced or context-dependent categorization tasks. For example, it can be used to:

  • Automatically tag customer feedback into sentiment categories like "positive," "neutral," or "negative."
  • Classify support tickets into issue types based on their content.
  • Group product descriptions into relevant categories for e-commerce.

The node supports creating new category embeddings on the fly or using previously saved category embeddings, allowing flexibility depending on whether categories are static or dynamic.

Properties

Name Meaning
Authentication Choose between using dedicated OpenAI Analytics API credentials or existing OpenAI API credentials for authentication.
Target Text The text string that you want to classify using embeddings.
Model The embedding model to use for generating embeddings for classification. Options are dynamically loaded from available embedding models (e.g., text-embedding-3-small).
Categories Mode Whether to create new category embeddings ("Create New Categories") or use previously saved category embeddings ("Use Saved Categories").
Categories A collection of categories for classification. Each category includes:
- Category name (string)
- Optional embedding vector (JSON array). If embedding is empty, it will be auto-generated.
Similarity Threshold Minimum similarity score (between 0 and 1) required for a category to be considered a match during classification.
Classification Type Classification method:
- Single (Best Match): Returns only the best matching category.
- Multiple (All Above Threshold): Returns all categories with similarity above the threshold.
Use Branch Outputs Boolean flag to enable branching in the workflow based on classification results, allowing different paths depending on the classification outcome.

Output

The output JSON contains the classification results based on the similarity of the target text embedding to the category embeddings. Depending on the classification type, the output may include:

  • The single best matching category with its similarity score.
  • Multiple categories that exceed the similarity threshold, each with their similarity scores.

If branching is enabled, the node also supports outputting data that can be used to route execution flow according to classification results.

No binary data output is indicated for this operation.

Dependencies

  • Requires an API key credential for OpenAI services, either via dedicated OpenAI Analytics API credentials or standard OpenAI API credentials.
  • Uses OpenAI's embedding models to generate vector representations of text and categories.
  • The node dynamically loads available embedding models from the OpenAI API.
  • Proper network access to OpenAI endpoints is necessary.

Troubleshooting

  • Missing or invalid API credentials: Ensure that valid API keys are configured in n8n for the selected authentication method.
  • Empty or missing category names: The node throws an error if any category name is empty when generating embeddings.
  • Similarity threshold too high: Setting the threshold close to 1 may result in no categories matching; try lowering the threshold.
  • Model loading errors: If embedding models fail to load, fallback default models are provided, but verify API connectivity.
  • Input text empty: The target text must be non-empty; otherwise, classification cannot proceed.
  • Branching not working as expected: Verify that "Use Branch Outputs" is enabled and that downstream nodes are configured to handle branches correctly.

Links and References

Discussion