14.13.6 Loading and Storing Vector Properties

You can load or store vector properties which are fundamental for PgxML functionality in the graph server (PGX) using PgxFrames.

In order to load a PgxFrame with vector properties, follow the steps as shown:

  1. Create the PgxFrame schema, defining the columns as shown:
    opg4j> var vecFrameSchema = List.of(
      columnDescriptor("intProp", DataTypes.INTEGER_TYPE),
      columnDescriptor("intProp2", DataTypes.INTEGER_TYPE),
      columnDescriptor("vectProp", DataTypes.vector(DataTypes.FLOAT_TYPE, 3)),
      columnDescriptor("stringProp", DataTypes.STRING_TYPE),
      columnDescriptor("vectProp2", DataTypes.vector(DataTypes.FLOAT_TYPE, 2))
    ).toArray(new ColumnDescriptor[0])
    ColumnDescriptor[] vecFrameSchema = {
        columnDescriptor("intProp", DataTypes.INTEGER_TYPE),
        columnDescriptor("intProp2", DataTypes.INTEGER_TYPE),
        columnDescriptor("vectProp", DataTypes.vector(DataTypes.FLOAT_TYPE, 3)),
        columnDescriptor("stringProp", DataTypes.STRING_TYPE),
        columnDescriptor("vectProp2", DataTypes.vector(DataTypes.FLOAT_TYPE, 2))
    };
  2. Load the PgxFrame with the given schema from the specified path:
    opg4j> var vecFrame = session.readFrame().
        db().
        name("vector PgxFrame").
        tablename("tablename").      // name of the table from where the data must be loaded
        jdbcUrl("jdbcUrl").
        username("user").
        owner("owner").              // necessary if the table is owned by another user
        connections(16).             // indicates that 16 connections can be used to load in parallel
        columns(vecFrameSchema).     // columns to load
        load()
    PgxFrame vecFrame = session.readFrame()
        .db()
        .name("vector PgxFrame")
        .tablename("tablename")      // name of the table from where the data must be loaded
        .jdbcUrl("jdbcUrl")
        .username("user")
        .owner("owner")              // necessary if the table is owned by another user
        .connections(16)             // indicates that 16 connections can be used to load in parallel
        .columns(vecFrameSchema)     // columns to load
        .load();
    The final result in the PgxFrame may appear as follows:
    +-----------------------------------------------------------+
    | intProp | intProp2 | vectProp    | stringProp | vectProp2 |
    +-----------------------------------------------------------+
    | 0       | 2        | 0.1;0.2;0.3 | testProp0  | 0.1;0.2   |
    | 1       | 1        | 0.1;0.2;0.3 | testProp10 | 0.1;0.2   |
    | 1       | 2        | 0.1;0.2;0.3 | testProp20 | 0.1;0.2   |
    | 2       | 3        | 0.1;0.2;0.3 | testProp30 | 0.1;0.2   |
    | 3       | 1        | 0.1;0.2;0.3 | testProp40 | 0.1;0.2   |
    +-----------------------------------------------------------+