@@ -21,11 +21,17 @@ type vectorLayerExecution struct {
|
||||
AgentID string
|
||||
ComputeMS int64
|
||||
FallbackReason string
|
||||
LayoutMode string
|
||||
LayoutDue bool
|
||||
}
|
||||
|
||||
func (e *Engine) vectorLayerConfig() graph.VectorSemanticLayerConfig {
|
||||
workers := 1
|
||||
if settings := e.RuntimeSettings(); settings.SpeedMode {
|
||||
workers = e.effectiveSpeedCPUWorkers(settings)
|
||||
}
|
||||
return graph.VectorSemanticLayerConfig{
|
||||
Neighbors: e.Cfg.VectorGraphNeighbors, CandidateLimit: e.Cfg.VectorGraphCandidates,
|
||||
Workers: workers, Neighbors: e.Cfg.VectorGraphNeighbors, CandidateLimit: e.Cfg.VectorGraphCandidates,
|
||||
HashBits: e.Cfg.ClusterHashBits, HashTables: e.Cfg.ClusterHashTables,
|
||||
MinSimilarity: e.Cfg.VectorGraphMinSimilarity, MinAffinity: e.Cfg.VectorGraphMinAffinity,
|
||||
Layout: e.Cfg.VectorGraphLayout, LayoutRelax: false, LayoutBlend: e.Cfg.VectorGraphLayoutBlend, LayoutMaxShift: e.Cfg.VectorGraphLayoutMaxShift,
|
||||
@@ -36,8 +42,12 @@ func (e *Engine) vectorLayerConfig() graph.VectorSemanticLayerConfig {
|
||||
}
|
||||
|
||||
func (e *Engine) vectorPrimaryConfig(layout bool) vectorgraph.Config {
|
||||
workers := 1
|
||||
if settings := e.RuntimeSettings(); settings.SpeedMode {
|
||||
workers = e.effectiveSpeedCPUWorkers(settings)
|
||||
}
|
||||
return vectorgraph.Config{
|
||||
Neighbors: e.Cfg.VectorGraphNeighbors, CandidateLimit: e.Cfg.VectorGraphCandidates,
|
||||
Workers: workers, Neighbors: e.Cfg.VectorGraphNeighbors, CandidateLimit: e.Cfg.VectorGraphCandidates,
|
||||
HashBits: e.Cfg.ClusterHashBits, HashTables: e.Cfg.ClusterHashTables, BandBits: 8,
|
||||
MinSimilarity: e.Cfg.VectorGraphMinSimilarity, MinAffinity: e.Cfg.VectorGraphMinAffinity,
|
||||
Layout: layout, Smoothing: .22,
|
||||
@@ -45,8 +55,12 @@ func (e *Engine) vectorPrimaryConfig(layout bool) vectorgraph.Config {
|
||||
}
|
||||
|
||||
func (e *Engine) vectorOrphanConfig() vectorgraph.Config {
|
||||
workers := 1
|
||||
if settings := e.RuntimeSettings(); settings.SpeedMode {
|
||||
workers = e.effectiveSpeedCPUWorkers(settings)
|
||||
}
|
||||
return vectorgraph.Config{
|
||||
Neighbors: e.Cfg.VectorGraphOrphanNeighbors, CandidateLimit: e.Cfg.VectorGraphOrphanCandidates,
|
||||
Workers: workers, Neighbors: e.Cfg.VectorGraphOrphanNeighbors, CandidateLimit: e.Cfg.VectorGraphOrphanCandidates,
|
||||
HashBits: e.Cfg.ClusterHashBits, HashTables: e.Cfg.ClusterHashTables, BandBits: 8,
|
||||
MinSimilarity: e.Cfg.VectorGraphOrphanMinSimilarity, MinAffinity: e.Cfg.VectorGraphOrphanMinAffinity,
|
||||
Layout: false,
|
||||
@@ -104,15 +118,24 @@ func (e *Engine) rebuildVectorSemanticLayer(ctx context.Context, runID string, f
|
||||
layoutDue := e.Cfg.VectorGraphLayout || (e.Cfg.VectorGraphRelaxLayout && (lastVectorLayout.IsZero() || time.Since(lastVectorLayout) >= e.Cfg.VectorGraphLayoutRelaxInterval))
|
||||
cfg.Layout = layoutDue
|
||||
cfg.LayoutRelax = !e.Cfg.VectorGraphLayout && layoutDue
|
||||
layoutMode := "off"
|
||||
if e.Cfg.VectorGraphLayout && layoutDue {
|
||||
layoutMode = "full"
|
||||
} else if cfg.LayoutRelax {
|
||||
layoutMode = "relax"
|
||||
}
|
||||
if !e.Cfg.VectorGraphAgentOffload || e.SourceInbox == nil {
|
||||
primary, orphan, focus := e.Graph.BuildVectorSemanticLayerLocal(cfg, filter)
|
||||
stats, mutations := e.Graph.ApplyVectorSemanticLayer(cfg, primary, orphan, focus)
|
||||
e.noteVectorLayoutApplied(layoutDue, stats.PositionUpdates)
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations}, nil
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, LayoutMode: layoutMode, LayoutDue: layoutDue}, nil
|
||||
}
|
||||
|
||||
hasAgent, availabilityErr := e.checkOnlineVectorComputeAgent(ctx)
|
||||
startupGrace := vectorAgentStartupGrace(!e.bootstrapIsComplete(), e.Cfg.VectorGraphAgentWait)
|
||||
if e.SpeedModeEnabled() && !e.Cfg.VectorGraphAgentRequired {
|
||||
startupGrace = 0
|
||||
}
|
||||
if availabilityErr == nil && !hasAgent && startupGrace > 0 {
|
||||
_ = e.requestControllerComputeCapacity(ctx, sourceagent.ComputeKindVectorGraph)
|
||||
e.Broker.Publish(model.Activity{Type: "vector.graph.agent.waiting", Source: "brain", Phase: "semantic-linking", Message: fmt.Sprintf("Initialer Vector-Graph wartet bis zu %s auf die Compute-Agent-Registrierung", startupGrace), Strength: .34, Metadata: map[string]any{"run_id": runID, "kind": sourceagent.ComputeKindVectorGraph, "startup_grace": startupGrace.String()}})
|
||||
@@ -127,12 +150,12 @@ func (e *Engine) rebuildVectorSemanticLayer(ctx context.Context, runID string, f
|
||||
reason = "compute_agent_check_failed: " + availabilityErr.Error()
|
||||
}
|
||||
if e.Cfg.VectorGraphAgentRequired {
|
||||
return vectorLayerExecution{FallbackReason: reason}, fmt.Errorf("vector graph agent offload required but unavailable: %s", reason)
|
||||
return vectorLayerExecution{FallbackReason: reason, LayoutMode: layoutMode, LayoutDue: layoutDue}, fmt.Errorf("vector graph agent offload required but unavailable: %s", reason)
|
||||
}
|
||||
primary, orphan, focus := e.Graph.BuildVectorSemanticLayerLocal(cfg, filter)
|
||||
stats, mutations := e.Graph.ApplyVectorSemanticLayer(cfg, primary, orphan, focus)
|
||||
e.noteVectorLayoutApplied(layoutDue, stats.PositionUpdates)
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, FallbackReason: reason}, nil
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, FallbackReason: reason, LayoutMode: layoutMode, LayoutDue: layoutDue}, nil
|
||||
}
|
||||
|
||||
entries := e.Graph.VectorSemanticEntries(filter)
|
||||
@@ -146,7 +169,7 @@ func (e *Engine) rebuildVectorSemanticLayer(ctx context.Context, runID string, f
|
||||
Entries: entries,
|
||||
}
|
||||
e.Broker.Publish(model.Activity{Type: "vector.graph.agent.queued", Source: "brain", Phase: "semantic-linking", Message: fmt.Sprintf("Vector-Graph-CPU-Job für Agent bereitgestellt · %d Embeddings", len(entries)), Strength: .46, Metadata: map[string]any{
|
||||
"run_id": runID, "kind": sourceagent.ComputeKindVectorGraph, "indexed": len(entries), "orphan_focus_candidates": len(baseOrphans), "graph_version": inputVersion,
|
||||
"run_id": runID, "kind": sourceagent.ComputeKindVectorGraph, "indexed": len(entries), "orphan_focus_candidates": len(baseOrphans), "graph_version": inputVersion, "cpu_workers": request.Header.Primary.Workers, "speed_mode": e.SpeedModeEnabled(),
|
||||
}})
|
||||
jobCtx, cancelJob := context.WithTimeout(ctx, e.Cfg.VectorGraphAgentWait)
|
||||
result, err := e.SourceInbox.SubmitVectorGraphJob(jobCtx, request)
|
||||
@@ -161,12 +184,12 @@ func (e *Engine) rebuildVectorSemanticLayer(ctx context.Context, runID string, f
|
||||
reason := err.Error()
|
||||
e.Broker.Publish(model.Activity{Type: "vector.graph.agent.fallback", Source: "brain", Phase: "semantic-linking", Message: "Agent-Vectorjob konnte nicht sicher übernommen werden; lokale CPU-Berechnung wird verwendet", Strength: .38, Metadata: map[string]any{"run_id": runID, "reason": reason, "graph_version": inputVersion}})
|
||||
if e.Cfg.VectorGraphAgentRequired {
|
||||
return vectorLayerExecution{FallbackReason: reason}, err
|
||||
return vectorLayerExecution{FallbackReason: reason, LayoutMode: layoutMode, LayoutDue: layoutDue}, err
|
||||
}
|
||||
primary, orphan, focus := e.Graph.BuildVectorSemanticLayerLocal(cfg, filter)
|
||||
stats, mutations := e.Graph.ApplyVectorSemanticLayer(cfg, primary, orphan, focus)
|
||||
e.noteVectorLayoutApplied(layoutDue, stats.PositionUpdates)
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, FallbackReason: reason}, nil
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, FallbackReason: reason, LayoutMode: layoutMode, LayoutDue: layoutDue}, nil
|
||||
}
|
||||
|
||||
focus := remainingOrphanFocus(baseOrphans, result.Primary.Links)
|
||||
@@ -174,9 +197,9 @@ func (e *Engine) rebuildVectorSemanticLayer(ctx context.Context, runID string, f
|
||||
e.noteVectorLayoutApplied(layoutDue, stats.PositionUpdates)
|
||||
e.Broker.Publish(model.Activity{Type: "vector.graph.agent.completed", Source: "agent", Phase: "semantic-linking", Message: fmt.Sprintf("Agent hat Vector-Graph-CPU-Job abgeschlossen · %d + %d Kanten", len(result.Primary.Links), len(result.Orphan.Links)), Strength: .68, Metadata: withRunMutations(map[string]any{
|
||||
"run_id": runID, "agent_id": result.AgentID, "compute_duration_ms": result.DurationMS, "indexed": len(entries),
|
||||
"primary_links": len(result.Primary.Links), "orphan_links": len(result.Orphan.Links), "orphan_focus": len(focus), "no_model_call": true,
|
||||
"primary_links": len(result.Primary.Links), "orphan_links": len(result.Orphan.Links), "orphan_focus": len(focus), "no_model_call": true, "cpu_workers": request.Header.Primary.Workers, "speed_mode": e.SpeedModeEnabled(),
|
||||
}, mutations)})
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, Offloaded: true, AgentID: result.AgentID, ComputeMS: result.DurationMS}, nil
|
||||
return vectorLayerExecution{Stats: stats, Mutations: mutations, Offloaded: true, AgentID: result.AgentID, ComputeMS: result.DurationMS, LayoutMode: layoutMode, LayoutDue: layoutDue}, nil
|
||||
}
|
||||
|
||||
func (e *Engine) noteVectorLayoutApplied(layoutDue bool, updates uint64) {
|
||||
|
||||
Reference in New Issue
Block a user