graphindexspatial

package
v1.0.0-alpha.34 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 17 Imported by: 0

README

graph-index-spatial

Geospatial indexing component for the graph subsystem.

Overview

The graph-index-spatial component watches the ENTITY_STATES KV bucket and maintains a geospatial index for entities with location data. This enables efficient spatial queries.

Architecture

                    ┌─────────────────────┐
ENTITY_STATES ─────►│                     │
   (KV watch)       │  graph-index-spatial├──► SPATIAL_INDEX (KV)
                    │                     │
                    └─────────────────────┘

Features

  • Geohash Indexing: Efficient spatial indexing using geohash algorithm
  • Configurable Precision: 1-12 precision levels for different use cases
  • Automatic Location Extraction: Extracts lat/lon from entity triples
  • Batch Processing: Efficient bulk index updates

Configuration

{
  "type": "processor",
  "name": "graph-index-spatial",
  "enabled": true,
  "config": {
    "ports": {
      "inputs": [
        {
          "name": "entity_watch",
          "subject": "ENTITY_STATES",
          "type": "kv-watch"
        }
      ],
      "outputs": [
        {
          "name": "spatial_index",
          "subject": "SPATIAL_INDEX",
          "type": "kv"
        }
      ]
    },
    "geohash_precision": 6,
    "workers": 4,
    "batch_size": 100
  }
}
Configuration Options
Option Type Default Description
ports object required Port configuration
geohash_precision int 6 Geohash precision (1-12)
workers int 4 Number of worker goroutines
batch_size int 100 Batch size for index updates

Ports

Inputs
Name Type Subject Description
entity_watch kv-watch ENTITY_STATES Watch entity state changes
Outputs
Name Type Subject Description
spatial_index kv SPATIAL_INDEX Geospatial index

Geohash Precision Guide

Precision Cell Size Use Case
1 ~5,000 km Continental
2 ~1,250 km Large country
3 ~156 km State/province
4 ~39 km City
5 ~4.9 km Neighborhood
6 ~1.2 km Street (default)
7 ~153 m Block
8 ~38 m Building
9+ <10 m Precise location

Index Structure

The SPATIAL_INDEX uses geohash as key:

{
  "geohash": "9q8yy",
  "entities": [
    {
      "entity_id": "c360.logistics.warehouse.sensor.gps.gps-001",
      "lat": 37.7749,
      "lon": -122.4194,
      "precision": 6
    }
  ]
}

Location Extraction

The component extracts location from these predicates:

  • geo.location.latitude / geo.location.longitude
  • location.lat / location.lon
  • coordinates.latitude / coordinates.longitude

Spatial Queries

The gateway component uses this index for:

  • Radius search: Find entities within N km of a point
  • Bounding box: Find entities within lat/lon bounds
  • Geohash prefix: Find entities in geohash cell

Dependencies

Upstream
  • graph-ingest - produces ENTITY_STATES
Downstream
  • graph-gateway - queries spatial index

Metrics

Metric Type Description
graph_spatial_indexed_total counter Total entities indexed
graph_spatial_updates_total counter Total index updates
graph_spatial_errors_total counter Indexing errors

Health

The component reports healthy when:

  • KV watch subscription is active
  • SPATIAL_INDEX bucket is accessible
  • Index updates completing successfully

Documentation

Overview

Package graphindexspatial provides the graph-index-spatial component for spatial indexing.

Package graphindexspatial provides the graph-index-spatial component for spatial indexing.

Overview

The graph-index-spatial component watches the ENTITY_STATES KV bucket and maintains a geospatial index for entities with location data. This enables efficient spatial queries like "find entities within radius" or "find entities in bounding box".

Architecture

graph-index-spatial is an optional component that can be enabled for deployments requiring geospatial query capabilities.

                    ┌─────────────────────┐
ENTITY_STATES ─────►│                     │
   (KV watch)       │  graph-index-spatial├──► SPATIAL_INDEX (KV)
                    │                     │
                    └─────────────────────┘

Features

  • Geohash-based spatial indexing with configurable precision
  • Automatic extraction of location data from entity triples
  • Batch processing for efficient index updates
  • Support for point locations (lat/lon)

Configuration

The component is configured via JSON with the following structure:

{
  "ports": {
    "inputs": [
      {"name": "entity_watch", "subject": "ENTITY_STATES", "type": "kv-watch"}
    ],
    "outputs": [
      {"name": "spatial_index", "subject": "SPATIAL_INDEX", "type": "kv"}
    ]
  },
  "geohash_precision": 6,
  "workers": 4,
  "batch_size": 100
}

Geohash Precision

The geohash_precision setting controls the granularity of spatial indexing:

Precision 1: ~5,000 km (continental)
Precision 2: ~1,250 km (large country)
Precision 3: ~156 km (state/province)
Precision 4: ~39 km (city)
Precision 5: ~4.9 km (neighborhood)
Precision 6: ~1.2 km (street) - default
Precision 7: ~153 m (block)
Precision 8: ~38 m (building)
Precision 9-12: increasingly fine precision

Port Definitions

Inputs:

  • KV watch: ENTITY_STATES - watches for entity state changes

Outputs:

  • KV bucket: SPATIAL_INDEX - geohash-based spatial index

Usage

Register the component with the component registry:

import graphindexspatial "github.com/c360studio/semstreams/processor/graph-index-spatial"

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

Dependencies

Upstream:

  • graph-ingest: produces ENTITY_STATES that this component watches

Downstream:

  • graph-gateway: reads SPATIAL_INDEX for spatial queries

Package graphindexspatial query handlers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateGraphIndexSpatial

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

CreateGraphIndexSpatial is the factory function for creating graph-index-spatial components

func Register

func Register(registry *component.Registry) error

Register registers the graph-index-spatial factory with the component registry

Types

type Component

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

Component implements the graph-index-spatial processor

func (*Component) ConfigSchema

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

ConfigSchema returns the configuration schema

func (*Component) DataFlow

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

DataFlow returns current data flow metrics

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

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

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

type Config

type Config struct {
	Ports            *component.PortConfig `json:"ports" schema:"type:ports,description:Port configuration,category:basic"`
	GeohashPrecision int                   `json:"geohash_precision" schema:"type:int,description:Geohash precision (1-12),category:basic"`
	Workers          int                   `json:"workers" schema:"type:int,description:Number of worker goroutines,category:basic"`
	BatchSize        int                   `json:"batch_size" schema:"type:int,description:Event batch size,category:basic"`

	// Dependency startup configuration
	StartupAttempts int `` /* 130-byte string literal not displayed */
	StartupInterval int `` /* 134-byte string literal not displayed */
}

Config holds configuration for graph-index-spatial 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

type SpatialResult

type SpatialResult struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

SpatialResult represents an entity found in spatial search

Jump to

Keyboard shortcuts

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