-
Notifications
You must be signed in to change notification settings - Fork 1
geo_integration
Stand: 5. Dezember 2025
Version: 1.0.0
Kategorie: Geo
This document describes the geo MVP implementation that connects blob ingestion with spatial indexing and provides CPU-based exact geometry checks using Boost.Geometry.
The geo MVP consists of four main components:
-
Geo Index Hooks (
src/api/geo_index_hooks.cpp)- Integrates spatial index updates into entity lifecycle (PUT/DELETE)
- Parses geometry from entity blobs (GeoJSON or EWKB)
- Computes sidecar metadata (MBR, centroid, z-range)
- Updates spatial index via
SpatialIndexManager
-
Boost.Geometry CPU Backend (
src/geo/boost_cpu_exact_backend.cpp)- Provides actual exact geometry intersection checks
- Uses Boost.Geometry library for computational geometry
- Supports Point, LineString, and Polygon types
- Falls back to MBR checks for unsupported types
-
Exact Geometry Check in searchIntersects (
src/index/spatial_index.cpp)- Phase 1: MBR intersection (fast candidate filter)
- Phase 2: Load entity blobs and perform exact geometry check
- Filters out MBR false positives using Boost.Geometry
- Falls back to MBR-only if exact backend not available
-
Per-PK Storage Optimization (
src/index/spatial_index.cpp)- Stores sidecar per primary key in addition to bucket JSON
- Allows updating/deleting individual entities without rewriting entire Morton bucket
- Backward compatible with existing bucket-based storage
The geo hooks are integrated into the HTTP API entity handlers:
-
PUT /entities/:key - After successful entity write, calls
GeoIndexHooks::onEntityPut() -
DELETE /entities/:key - Before entity deletion, calls
GeoIndexHooks::onEntityDelete()
Entity blobs can contain geometry in several formats:
- GeoJSON (recommended):
{
"id": "entity1",
"geometry": {
"type": "Point",
"coordinates": [10.5, 50.5]
}
}- Hex-encoded EWKB:
{
"id": "entity1",
"geometry": "0101000000000000000000244000000000008049400"
}- Binary EWKB array:
{
"id": "entity1",
"geom_blob": [1, 1, 0, 0, 0, ...]
}IMPORTANT: In the MVP implementation, spatial index updates are not atomic with entity writes.
- Entity write and spatial index update happen in separate operations
- Parse/index errors do not abort the entity write (logged only)
- Future versions should integrate into RocksDB transactions or use saga pattern
The hooks are designed to be robust:
- Geometry parse errors → logged as warnings, entity write succeeds
- Spatial index failures → logged as warnings, entity write succeeds
- Missing geometry field → silently skipped (not an error)
- Invalid JSON → logged, entity write succeeds
This ensures that geo functionality is additive and doesn't break existing functionality.
The SpatialIndexManager::searchIntersects() method now performs a two-phase query:
Phase 1: MBR Filtering (Fast)
- Uses Morton-encoded spatial index to find candidates
- Checks if entity MBR intersects query MBR
- Reduces search space by ~95% for typical queries
Phase 2: Exact Geometry Check (Accurate)
- Loads entity blob from RocksDB
- Parses geometry using EWKBParser
- Creates query geometry from bbox
- Uses Boost.Geometry to perform exact
intersects()check - Filters out false positives from MBR-only filtering
User Query (bbox)
↓
Morton Range Calculation
↓
RocksDB Range Scan (get candidates by MBR)
↓
FOR EACH candidate:
├─ MBR.intersects(query_bbox)? → NO: skip
├─ Load entity blob from RocksDB
├─ Parse geometry (GeoJSON → GeometryInfo)
├─ Boost.Geometry exactIntersects(entity_geom, query_geom)? → NO: skip
└─ YES: add to results
↓
Return filtered results (exact matches only)
- Without exact backend: Returns MBR candidates (may include false positives)
- With exact backend: Returns only true geometric intersections
- Overhead: ~1-5ms per candidate for exact check (depends on geometry complexity)
- Typical case: 10-100 candidates → 10-500ms additional latency for exact checks
- Benefit: Eliminates false positives, especially important for complex polygons
To enable the Boost.Geometry exact backend, ensure Boost is available:
# vcpkg.json already includes boost dependencies
# The backend is conditionally compiled with THEMIS_GEO_BOOST_BACKEND flagBuild with geo support:
cmake -DTHEMIS_GEO=ON -DTHEMIS_GEO_BOOST_BACKEND=ON ..If Boost.Geometry is not available:
- The build will still succeed
-
getBoostCpuBackend()returnsnullptr - Queries fall back to MBR-only filtering (no exact checks)
curl -X POST http://localhost:8080/api/spatial/index \
-H "Content-Type: application/json" \
-d '{
"table": "places",
"geometry_column": "geometry",
"config": {
"total_bounds": {"minx": -180, "miny": -90, "maxx": 180, "maxy": 90}
}
}'curl -X PUT http://localhost:8080/api/entities/places:berlin \
-H "Content-Type: application/json" \
-d '{
"key": "places:berlin",
"blob": "{\"id\":\"berlin\",\"name\":\"Berlin\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[13.4,52.5]}}"
}'The spatial index is automatically updated.
curl -X POST http://localhost:8080/api/spatial/search \
-H "Content-Type: application/json" \
-d '{
"table": "places",
"bbox": {"minx": 13.0, "miny": 52.0, "maxx": 14.0, "maxy": 53.0}
}'Returns entities whose MBR intersects the query bbox. With Boost backend enabled, exact geometry checks are performed.
Run the integration tests:
cd build
ctest -R test_geo_index_integration -VTests verify:
- Entity PUT triggers spatial index insert
- searchIntersects returns correct results
- Entity DELETE removes from index
- Error handling (missing geometry, invalid JSON)
- Null spatial manager handling
-
Transactional Integration
- Integrate hooks into RocksDB WriteBatch
- Or use saga pattern for multi-step transactions
- Ensure atomicity between entity write and index update
-
Exact Geometry in Query Engine
- Wire Boost backend into
SpatialIndexManager::searchIntersects() - Load entity blobs, parse geometries, call exact checks
- Filter out MBR false positives
- Wire Boost backend into
-
Additional Backends
- SIMD-optimized CPU kernels for batch operations
- GPU compute shaders for large-scale queries
- GEOS prepared geometries plugin
-
Storage Optimization
- Migrate fully to per-PK keys
- Remove bucket JSON format (breaking change)
- Compact binary sidecar format (not JSON)
- Geometry parsing uses exception handling to prevent crashes
- No user input is directly executed (only parsed as JSON/EWKB)
- Spatial index updates are logged for audit trails
- No SQL injection risk (key-value storage only)
- MBR computation: O(n) where n = number of coordinates
- Morton encoding: O(1)
- Bucket read/write: O(k) where k = entities per bucket
- Per-PK write: O(1) additional overhead per insert/delete
- Exact checks: Depends on geometry complexity (typically fast for simple polygons)
- Geo Execution Plan:
docs/geo_execution_plan_over_blob.md - Feature Tiering:
docs/geo_feature_tiering.md - EWKB Spec: PostGIS Extended Well-Known Binary format
- Boost.Geometry: https://www.boost.org/doc/libs/release/libs/geometry/
- Architecture-ACCESS-MODEL-IMPLEMENTATION-SUMMARY
- Architecture-ADR-003-pg-dump-sql-parser
- Architecture-BASEENTITY-PRINCIPLE
- Architecture-CACHE-STORAGE-INTEGRATION
- Architecture-CMAKE-ARCHITECTURE
- Architecture-CMAKE-FLAGS-REFERENCE
- Architecture-CMAKE-MODULAR-ARCHITECTURE
- Architecture-CONCERNS-ARCHITECTURE-DIAGRAM
- Architecture-CONCERNS-IMPLEMENTATION-SUMMARY
- Architecture-CONTENT-MODEL
- Architecture-COPILOT-THEMISDB-GRAPH-RAG-BACKEND-ARCHITECTURE
- Architecture-CRYPTO-AND-KEYS
- Architecture-FEATURE-FLAGS-REFERENCE
- Architecture-GPU-ARCHITECTURE-REVIEW-TEMPLATE
- Architecture-HTTP-SHUTDOWN-HARDENING
- Architecture-MIGRATION-GUIDE-CONCERNS
- Architecture-MIGRATION-GUIDE-v13-v14
- Architecture-MODULARIZATION-GUIDE
- Architecture-MODULAR-ARCHITECTURE-ROADMAP
- Architecture-MODULE-ARCHITECTURE-INDEX
- Architecture-P1D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D08-MAMBA-GOVERNANCE-CONTRACT
- Architecture-P1-P2-IMPLEMENTATION-COMPLETION-INDEX
- Architecture-PHASE0-COMPLETION-ASSESSMENT
- Architecture-PHASE3-QUERYENGINE-DI-ARCHITECTURE
- Architecture-PHASE4-INDEX-MANAGER-DI
- Architecture-POSTGRESQL-WIRE-PROTOCOL
- Architecture-QUERYENGINE-IMPLEMENTATION-GUIDE
- Architecture-QUERY-SCHEDULING
- Architecture-RAFT-CONSENSUS-DESIGN
- Architecture-README
- Architecture-README-SSM-HYBRID-IMPLEMENTATION
- Architecture-REFACTORING-SUMMARY
- Architecture-RESOURCE-POOLING
- Architecture-SOURCE-DIRECTORY-GUIDE
- Architecture-THEMIS-CORE-GUIDE
- Architecture-UNIFIED-ACCESS-MODEL
- Architecture-WAL-GRPC-MTLS-CONFIGURATION
- Architecture-WIRE-PROTOCOL-RETRY
- Architecture-boltzmann-observability-draft
- Architecture-experimental-logarithmic-vector-storage
- Architecture-llm-wiki-mvp-adr
- Architecture-rewrite-engine-architecture
- Architecture-rope-api-architecture
- Architecture-ssm-gguf-mamba-status
- Architecture-ssm-hybrid-analysis
- Architecture-ssm-hybrid-rollout-plan
- Architecture-ssm-plugin-interface-design-review
- Architecture-transaction-coordinators
- Architecture-wiki-secondary-index
- Architecture-wire-protocol
- Governance-DISABLED-STUB-POLICY
- Governance-DOCS-PR-POLICY
- Governance-GA-PROMOTION-SIGN-OFF
- Governance-GITHUB-MILESTONES-SETUP
- Governance-MATURITY-CLAIM-VERIFICATION-CHECKLIST
- Governance-MATURITY-EVIDENCE-REGISTRY
- Governance-MERGE-GATE-BOT-CONFIG
- Governance-MERGE-GATE-STATUS-LIVE
- Governance-PHASE3-ENFORCEMENT-RUNBOOK
- Governance-PHASE-1-CLOSURE-REPORT
- Governance-PHASE-CLOSURE-POLICY
- Governance-PHASE-DEPENDENCY-GRAPH
- Governance-PLUGIN-SUBMODULE-ROLLBACK
- Governance-PRODUCTION-READY-2026-DELIVERY-PLAN
- Governance-PR-VERSION-TARGETING
- Governance-PR-VERSION-TARGETING-BACKFILL
- Governance-QUERY-MODULE-STATUS
- Governance-README
- Governance-RELEASE-PROMOTION-GATE-POLICY
- Governance-RELEASE-VALIDATION-CHECKLIST
- Governance-SECURITY-MODULE-5671-EVIDENCE-SUMMARY
- Governance-SHARDING-P6-RESIDUAL-RISK-ACCEPTANCE
- Governance-SOURCECODE-COMPLIANCE-GOVERNANCE
- Governance-UPDATES-DEVELOPMENT-STATUS-SIGN-OFF
- Governance-WAVE-C-IMPLEMENTATION-COMPLETE
- Module-acceleration-Roadmap
- Module-access-model-Roadmap
- Module-ai-Roadmap
- Module-analytics-Roadmap
- Module-api-Roadmap
- Module-aql-Roadmap
- Module-auth-Roadmap
- Module-base-Roadmap
- Module-cache-Roadmap
- Module-cdc-Roadmap
- Module-chaos-Roadmap
- Module-chimera-Roadmap
- Module-config-Roadmap
- Module-content-Roadmap
- Module-core-Roadmap
- Module-distributed-knowledge-Roadmap
- Module-distributed-tensor-Roadmap
- Module-document-Roadmap
- Module-ethics-ai-Roadmap
- Module-evaluation-Roadmap
- Module-execution-Roadmap
- Module-exporters-Roadmap
- Module-failover-Roadmap
- Module-geo-Roadmap
- Module-governance-Roadmap
- Module-gpu-Roadmap
- Module-graph-Roadmap
- Module-image-analysis-Roadmap
- Module-importers-Roadmap
- Module-index-Roadmap
- Module-ingestion-Roadmap
- Module-llama-cpp-Roadmap
- Module-llm-Roadmap
- Module-llm-streaming-Roadmap
- Module-llm-wiki-Roadmap
- Module-maintenance-Roadmap
- Module-metadata-Roadmap
- Module-network-Roadmap
- Module-observability-Roadmap
- Module-onnx-clip-Roadmap
- Module-performance-Roadmap
- Module-plugins-Roadmap
- Module-process-Roadmap
- Module-projects-Roadmap
- Module-prompt-engineering-Roadmap
- Module-query-Roadmap
- Module-rag-Roadmap
- Module-replication-Roadmap
- Module-retrieval-Roadmap
- Module-rpc-grpc-Roadmap
- Module-scheduler-Roadmap
- Module-scraper-Roadmap
- Module-search-Roadmap
- Module-security-Roadmap
- Module-server-Roadmap
- Module-sharding-Roadmap
- Module-stable-diffusion-Roadmap
- Module-storage-Roadmap
- Module-temporal-Roadmap
- Module-tensor-Roadmap
- Module-themis-Roadmap
- Module-timeseries-Roadmap
- Module-toolbox-Roadmap
- Module-training-Roadmap
- Module-transaction-Roadmap
- Module-updates-Roadmap
- Module-user-storage-encrypted-Roadmap
- Module-utils-Roadmap
- Module-vector-search-Roadmap
- Module-voice-Roadmap
- Module-whisper-Roadmap