Skip to main content
Version: Nightly

semantic_relationships

semantic_relationships is the edge set of the semantic graph: typed, time-ranged relationships between entities.

The table is computed, not stored. Scanning it pairs trace spans, applies the co-declaration rules to the declaring tables, and unions the result with the rows of semantic_relationships_declared. It is read-only: INSERT, CREATE, ALTER, TRUNCATE, and DROP are rejected.

SELECT src_id, dst_id, rel_type, provenance, request_count, error_count
FROM greptime_private.semantic_relationships
WHERE observed_at >= now() - INTERVAL '15' MINUTE
ORDER BY dst_id;

The four temporal columns mean different things for a derived edge and for a declared one:

ColumnDerived edgeDeclared edge
observed_atThe 60-second bucket the edge was observed inThe later of the edge's validity start and the queried window's lower bound
window_startStart of that bucketvalid_from, or the declaration time when it is NULL
window_endwindow_start + 60 secondsvalid_until, or the queried window's upper bound when it is NULL
fresh_untilEquals window_endEquals window_end

A declared edge therefore spans its whole validity period rather than a 60-second bucket, and its window_start / window_end / fresh_until are computed on read. The values stored in those columns of semantic_relationships_declared are ignored.

ColumnTypeDescription
observed_atTimestampMillisecondTime index. See the table above.
window_startTimestampMillisecondStart of the window the row covers.
window_endTimestampMillisecondEnd of that window.
fresh_untilTimestampMillisecondTime up to which the edge counts as live.
src_typeStringType of the source endpoint.
src_idStringCanonical id of the source endpoint.
dst_typeStringType of the destination endpoint.
dst_idStringCanonical id of the destination endpoint.
rel_typeStringRelationship kind: calls, runs_on, contains, part_of, uses, invokes, depends_on, owns, or a custom value on a declared edge. Direction is srcdst.
provenanceStringHow the edge was obtained: trace (paired spans), attribute (identities on the same row), declared (asserted by hand), or agent (inferred by an agent).
confidenceFloat64Derivation certainty. 1.0 for a paired edge and 0.5 for a virtual-node edge; a declared edge carries whatever was inserted, NULL included. The intended range is [0, 1], which is not enforced on declared edges. It does not correct for trace sampling.
request_countInt64Requests over the window. calls edges only.
unmatched_countInt64Client spans on this edge with no matching server span. Always NULL for declared edges.
error_countInt64Errored requests over the window.
duration_sumFloat64Sum of request durations, in seconds.
duration_countInt64Number of durations summed.
duration_maxFloat64Longest single request, in seconds, over the population duration_sum covers. Always NULL for declared edges.
attributesJsonEdge attributes, for example {"connection_type":"database"}.

provenance is part of an edge's identity, so a declared edge and a derived edge between the same pair coexist as separate rows.

The observed_at predicate bounds the derivation. Without one, the last hour is used; a predicate with no lower bound is an error. See The query window.

Derivation runs with the querying user's permissions. Source tables the caller cannot read are excluded, and a join-derived edge requires read access to every table it joins.

semantic_relationships_declared

semantic_relationships_declared is a physical table holding the edges you assert yourself. Its rows are unioned into semantic_relationships. GreptimeDB creates it with a canonical schema on the first INSERT and rejects user CREATE and ALTER; INSERT, DELETE, and DROP are allowed. It has a 90-day TTL.

It carries the same columns as semantic_relationships, minus unmatched_count and duration_max, plus:

ColumnTypeDescription
valid_fromTimestampMillisecondStart of business validity. NULL means valid since the declaration.
valid_untilTimestampMillisecondEnd of business validity. NULL means valid for as long as the row exists.
scopeStringNamespace or environment the edge is scoped to. Part of the primary key; not exposed by the computed table.
generation_idStringFree-form generation marker. Part of the primary key; not exposed by the computed table.

The primary key is (src_type, src_id, rel_type, dst_type, dst_id, provenance, scope, generation_id), and observed_at is the time index. Re-inserting the same key stores a new revision; reads keep the latest revision as of the queried window.

window_start, window_end, and fresh_until exist on this table for schema symmetry with the computed one. Reads recompute them from valid_from and valid_until, so writing them has no effect. confidence and the RED columns are passed through unchanged.

See Declaring edges by hand for usage.