3.0 KiB
3.0 KiB
Backend (Go) – Graph + Selection API
This service exposes a small HTTP API for:
- Building and caching a “graph snapshot” from AnzoGraph via SPARQL (
/api/graph) - Returning available “graph query” and “selection query” modes
- Running selection queries for the currently selected node IDs
- (Optionally) issuing raw SPARQL passthrough for debugging
Run
Via Docker Compose (recommended):
docker compose up --build backend
The backend listens on :8000 (configurable via LISTEN_ADDR).
Configuration (env)
See backend_go/config.go for the full set.
Important variables:
- Snapshot limits:
DEFAULT_NODE_LIMIT,DEFAULT_EDGE_LIMITMAX_NODE_LIMIT,MAX_EDGE_LIMIT
- SPARQL connectivity:
SPARQL_HOST(defaulthttp://anzograph:8080) orSPARQL_ENDPOINTSPARQL_USER,SPARQL_PASS
- Startup behavior:
SPARQL_LOAD_ON_START,SPARQL_CLEAR_ON_STARTSPARQL_DATA_FILE(typicallyfile:///opt/shared-files/<file>.ttl)
- Other:
INCLUDE_BNODES(include blank nodes in snapshots)CORS_ORIGINS
Endpoints
GET /api/healthGET /api/statsGET /api/graph?node_limit=&edge_limit=&graph_query_id=GET /api/graph_queriesGET /api/selection_queriesPOST /api/selection_query- Body:
{"query_id":"neighbors","selected_ids":[1,2,3],"node_limit":...,"edge_limit":...,"graph_query_id":"default"}
- Body:
POST /api/sparql(raw passthrough)POST /api/neighbors(legacy alias ofquery_id="neighbors")
Graph snapshots
Snapshots are built by:
- Running a SPARQL edge query (controlled by
graph_query_id) - Converting SPARQL bindings into dense integer node IDs + edge list
- Computing a layout and fetching optional
rdfs:label
Snapshots are cached in-memory keyed by:
node_limit,edge_limit,INCLUDE_BNODES,graph_query_id
Query registries
Graph query modes (graph_query_id)
Stored under backend_go/graph_queries/ and listed by GET /api/graph_queries.
Built-in modes:
default–rdf:type(toowl:Class) +rdfs:subClassOfhierarchy–rdfs:subClassOfonlytypes–rdf:type(toowl:Class) only
To add a new mode:
- Add a new file under
backend_go/graph_queries/that returns a SPARQL query selecting?s ?p ?o. - Register it in
backend_go/graph_queries/registry.go.
Selection query modes (query_id)
Stored under backend_go/selection_queries/ and listed by GET /api/selection_queries.
Built-in modes:
neighbors– type + subclass neighbors (both directions)superclasses–?sel rdfs:subClassOf ?nbrsubclasses–?nbr rdfs:subClassOf ?sel
To add a new mode:
- Add a new file under
backend_go/selection_queries/that returns neighbor node IDs. - Register it in
backend_go/selection_queries/registry.go.
Performance notes
- Memory usage is dominated by the cached snapshot (
[]Node,[]Edge) and the temporary SPARQL JSON unmarshalling step. - Tune
DEFAULT_NODE_LIMIT/DEFAULT_EDGE_LIMITfirst if memory is too high.