graphingest

package
v1.0.0-beta.95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

graph-ingest

Entity and triple ingestion component for the graph subsystem.

Overview

The graph-ingest component is the entry point for all entity data flowing into the graph system. It subscribes to JetStream subjects for incoming entity events and stores them in the ENTITY_STATES KV bucket.

Architecture

                    ┌─────────────────┐
objectstore.stored ─┤                 │
                    │  graph-ingest   ├──► ENTITY_STATES (KV)
sensor.processed   ─┤                 │
                    └─────────────────┘

Features

  • Entity CRUD: Create, read, update, delete entity operations
  • Triple Mutations: Add and remove triples on entities
  • Hierarchy Inference: Automatically creates container entities based on 6-part entity ID structure
  • At-Least-Once Delivery: JetStream subscription with proper acknowledgment

Configuration

{
  "type": "processor",
  "name": "graph-ingest",
  "enabled": true,
  "config": {
    "ports": {
      "inputs": [
        {
          "name": "objectstore_in",
          "subject": "objectstore.stored.entity",
          "type": "jetstream",
          "interface": "storage.stored.v1"
        },
        {
          "name": "sensor_in",
          "subject": "sensor.processed.entity",
          "type": "jetstream",
          "interface": "iot.sensor.v1"
        }
      ],
      "outputs": [
        {
          "name": "entity_states",
          "subject": "ENTITY_STATES",
          "type": "kv"
        }
      ]
    },
    "enable_hierarchy": true
  }
}
Configuration Options
Option Type Default Description
ports object required Port configuration for inputs and outputs
enable_hierarchy bool false Enable automatic hierarchy inference

Ports

Inputs
Name Type Subject Description
objectstore_in jetstream objectstore.stored.entity Stored document entity events
sensor_in jetstream sensor.processed.entity Sensor entity events
Outputs
Name Type Subject Description
entity_states kv ENTITY_STATES Entity state storage

Hierarchy Inference

When enable_hierarchy is enabled, the component automatically creates container entities based on the 6-part entity ID structure:

org.platform.domain.system.type.instance
 │      │       │      │     │      │
 └──────┴───────┴──────┴─────┴──────┴─► Real entity
        │       │      │     │
        └───────┴──────┴─────┴─► Type container (*.group)
                │      │
                └──────┴─► System container (*.container)
                       │
                       └─► Domain container (*.level)

This creates edges that enable:

  • Efficient traversal by type, system, or domain
  • Automatic grouping without explicit relationship creation
  • Query-time aggregation by hierarchy level

Dependencies

Upstream
  • None (entry point component)
Downstream
  • graph-index - watches ENTITY_STATES for index updates
  • graph-embedding - watches ENTITY_STATES for embedding generation
  • graph-clustering - watches ENTITY_STATES for community detection triggers

Metrics

Metric Type Description
graph_ingest_entities_processed_total counter Total entities processed
graph_ingest_triples_added_total counter Total triples added
graph_ingest_errors_total counter Total processing errors
graph_ingest_processing_duration_seconds histogram Processing time per entity

Health

The component reports healthy when:

  • JetStream subscription is active
  • KV bucket is accessible
  • No sustained error rate above threshold

Documentation

Overview

Package graphingest provides the graph-ingest component for entity and triple ingestion.

Package graphingest provides the graph-ingest component for entity and triple ingestion.

Overview

The graph-ingest component is responsible for ingesting entities and triples into the graph system. It subscribes to JetStream subjects for incoming entity data and stores them in the ENTITY_STATES KV bucket.

Tier

Tier: ALL TIERS (Tier 0, 1, 2) - Required for all deployments.

Architecture

graph-ingest is a core component required for all deployment tiers (Structural, Statistical, Semantic). It serves as the entry point for all entity data flowing into the graph subsystem.

                    ┌─────────────────┐
objectstore.stored ─┤                 │
                    │  graph-ingest   ├──► ENTITY_STATES (KV)
sensor.processed   ─┤                 │
                    └─────────────────┘

Features

  • Entity CRUD operations (create, read, update, delete)
  • Triple mutations (add, remove)
  • Hierarchy inference (optional) - creates container entities based on 6-part entity ID structure
  • JetStream subscription with at-least-once delivery semantics
  • KV storage with atomic updates

Configuration

The component is configured via JSON with the following structure:

{
  "ports": {
    "inputs": [
      {"name": "objectstore_in", "subject": "objectstore.stored.entity", "type": "jetstream"},
      {"name": "sensor_in", "subject": "sensor.processed.entity", "type": "jetstream"}
    ],
    "outputs": [
      {"name": "entity_states", "subject": "ENTITY_STATES", "type": "kv"}
    ]
  },
  "enable_hierarchy": true
}

Port Definitions

Inputs:

  • JetStream subscriptions for entity events (objectstore.stored.entity, sensor.processed.entity)

Outputs:

  • KV bucket: ENTITY_STATES - stores entity state with triples

Hierarchy Inference

When enable_hierarchy is true, the component automatically creates container entities based on the 6-part entity ID structure (org.platform.domain.system.type.instance). This creates edges for:

  • Type containers (*.group)
  • System containers (*.container)
  • Domain containers (*.level)

Usage

Register the component with the component registry:

import graphingest "github.com/c360studio/semstreams/processor/graph-ingest"

func init() {
    graphingest.Register(registry)
}

Dependencies

This component has no upstream graph component dependencies. It is the entry point for entity data and other graph components (graph-index, graph-embedding, etc.) watch its output KV bucket.

Package graphingest mutation handlers for triple and entity operations via NATS request/reply.

Package graphingest query handlers

Index

Constants

View Source
const (
	// SubjectTripleAdd is the NATS subject for add triple requests
	SubjectTripleAdd = "graph.mutation.triple.add"
	// SubjectTripleAddBatch is the NATS subject for batched add-triple
	// requests. Optimised for tools that emit many triples in one call
	// (write_todos per ADR-036): triples sharing a Subject collapse to
	// one CAS round-trip on that entity.
	SubjectTripleAddBatch = "graph.mutation.triple.add_batch"
	// SubjectTripleRemove is the NATS subject for remove triple requests
	SubjectTripleRemove = "graph.mutation.triple.remove"

	// SubjectEntityCreate is the NATS subject for create-or-fail entity
	// requests. Returns Success=false with "entity already exists" when
	// the entity ID is present — lets a CS API POST surface 409 Conflict
	// without a separate existence pre-check.
	SubjectEntityCreate = "graph.mutation.entity.create"

	// SubjectEntityCreateWithTriples is the NATS subject for atomic
	// entity+triples creation. Carries the full EntityState shape
	// (MessageType, Version, StorageRef) so provenance fields survive
	// — fields AddTriple synthesizes with defaults. Same create-or-fail
	// semantics as SubjectEntityCreate.
	SubjectEntityCreateWithTriples = "graph.mutation.entity.create_with_triples"

	// SubjectEntityUpdate is the NATS subject for must-exist entity
	// updates. Returns Success=false with "entity not found" when the
	// entity ID is absent — lets a CS API PUT/PATCH surface 404 without
	// silently upserting a new entity.
	SubjectEntityUpdate = "graph.mutation.entity.update"

	// SubjectEntityUpdateWithTriples is the NATS subject for must-exist
	// entity updates with triple-set deltas. AddTriples appends; the
	// RemoveTriples slice names predicates whose triples are removed.
	// PR-A applies the delta via read-modify-write (TOCTOU window
	// possible); PR-B will switch to a single CAS over the entity state
	// to close the partial-erasure window semconnect Stage 27 flagged.
	SubjectEntityUpdateWithTriples = "graph.mutation.entity.update_with_triples"

	// SubjectEntityDelete is the NATS subject for entity-scoped delete.
	// Idempotent — deleting a non-existent entity returns Success=true,
	// Deleted=false (the NATS KV Delete primitive is itself idempotent).
	SubjectEntityDelete = "graph.mutation.entity.delete"
)

Variables

This section is empty.

Functions

func CreateGraphIngest

func CreateGraphIngest(rawConfig json.RawMessage, deps component.Dependencies) (component.Discoverable, error)

CreateGraphIngest is the factory function for creating graph-ingest components

func Register

func Register(registry *component.Registry) error

Register registers the graph-ingest factory with the component registry

Types

type Component

type Component struct {
	// contains filtered or unexported fields
}

Component implements the graph-ingest processor

func (*Component) AddTriple

func (c *Component) AddTriple(ctx context.Context, triple message.Triple) error

AddTriple adds a triple to an entity using CAS for concurrency safety

func (*Component) AddTriples

func (c *Component) AddTriples(ctx context.Context, triples []message.Triple) (writtenCount int, failedSubjects map[string]string, err error)

AddTriples adds many triples in one call, batching per entity. Triples sharing the same Subject collapse to a single CAS read-modify-write on that entity's KV record — N triples on the same loop entity become 1 round-trip to graph-ingest, not N. Triples spanning multiple entities issue one CAS per entity in deterministic subject order.

Atomicity scope: per-entity, not cross-entity. If two entities are in the batch and the first commits but the second exhausts CAS retries, the first stays committed. This trade-off is acceptable for the primary use case (write_todos, ADR-036) where every triple shares one Subject (the loop entity). Multi-subject callers that need cross-entity atomicity should use UpdateEntityWithTriples instead.

Returns nil on full success. On partial failure returns an error whose message names the failing subjects; the per-subject error detail surfaces via the handler's FailedSubjects response field.

func (*Component) ConfigSchema

func (c *Component) ConfigSchema() component.ConfigSchema

ConfigSchema returns the configuration schema

func (*Component) CreateEntity

func (c *Component) CreateEntity(ctx context.Context, entity *graph.EntityState) error

CreateEntity creates a new entity in the graph using upsert (Put) semantics. Existing callers that need last-writer-wins behavior (graph/datamanager edge ops) stay on this path. New atomic-create callers (the NATS mutation handlers' POST 409 path) use CreateEntityStrict, which fails fast with natsclient.ErrKVKeyExists when the ID is already present.

func (*Component) CreateEntityStrict

func (c *Component) CreateEntityStrict(ctx context.Context, entity *graph.EntityState) error

CreateEntityStrict creates a new entity atomically — if the ID is already present, returns natsclient.ErrKVKeyExists without overwriting. Closes the concurrent-create TOCTOU window the graph.mutation.entity.create handler used to have when it relied on exists-check + Put.

func (*Component) DataFlow

func (c *Component) DataFlow() component.FlowMetrics

DataFlow returns current data flow metrics

func (*Component) DeleteEntity

func (c *Component) DeleteEntity(ctx context.Context, entityID string) error

DeleteEntity removes an entity from the graph

func (*Component) Health

func (c *Component) Health() component.HealthStatus

Health returns current health status

func (*Component) Initialize

func (c *Component) Initialize() error

Initialize validates configuration and sets up ports (no I/O)

func (*Component) InputPorts

func (c *Component) InputPorts() []component.Port

InputPorts returns input port definitions. Reads directly from config so ports are available before Initialize().

func (*Component) MergeEntity

func (c *Component) MergeEntity(ctx context.Context, entity *graph.EntityState) error

MergeEntity ingests a streaming-consumer EntityState (typically built by extractEntityFromMessage from a Graphable arriving on the JetStream input) WITHOUT clobbering pre-existing triples on the entity. First write behaves like CreateEntity (the entity didn't exist; its fields land verbatim); subsequent writes append the incoming triples to the existing slice and refresh latest-wins metadata (MessageType, StorageRef, UpdatedAt) while monotonically bumping Version.

Closes gh#177: the prior code called CreateEntity (Put = full- replace) from handleMessage, which erased any triples written via the atomic mutation handlers (create_with_triples, update_with_ triples, triple.add) — all of which merge. The jetstream consumer path was the lone outlier. Lifecycle-managed entities surfaced this most loudly: Manager.Create stamped the phase triple, then the first Graphable arrival via a downstream processor wiped it.

Uses entityBucket.UpdateWithRetry for atomic CAS read-modify-write, so concurrent arrivals on the same Subject converge without racing.

func (*Component) Meta

func (c *Component) Meta() component.Metadata

Meta returns component metadata

func (*Component) OutputPorts

func (c *Component) OutputPorts() []component.Port

OutputPorts returns output port definitions. Reads directly from config so ports are available before Initialize().

func (*Component) RemoveTriple

func (c *Component) RemoveTriple(ctx context.Context, subject, predicate string) error

RemoveTriple removes a triple from an entity using CAS for concurrency safety

func (*Component) Start

func (c *Component) Start(ctx context.Context) error

Start begins processing (must be initialized first)

func (*Component) Stop

func (c *Component) Stop(timeout time.Duration) error

Stop gracefully shuts down the component

func (*Component) UpdateEntity

func (c *Component) UpdateEntity(ctx context.Context, entity *graph.EntityState) error

UpdateEntity updates an existing entity

type Config

type Config struct {
	Ports              *component.PortConfig `json:"ports" schema:"type:ports,description:Port configuration,category:basic"`
	EnableHierarchy    bool                  `json:"enable_hierarchy" schema:"type:bool,description:Enable hierarchy inference,default:false,category:advanced"`
	EnableTypeSiblings *bool                 `` /* 162-byte string literal not displayed */
}

Config holds configuration for graph-ingest component

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a valid default configuration

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults sets default values for configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate implements component.Validatable interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL