OpenAI Analytics icon

OpenAI Analytics

Use OpenAI Analytics API

Embedding → Cosine Similarity

AI-generated

Overview

This node operation calculates the cosine similarity between two embedding vectors. Cosine similarity is a measure of similarity between two non-zero vectors that calculates the cosine of the angle between them, commonly used in machine learning and natural language processing to compare text embeddings or other vector representations.

Typical use cases include:

  • Comparing semantic similarity between two pieces of text represented as embeddings.
  • Measuring how close two feature vectors are in vector space for clustering or classification tasks.
  • Validating or analyzing embedding outputs from models by quantifying their similarity.

For example, you might input two sentence embeddings to determine how semantically similar the sentences are, which can be useful in recommendation systems, search ranking, or duplicate detection.

Properties

Name Meaning
Authentication Choose which API credentials to use: either dedicated OpenAI Analytics API credentials or existing OpenAI API credentials.
입력 방식 (cosineInputType) Method to provide the embedding vectors:
- 직접 입력 (direct): Enter vectors directly as JSON or comma/space-separated values.
- JSON 경로 (jsonPath): Extract vectors from specified JSON paths in input data.
- 바이너리 속성 (binaryProperty): Extract vectors from binary properties in input data.
Embedding Vector 1 (vector1) The first embedding vector provided directly as a string in JSON format or as comma/space-separated numbers. Required if input type is "direct".
Embedding Vector 2 (vector2) The second embedding vector provided directly as a string in JSON format or as comma/space-separated numbers. Required if input type is "direct".
Embedding Vector 1 Path (vector1Path) JSON path to extract the first embedding vector from input data. Required if input type is "jsonPath".
Embedding Vector 2 Path (vector2Path) JSON path to extract the second embedding vector from input data. Required if input type is "jsonPath".
Embedding Vector 1 Binary Property (vectorProperty1) Name of the binary property containing the first embedding vector. Required if input type is "binaryProperty".
Embedding Vector 2 Binary Property (vectorProperty2) Name of the binary property containing the second embedding vector. Required if input type is "binaryProperty".

Output

The output contains a JSON object with the cosine similarity score between the two vectors. This score is a numeric value typically ranging from -1 to 1, where 1 means the vectors are identical in direction, 0 means orthogonal (no similarity), and -1 means opposite directions.

Example output JSON structure:

{
  "cosineSimilarity": 0.87
}

There is no binary output for this operation.

Dependencies

  • Requires an API key credential for OpenAI services, either through dedicated OpenAI Analytics API credentials or standard OpenAI API credentials.
  • The node uses internal helper functions to parse and handle embedding vectors but does not call external APIs for cosine similarity calculation itself.
  • No additional environment variables or configurations beyond valid API credentials are required for this operation.

Troubleshooting

  • Invalid Vector Format: If the input vectors are not properly formatted JSON arrays or comma/space-separated numbers, the node may throw parsing errors. Ensure vectors are correctly formatted.
  • Missing Vectors: When using JSON path or binary property input types, ensure the specified paths or property names exist in the input data; otherwise, the node will fail to retrieve vectors.
  • Dimension Mismatch: Cosine similarity requires vectors of the same dimension. If vectors differ in length, the node may error or produce invalid results.
  • Credential Errors: If API credentials are missing or invalid, the node will fail during initialization. Verify that the correct API key credential is selected and configured.
  • Empty Input Data: If the input data array is empty or does not contain expected fields, the node cannot compute similarity.

Links and References

Discussion