This section introduces methods for managing HDC graph and HDC algorithms. Note that these methods require the deployment of HDC servers for the database.
HDC Graph
showHDCGraph()
Retrieves all HDC graphs created from the graph.
Parameters
config: RequestConfig
(Optional): Request configuration.
Returns
HDCGraph[]
: The list of retrieved HDC graphs.
// Retrieves all HDC graphs of the graph 'miniCircle'
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const hdcGraphs = await conn.showHDCGraph(requestConfig);
for (const hdcGraph of hdcGraphs) {
console.log(`${hdcGraph.name} on ${hdcGraph.hdcServerName}`);
}
miniCircle_hdc_graph on hdc-server-1
miniCircle_hdc_graph2 on hdc-server-2
createHDCGraphBySchema()
Creates an HDC graph for the graph.
Parameters
builder: HDCBuilder
: The HDC graph to be created; the attributeshdcGraphName
andhdcServerName
are mandatory,nodeSchema
,edgeSchema
,syncType
,direction
,loadId
, andisDefault
are optional.config: RequestConfig
(Optional): Request configuration.
Returns
JobResponse
: Response of the request.
// Creates an HDC graph named 'test_hdc_graph' for the graph 'miniCircle'
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const nodeSchema = new Map<string, string[]>([
["*", ["*"]]
]);
const edgeSchema = new Map<string, string[]>([
["direct", ["*"]],
["review", ["value", "content"]]
]);
const hdcBuilder : HDCBuilder = {
hdcGraphName: "test_hdc_graph",
hdcServerName: "hdc-server-1",
nodeSchema: nodeSchema,
edgeSchema:edgeSchema,
syncType: HDCSyncType.STATIC,
direction:HDCDirection.UNDIRECTED,
loadId: true,
isDefault: false
};
const response = await conn.createHDCGraphBySchema(hdcBuilder,requestConfig);
const jobID = response.jobId;
await new Promise(resolve => setTimeout(resolve, 3000))
const jobs = await conn.showJob(jobID, requestConfig);
for (const job of jobs) {
console.log(`${job.id} - ${job.status}`);
}
61 - FINISHED
61_1 - FINISHED
dropHDCGraph()
Deletes a specified HDC graph of the graph.
Parameters
hdcGraphName: string
: Name of the HDC graph.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Drops the HDC graph 'miniCircle_hdc_graph2' of the graph 'miniCircle'
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.dropHDCGraph("miniCircle_hdc_graph2",requestConfig);
console.log(response.status?.message)
SUCCESS
HDC Algorithms
showHDCAlgo()
Retrieves all HDC algorithms installed on an HDC server.
Parameters
hdcServerName: string
: Name of the HDC server.config: RequestConfig
(Optional): Request configuration.
Returns
Algo[]
: The list of retrieved HDC algorithms.
// Retrieves all HDC algorithms installed on the HDC server 'hdc-server-1'
const algos = await conn.showHDCAlgo("hdc-server-1", requestConfig);
for (const algo of algos) {
if (algo.type == "algo") {
console.log(
`${algo.name} supports writeback types: ${algo.writeSupportType}`
);
}
}
fastRP supports writeback types: DB,FILE
struc2vec supports writeback types: DB,FILE
installHDCAlgo()
Installs an HDC algorithm on an HDC server.
Parameters
files: string[]
: List of the paths of the installation files, the package file (.so) is necessary while the configuration file (.yml) is optional.hdcServerName: string
: Name of the HDC server.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Installs the HDC algorithm LPA on the HDC server 'hdc-server-1'
const response = await conn.installHDCAlgo(["src/main/resources/algo/libplugin_lpa.so","src/main/resources/algo/lpa.yml"],"hdc-server-1");
console.log(response.status?.message)
SUCCESS
uninstallHDCAlgo()
Uninstalls an HDC algorithm from an HDC server.
Parameters
algoName: string
: Name of the algorithm.hdcServerName: string
: Name of the HDC server.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Uninstalls the HDC algorithm LPA from the HDC server 'hdc-server-1'
const response = await conn.uninstallHDCAlgo("lpa","hdc-server-1");
console.log(response.status?.message)
SUCCESS
rollbackHDCAlgo()
Rolls back a specified HDC algorithm on an HDC server.
Parameters
algoName: string
: Name of the algorithm.hdcServerName: string
: Name of the HDC server.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Rolls back the HDC algorithms LPA on the HDC server 'hdc-server-1'
const response = await conn.rollbackHDCAlgo("lpa","hdc-server-1");
console.log(response.status?.message)
SUCCESS
Full Example
import { UltipaDriver } from "@ultipa-graph/ultipa-driver";
import { ULTIPA } from "@ultipa-graph/ultipa-driver/dist/types";
let sdkUsage = async () => {
// URI example: ultipaConfig.hosts: ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
const ultipaConfig: ULTIPA.UltipaConfig = {
hosts: ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"],
username: "<username>",
password: "<password>"
};
const conn = new UltipaDriver(ultipaConfig);
const isSuccess = await conn.test();
console.log(`Connection succeeds: ${isSuccess}`);
// Installs the HDC algorithm LPA on the HDC server 'hdc-server-1'
const response = await conn.installHDCAlgo(
[
"src/main/resources/algo/libplugin_lpa.so",
"src/main/resources/algo/lpa.yml",
],
"hdc-server-1"
);
console.log(response.status?.message);
};
sdkUsage().catch(console.error);