Skip to content

Document cross-shard graph/hybrid search with hub-shard coordination, link discovery, topology metrics, Grafana dashboard, and production operations - #85

Merged
makr-code merged 10 commits into
mainfrom
copilot/implement-hob-shard-nodes
Dec 13, 2025
Merged

makr-code merged 10 commits into
mainfrom
copilot/implement-hob-shard-nodes

Conversation

Copilot AI commented Dec 13, 2025 •

Copy link
Copy Markdown
Contributor

Problem: With complex sharding and redundancy in place, the system lacked documentation on how Graph and Hybrid searches execute across distributed shards, particularly URN-based cross-network searches, hub-shard node implementation, link discovery during ingestion, graph topology analysis, operational monitoring, and production deployment considerations.

Changes

Cross-Shard Search Architecture (docs/sharding/sharding_redundancy.md +2859 lines)

URN-Based Query Distribution

  • Location-transparent queries via URN patterns (urn:themis:graph:docs:chunks:*)
  • Shard discovery through URN resolver pattern matching
  • Scatter-gather execution with intelligent shard filtering

Hub-Shard Coordination Pattern

  • Hub nodes: query planning, URN resolution, result aggregation, cross-shard edge tracking
  • Worker nodes: local graph traversal, local hybrid search execution
  • Cross-shard edge index for tracking inter-shard relationships

Hybrid Search Fusion

  • Text + Vector + Graph result merging across shards
  • RRF (Reciprocal Rank Fusion) and weighted score algorithms
  • Deduplication and re-ranking of distributed results

Remote Node Referencing

  • Detailed explanation of how graph entities store references to remote nodes on other shards
  • URN-based edge reference format with target_urn, local, and target_shard fields
  • Graph entity storage schema with RocksDB
  • Hub-shard edge index structure for cross-shard edge tracking
  • Resolution mechanism for fetching remote nodes during graph traversal

Link Discovery During Ingestion

  • Client-declared links: Explicit link specification at HTTP endpoint ingestion
  • Asynchronous link discovery service (low-priority background task):
    • URN pattern scanning in document text
    • NLP-based entity extraction for authority/organization references
    • Metadata-based URN mapping
  • Shard-to-shard link exchange via Hub-Shard notifications
  • Hybrid approach combining immediate client links with automatic discovery
  • Configuration examples for link discovery strategies and extraction methods

Graph Topology Metrics

  • Real-time tracking of InDegree (incoming edges) and OutDegree (outgoing edges) per entity
  • Hub-node identification: highly-referenced entities (authorities, policies, central documents)
  • Leaf-node detection: orphaned or low-referenced documents
  • Prometheus metrics for degree distribution and top-referenced entities
  • API endpoints for querying graph topology (/api/v1/graph/topology/top-referenced, /api/v1/graph/topology/low-referenced)
  • Use cases: importance ranking, orphaned document detection, anomaly detection
  • TimeSeries persistence for historical topology tracking

Production Considerations (new)

  • Failure Scenarios & Recovery: Hub-shard HA with active-passive failover, worker-shard replica failover, network partition handling with quorum-based decisions
  • Consistency Guarantees: Read consistency levels (EVENTUAL, MONOTONIC_READ, STRONG), write-after-read consistency with session tracking
  • Security & Access Control: PKI-based mutual TLS, URN-based access control, cross-shard query authorization
  • Capacity Planning: Shard sizing guidelines, capacity triggers, rebalancing process after shard addition
  • Performance Tuning: URN cache optimization formulas, query timeout tuning per query type
  • Troubleshooting Guide: Common problems (high latency, cache misses, edge tracking), diagnosis commands, solutions, debug mode configuration

Grafana Dashboard (deploy/kubernetes/monitoring/grafana-dashboards/)

Production-Ready Monitoring Dashboard - themisdb-shard-network-dashboard.json

  • Import-ready Grafana dashboard (9.0+ compatible) for comprehensive shard network monitoring
  • 25+ panels organized into 5 sections:
    1. Hub-Shard Network Overview: Active shards, cross-shard edges, URN cache hit rate, query fanout
    2. Cross-Shard Query Performance: Query rates, latency (P95/P99), fanout distribution
    3. Link Discovery: Discovery rates by method, progress tracking, confidence distribution
    4. Graph Topology Analysis: Top-10 hub nodes, InDegree distribution, orphaned documents, degree trends
    5. Shard Communication: Routing patterns, network traffic, error rates

Dashboard Documentation - README.md

  • Three import methods: Grafana UI, kubectl, Grafana Operator
  • Required Prometheus metrics reference
  • Configuration examples and alert rules
  • Troubleshooting guide
  • Custom query examples for extensions

Implementation Example

class HubShard {
    nlohmann::json executeGraphSearch(
        std::string_view urn_pattern,  // "urn:themis:graph:docs:chunks:*"
        uint32_t hops,
        const std::vector<std::string>& edge_types
    ) {
        // 1. Resolve URN pattern to target shards
        auto target_shards = getRelevantShards(urn_pattern);
        
        // 2. Scatter: parallel execution on workers
        std::vector<std::future<json>> futures;
        for (const auto& shard : target_shards) {
            futures.push_back(std::async([this, shard, urn_pattern, hops, edge_types]() {
                return executor_->executeGraphSearch(shard, urn_pattern, hops, edge_types);
            }));
        }
        
        // 3. Gather and merge results
        auto merged = mergeGraphResults(collect(futures));
        
        // 4. Resolve cross-shard edges
        followCrossShardEdges(merged, hops, edge_types);
        
        return merged;
    }
};

Graph Entity Structure with Remote References

{
  "urn": "urn:themis:graph:docs:chunks:abc-123",
  "edges": [
    {
      "type": "next",
      "target_urn": "urn:themis:graph:docs:chunks:def-789",
      "local": false,
      "target_shard": "worker_002"
    }
  ]
}

Link Discovery at Ingestion

POST /api/v1/data/ingest
{
  "document": {
    "urn": "urn:themis:graph:docs:document:doc-123",
    "data": {"title": "Antrag für Behörde XY", "content": "..."}
  },
  "links": [
    {
      "type": "belongs_to_authority",
      "target_urn": "urn:themis:hierarchy:government:institutional:de_bmf:uuid-xyz"
    }
  ]
}

Configuration & Deployment

Hub-shard topology with YAML-based configuration:

  • Hub capabilities: query coordination, URN caching, cross-shard join
  • Hub HA: Active-passive failover with etcd-backed shared state
  • Worker partitioning by hash range with independent data storage
  • Kubernetes deployment examples with StatefulSet for workers
  • Link discovery service deployment as low-priority background task

Monitoring: Prometheus metrics for:

  • Query fanout, URN cache hit rate, cross-shard edge tracking
  • Link discovery rates by extraction method (URN pattern, NLP, metadata)
  • Graph topology: InDegree/OutDegree distributions, hub-nodes, leaf-nodes

Grafana Dashboard Import:

# Via Grafana UI: Dashboards → Import → Upload JSON
# Via kubectl:
kubectl apply -f deploy/kubernetes/monitoring/grafana-dashboards/themisdb-shard-network-dashboard.json
# Via ConfigMap:
kubectl create configmap themisdb-shard-network-dashboard \
  --from-file=deploy/kubernetes/monitoring/grafana-dashboards/themisdb-shard-network-dashboard.json \
  -n monitoring

Documentation Updates

  • docs/sharding/README.md: Referenced cross-shard search capabilities
  • README.md: Added Cross-Shard Search section with URN-based queries and hub-shard architecture
  • docs/sharding/sharding_redundancy.md: Integrated Grafana dashboard reference and production considerations

Technical Notes

  • Lambda captures fixed to avoid race conditions in async loops (capture by value)
  • Score aggregation uses max() across shards (assumes normalized scores)
  • RRF calculation optimized with pre-computed reciprocal
  • Edge types documented: parent (hierarchy), next/prev (sequence), geo (spatial proximity)
  • Remote node references use full URNs for global uniqueness and location transparency
  • Link discovery supports both immediate (client-declared) and asynchronous (background discovery) approaches
  • Graph topology metrics enable identification of hub-nodes and orphaned documents
  • Grafana dashboard provides comprehensive operational visibility into shard network health and performance
  • Production considerations cover failure recovery, consistency guarantees, security, capacity planning, performance tuning, and troubleshooting
  • Hub-shard HA with RTO < 30 seconds, quorum-based decisions for split-brain prevention
  • Consistency levels: EVENTUAL, MONOTONIC_READ, STRONG with session-based read-your-writes guarantees

Status: Design complete, implementation follows in Phase 2
Dependencies: Sharding ✅, URN System ✅, Graph API ✅, Hybrid Search ✅

Original prompt

On sharding_redundancy.md, Wir haben nun mit dem sharding eine komplexe DB Spiegelung usw. Struktur geschaffen. Wie stellen wir sicher das Graph-Suchen / Hybrid über alle relevanten Shards durchgeführt werden. Wir haben ja über URN basierte netzübergreifende Suchen gesprochen. Wie sind diese hob-shard Knoten implementiert?


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Implement hob-shard nodes for graph searches Document cross-shard graph/hybrid search with hub-shard coordination Dec 13, 2025
Copilot AI requested a review from makr-code December 13, 2025 21:06
@makr-code

Copy link
Copy Markdown
Owner

@copilot Wie werden diese entfernten nodes in entfernten shards im graph-entity referenziert

Copilot AI commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Wie werden diese entfernten nodes in entfernten shards im graph-entity referenziert

Entfernte Nodes in anderen Shards werden durch URN-basierte Edge-Referenzen referenziert. Jede Graph-Entity speichert ihre Edges mit vollständigen URNs der Zielnodes:

{
  "urn": "urn:themis:graph:docs:chunks:abc-123",
  "edges": [
    {
      "type": "next",
      "target_urn": "urn:themis:graph:docs:chunks:def-789",
      "local": false,
      "target_shard": "worker_002"
    }
  ]
}

Die target_urn enthält die vollständige URN des entfernten Nodes. Der Hub-Shard löst diese URN auf, bestimmt den Ziel-Shard, und holt den Node via Remote-Executor.

Ich habe einen neuen Abschnitt "Referenzierung entfernter Nodes in Graph-Entities" mit detaillierten Code-Beispielen hinzugefügt, der das Speicherformat, die Auflösungsmechanismen und den Hub-Shard Edge-Index erklärt.

Commit: afc3af4

@makr-code

Copy link
Copy Markdown
Owner

@copilot Wie erlangt jetzt die themisdb die Erkenntnis bei der Ingestion ob ein Dokument in Behörde xy referenziert werden muss oder nicht? Die Daten müssten ja bei Eingang am http-Endpoint vorliegen oder können die shards untereinander Informationen über relevante "linked" URN austauschen? Als niedrig priorisierte Daueraufgabe.

Copilot AI commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Wie erlangt jetzt die themisdb die Erkenntnis bei der Ingestion ob ein Dokument in Behörde xy referenziert werden muss oder nicht? Die Daten müssten ja bei Eingang am http-Endpoint vorliege...

ThemisDB unterstützt zwei Ansätze für Link-Discovery bei der Ingestion:

1. Client-deklarierte Links (sofort verfügbar):
Der Client übergibt Links direkt am HTTP-Endpoint:

POST /api/v1/data/ingest
{
  "document": {...},
  "links": [
    {
      "type": "belongs_to_authority",
      "target_urn": "urn:themis:hierarchy:government:institutional:de_bmf:uuid-xyz"
    }
  ]
}

2. Asynchrone Link-Discovery (Hintergrundaufgabe, niedrige Priorität):
Ein Link-Discovery-Service scannt Dokumente und extrahiert automatisch Links durch:

  • URN-Pattern-Scanning im Text (Regex)
  • NLP Entity-Extraktion (Behörden, Organisationen)
  • Metadata-Mapping (z.B. authority_id → URN-Lookup)

Shards tauschen entdeckte Links über den Hub-Shard aus, der einen zentralen Cross-Shard Edge-Index verwaltet. Validierte Links werden automatisch registriert.

Ich habe einen neuen Abschnitt "Link-Discovery bei der Ingestion" hinzugefügt mit vollständigen Code-Beispielen, Konfigurations-Schema, und Deployment-Optionen für beide Ansätze.

Commit: 0da1a0d

Copilot AI changed the title Document cross-shard graph/hybrid search with hub-shard coordination Document cross-shard graph/hybrid search with hub-shard coordination, link discovery, and topology metrics Dec 13, 2025
@makr-code

Copy link
Copy Markdown
Owner

@copilot wir sollten dafür ein entsprechendes grafana dashboard für shard-netzwerke vorbereiten (import grafana).

Copilot AI commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

@copilot wir sollten dafür ein entsprechendes grafana dashboard für shard-netzwerke vorbereiten (import grafana).

Ich habe ein umfassendes Grafana-Dashboard für Shard-Netzwerke erstellt:

Dashboard-Datei: deploy/kubernetes/monitoring/grafana-dashboards/themisdb-shard-network-dashboard.json

Das Dashboard enthält 5 Hauptbereiche:

  1. Hub-Shard Network Overview - Aktive Shards, Cross-Shard Edges, URN Cache Hit Rate
  2. Cross-Shard Query Performance - Query-Raten, Latenz (P95/P99), Fanout-Verteilung
  3. Link Discovery - Discovery-Raten nach Methode (URN Pattern, NLP, Metadata), Konfidenz-Distribution
  4. Graph Topology Analysis - Top-10 Hub-Nodes, InDegree-Distribution, Orphaned Documents
  5. Shard Communication - Routing-Types, Netzwerk-Traffic, Error-Raten

Import-Methoden:

  • Grafana UI: Dashboards → Import → Upload JSON
  • kubectl: kubectl apply -f deploy/kubernetes/monitoring/grafana-dashboards/...
  • ConfigMap für automatisches Laden

Eine vollständige README mit Installations-Anleitung, erforderlichen Metriken, Alert-Beispielen und Troubleshooting ist ebenfalls enthalten: deploy/kubernetes/monitoring/grafana-dashboards/README.md

Commit: c350074

Copilot AI changed the title Document cross-shard graph/hybrid search with hub-shard coordination, link discovery, and topology metrics Document cross-shard graph/hybrid search with hub-shard coordination, link discovery, topology metrics, and Grafana dashboard Dec 13, 2025
@makr-code

Copy link
Copy Markdown
Owner

@copilot haben wir etwas vergessen zu berücksichten?

Copilot AI commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

@copilot haben wir etwas vergessen zu berücksichten?

Gute Frage! Bei der Review habe ich einige wichtige Aspekte identifiziert, die noch ergänzt werden sollten:

Fehlt noch:

  1. Failure Scenarios & Recovery - Was passiert bei Hub-Shard-Ausfall, Worker-Shard-Ausfall, Netzwerk-Partitionen
  2. Consistency Guarantees - Eventual Consistency bei Cross-Shard Queries, Read-after-Write Guarantees
  3. Security & Access Control - PKI-basierte Shard-Authentifizierung (bereits in anderen Docs, sollte hier referenziert werden)
  4. Capacity Planning - Wann neue Shards hinzufügen, Shard-Rebalancing-Trigger
  5. Performance Tuning - Best Practices für URN Cache Size, Query Timeout-Konfiguration
  6. Troubleshooting Guide - Häufige Probleme und Lösungen bei Cross-Shard Operations

Ich füge jetzt einen Abschnitt "Production Considerations" hinzu, der diese Themen abdeckt.

…y, capacity planning, and troubleshooting

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title Document cross-shard graph/hybrid search with hub-shard coordination, link discovery, topology metrics, and Grafana dashboard Document cross-shard graph/hybrid search with hub-shard coordination, link discovery, topology metrics, Grafana dashboard, and production operations Dec 13, 2025
@makr-code

Copy link
Copy Markdown
Owner

@copilot okay

@makr-code
makr-code marked this pull request as ready for review December 13, 2025 21:50
@makr-code
makr-code merged commit 8615a5f into main Dec 13, 2025
@makr-code makr-code added this to the v1.0.2 milestone Mar 11, 2026
Copilot AI added a commit that referenced this pull request Mar 16, 2026
Copilot AI added a commit that referenced this pull request Mar 16, 2026
makr-code added a commit that referenced this pull request Mar 16, 2026
…celerated-query-execution

fix(tests): complete AC-4 filter operator coverage and align AC-5 comments (HardwareAccelerator audit #85)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants