UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Similarity

Vector Similarity

Overview

Computes the similarity between two given numeric vectors. Unlike other similarity algorithms that operate on graph structure or node properties, this algorithm works directly on user-provided vectors.

Four metrics are supported:

  • Cosine: Cosine of the angle between two vectors. See Cosine Similarity for details.
  • Pearson: Linear correlation between two vectors. See Pearson Correlation Coefficient for details.
  • Euclidean: Normalized Euclidean distance between two vectors. See Euclidean Distance for details.
  • Jaccard: Ratio of positions where both vectors are non-zero to positions where at least one is non-zero. See Jaccard Similarity for details.

Parameters

NameTypeDefaultDescription
vector1LIST/Required. First numeric vector.
vector2LIST/Required. Second numeric vector.
metricSTRINGcosineSimilarity metric: cosine, pearson, euclidean, or jaccard.

Run Mode

Returns:

ColumnTypeDescription
similarityFLOATComputed similarity score

Cosine similarity:

GQL
CALL algo.similarityvec({
  vector1: [1.0, 2.0, 3.0],
  vector2: [4.0, 5.0, 6.0]
}) YIELD similarity

Result:

similarity
0.9746318461970762

Pearson correlation:

GQL
CALL algo.similarityvec({
  vector1: [1.0, 2.0, 3.0],
  vector2: [4.0, 5.0, 6.0],
  metric: "pearson"
}) YIELD similarity

Result:

similarity
1

Euclidean distance:

GQL
CALL algo.similarityvec({
  vector1: [1.0, 2.0],
  vector2: [4.0, 6.0],
  metric: "euclidean"
}) YIELD similarity

Result:

similarity
0.16666666666666666

Jaccard similarity:

GQL
CALL algo.similarityvec({
  vector1: [1.0, 2.0, 3.0],
  vector2: [2.0, 3.0, 4.0],
  metric: "jaccard"
}) YIELD similarity

Result:

similarity
1

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.similarityvec.stream({
  vector1: [1.0, 2.0, 3.0],
  vector2: [4.0, 5.0, 6.0]
}) YIELD similarity
RETURN similarity

Result:

similarity
0.9746318461970762

Stats Mode

Returns:

ColumnTypeDescription
similarityFLOATComputed similarity score
GQL
CALL algo.similarityvec.stats({
  vector1: [1.0, 2.0, 3.0],
  vector2: [4.0, 5.0, 6.0]
}) YIELD similarity

Result:

similarity
0.9746318461970762