SPB Git

Repository Public

ConstellationModels.swift 2.8 KB 77 lines swift

1// SP Notes Core2// File: Sources/SPNotesAPI/ConstellationModels.swift3// Description: The Thought Constellation of the knowledge workstream: the server's 2-D projection of the page embeddings4//              (`GET /api/graph/constellation`, feature `constellation` in `/api/meta`). The route is not part of every5//              3.0 server yet: gate on `ServerFeature.constellation`.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import Foundation1011/// The server's answer (`src/lib/graph/constellation.ts` of the web knowledge workstream). Coordinates are in `-1 ... 1`.12public struct ConstellationProjection: Codable, Sendable, Equatable {13    public struct Stats: Codable, Sendable, Equatable {14        public var pages: Int15        public var embedded: Int16        public var shown: Int17        public var links: Int18        public var truncated: Bool19    }2021    public struct Point: Codable, Sendable, Equatable, Identifiable {22        public var id: String23        public var title: String?24        public var icon: String?25        public var type: String?26        public var section: String?27        public var x: Double28        public var y: Double29        public var cluster: Int30        public var projectId: String?31        public var tags: [String]?32        public var updatedAt: Date?33        public var words: Int?34        public var degree: Int?35    }3637    public struct Cluster: Codable, Sendable, Equatable, Identifiable {38        public var id: Int39        public var x: Double40        public var y: Double41        public var r: Double42        public var size: Int43        public var label: String?44        public var topTags: [String]?45    }4647    public struct Link: Codable, Sendable, Equatable, Identifiable {48        public var id: String49        public var source: String50        public var target: String51        public var kind: String?52        public var relType: String?53        public var origin: String?54    }5556    public var model: String?57    public var computedAt: Date?58    public var cached: Bool?59    /// Share of the variance carried by each axis.60    public var explained: [Double]?61    public var stats: Stats62    public var points: [Point]63    public var clusters: [Cluster]64    public var links: [Link]65}6667/// What the screen draws, whatever the origin.6869extension NotesAPI {70    /// `GET /api/graph/constellation[?refresh=1]` — deterministic projection (PCA) of the stored embeddings; no model is71    /// called. Only on a server whose `/api/meta` lists `ServerFeature.constellation` (elsewhere the route is missing:72    /// `APIError.isRouteMissing`).73    public func graphConstellation(refresh: Bool = false) async throws -> ConstellationProjection {74        try await client.decode(ConstellationProjection.self, .get("/api/graph/constellation", query: refresh ? [URLQueryItem(name: "refresh", value: "1")] : []))75    }76}77
Files main
Menu

Theme