Skip to content

Installation

Install the package, set up the native TensorFlow backend, and verify everything works.

Terminal window
deno add jsr:@casys/shgat

Published on JSR, the modern JavaScript registry.

DependencyMinimum VersionNotes
Deno2.0+FFI requires --unstable-ffi flag
libtensorflow2.15.xNative C library (see below)
Linux x86_64Ubuntu 20.04+ / Debian 11+macOS x86_64 also supported
CUDA (optional)11.8+Only for GPU acceleration

@casys/shgat uses the C TensorFlow library directly via Deno.dlopen. You need libtensorflow installed on your system.

Terminal window
./scripts/install-libtensorflow.sh # CPU (default)
./scripts/install-libtensorflow.sh gpu # GPU (requires CUDA 11.8+)
Terminal window
# Download libtensorflow 2.15.0 (CPU)
curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.15.0.tar.gz \
-o /tmp/libtensorflow.tar.gz
# Extract to /usr/local
sudo tar -C /usr/local -xzf /tmp/libtensorflow.tar.gz
# Update library cache
sudo ldconfig
# Verify
ls /usr/local/lib/libtensorflow.so

Create a test-shgat.ts file:

import { createSHGAT, type Node } from "@casys/shgat";
const nodes: Node[] = [
{ id: "tool-a", embedding: new Array(1024).fill(0.1), children: [], level: 0 },
{ id: "tool-b", embedding: new Array(1024).fill(0.2), children: [], level: 0 },
{ id: "group", embedding: new Array(1024).fill(0.15), children: ["tool-a", "tool-b"], level: 1 },
];
const model = createSHGAT(nodes);
console.log(`Nodes registered: ${model.getToolCount()} leaves, ${model.getCapabilityCount()} composites`);
const scores = model.scoreNodes(new Array(1024).fill(0.1));
console.log("Top result:", scores[0]?.nodeId, scores[0]?.score.toFixed(4));
model.dispose();

Run it:

Terminal window
deno run --unstable-ffi --allow-ffi test-shgat.ts

Score your first real nodes and see ranked results: Quick Start.