Change Password

Please enter the password.
Please enter the password. Between 8-64 characters. Not identical to your email address. Contain at least 3 of: uppercase, lowercase, numbers, and special characters.
Please enter the password.
Submit

Change Nickname

Current Nickname:
Submit

Apply New License

License Detail

Please complete this required field.

  • Ultipa Blaze (v4)
  • Ultipa Powerhouse (v5)

Standalone

learn more about the four main severs in the architecture of Ultipa Powerhouse (v5) , click

here

Please complete this required field.

Please complete this required field.

Please complete this required field.

Please complete this required field.

Leave it blank if an HDC service is not required.

Please complete this required field.

Leave it blank if an HDC service is not required.

Please complete this required field.

Please complete this required field.

Mac addresses of all servers, separated by line break or comma.

Please complete this required field.

Please complete this required field.

Cancel
Apply
ID
Product
Status
Cores
Maximum Shard Services
Maximum Total Cores for Shard Service
Maximum HDC Services
Maximum Total Cores for HDC Service
Applied Validity Period(days)
Effective Date
Expired Date
Mac Address
Reason for Application
Review Comment
Close
Profile
  • Full Name:
  • Phone:
  • Company:
  • Company Email:
Change Password
Apply

You have no license application record.

Apply
Certificate Issued at Valid until Serial No. File
Serial No. Valid until File

Not having one? Apply now! >>>

Product Created On ID Amount (USD) Invoice
Product Created On ID Amount (USD) Invoice

No Invoice

v5.2
Search
    English
    v5.2

      Cosine Similarity

      HDC

      Overview

      In cosine similarity, data objects in a dataset are treated as vectors, and it uses the cosine value of the angle between two vectors to indicate the similarity between them. In the graph, N numeric node properties (features) are specified to form N-dimensional vectors; two nodes are considered similar if their vectors are similar.

      Cosine similarity ranges from -1 to 1, where 1 indicates that the two vectors point in the same direction, and -1 indicates they point in opposite directions.

      In 2-dimensional space, the cosine similarity between vectors A(a1, a2) and B(b1, b2) is computed as:

      In 3-dimensional space, the cosine similarity between vectors A(a1, a2, a3) and B(b1, b2, b3) is computed as:

      The following diagram shows the relationship between vectors A and B in 2D and 3D spaces, as well as the angle θ between them:

      Generalized to N-dimensional space, cosine similarity is computed as:

      Considerations

      • Theoretically, the calculation of cosine similarity between two nodes is independent of their connectivity in the graph.
      • The value of cosine similarity is independent of the length of the vectors, but only the direction of the vectors.

      Example Graph

      Run the following statements on an empty graph to define its structure and insert data:

      ALTER GRAPH CURRENT_GRAPH ADD NODE {
        product ({price int32, weight int32, width int32, height int32})
      };
      INSERT (:product {_id:"product1", price:50, weight:160, width:20, height:152}),
             (:product {_id:"product2", price:42, weight:90, width:30, height:90}),
             (:product {_id:"product3", price:24, weight:50, width:55, height:70}),
             (:product {_id:"product4", price:38, weight:20, width:32, height:66});
      

      create().node_schema("product");
      create().node_property(@product, "price", int32).node_property(@product, "weight", int32).node_property(@product, "width", int32).node_property(@product, "height", int32);
      insert().into(@product).nodes([{_id:"product1", price:50, weight:160, width:20, height:152}, {_id:"product2", price:42, weight:90, width:30, height:90}, {_id:"product3", price:24, weight:50, width:55, height:70}, {_id:"product4", price:38, weight:20, width:32, height:66}]);
      

      Creating HDC Graph

      To load the entire graph to the HDC server hdc-server-1 as my_hdc_graph:

      CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS {
        nodes: {"*": ["*"]},
        edges: {"*": ["*"]},
        direction: "undirected",
        load_id: true,
        update: "static"
      }
      

      hdc.graph.create("my_hdc_graph", {
        nodes: {"*": ["*"]},
        edges: {"*": ["*"]},
        direction: "undirected",
        load_id: true,
        update: "static"
      }).to("hdc-server-1")
      

      Parameters

      Algorithm name: similarity

      Name Type Spec Default Optional Description
      ids/uuids _id/_uuid
      /
      /
      Yes Specifies the first group of nodes by their _id or _uuid. If unset, all nodes in the graph are used as the first group of nodes. The algorithm supports two calculation modes:

      • Pairing mode: When both ids/uuids and ids2/uuids2 are set, each node in ids/uuids is paired with each node in ids2/uuids2 (excluding self-pairs), and their pairwise similarities are computed.
      • Selection mode: When only ids/uuids is set, the algorithm computes similarities between each specified node and all other nodes in the graph. Results include all (or a limited number of) nodes with a similarity > 0, sorted in descending order.
      ids2/uuids2 _id/_uuid
      /
      /
      Yes Specifies the second group of nodes for pairwise similarity by their _id or _uuid. If only ids2/uuids2 is set (and ids/uuids is not), the algorithm returns no result.
      type String cosine cosine No Specifies the type of similarity to compute; for Cosine Similarity, keep it as cosine.
      node_schema_property []"<@schema.?><property>"
      /
      /
      No Specifies numeric node properties to form a vector for each node; all specified properties must belong to the same label (schema).
      return_id_uuid String uuid,id,both uuid Yes Includes _uuid, _id, or both to represent nodes in the results.
      order String asc,desc
      /
      Yes Sorts the results by similarity.
      limit Integer ≥-1 -1 Yes Limits the number of results returned. Set to -1 to include all results.
      top_limit Integer ≥-1 -1 Yes Limits the number of results returned for each node specified with ids/uuids in selection mode. Set to -1 to include all results with a similarity greater than 0. This parameter is invalid in pairing mode.

      File Writeback

      CALL algo.similarity.write("my_hdc_graph", {
        return_id_uuid: "id",
        ids: "product1",
        ids2: ["product2", "product3", "product4"],
        node_schema_property: ["price", "weight", "width", "height"],
        type: "cosine"
      }, {
        file: {
          filename: "cosine"
        }
      })
      

      algo(similarity).params({
        projection: "my_hdc_graph",
        return_id_uuid: "id",
        ids: "product1",
        ids2: ["product2", "product3", "product4"],
        node_schema_property: ["price", "weight", "width", "height"],
        type: "cosine"
      }).write({
        file: {
          filename: "cosine"
        }
      })
      

      Result:

      _id1,_id2,similarity
      product1,product2,0.986529
      product1,product3,0.878858
      product1,product4,0.816876
      

      Full Return

      CALL algo.similarity.run("my_hdc_graph", {
        return_id_uuid: "id",
        ids: ["product1","product2"], 
        ids2: ["product2","product3","product4"],
        node_schema_property: ["price", "weight", "width", "height"],
        type: "cosine"
      }) YIELD cs
      RETURN cs
      

      exec{
        algo(similarity).params({
          return_id_uuid: "id",
          ids: ["product1","product2"], 
          ids2: ["product2","product3","product4"],
          node_schema_property: ["price", "weight", "width", "height"],
          type: "cosine"
        }) as cs
        return cs
      } on my_hdc_graph
      

      Result:

      _id1 _id2 similarity
      product1 product2 0.986529
      product1 product3 0.878858
      product1 product4 0.816876
      product2 product3 0.934217
      product2 product4 0.881988

      Stream Return

      CALL algo.similarity.stream("my_hdc_graph", {
        return_id_uuid: "id",
        ids: ["product1", "product3"], 
        node_schema_property: ["price", "weight", "width", "height"],
        type: "cosine",
        top_limit: 1    
      }) YIELD top
      RETURN top
      

      exec{
        algo(similarity).params({
          return_id_uuid: "id",
          ids: ["product1", "product3"], 
          node_schema_property: ["price", "weight", "width", "height"],
          type: "cosine",
          top_limit: 1        
        }).stream() as cs
        return cs
      } on my_hdc_graph
      

      Result:

      _id1 _id2 similarity
      product1 product2 0.986529
      product3 product2 0.934217
      Please complete the following information to download this book
      *
      公司名称不能为空
      *
      公司邮箱必须填写
      *
      你的名字必须填写
      *
      你的电话必须填写
      Privacy Policy
      Please agree to continue.

      Copyright © 2019-2025 Ultipa Inc. – All Rights Reserved   |  Security   |  Legal Notices   |  Web Use Notices