ClusterModel.swift
ClusterModel Documentation
Overview
ClusterModel.swift
defines the Cluster
struct, which represents a grouping of related entries based on their similarity threshold. Clusters help organize and categorize entries using their vector embeddings and optional category labels.
Structure Definition
Properties
id
UUID
Unique identifier for the cluster. Automatically generated if not provided.
entries
[Entry]
Array of Entry objects that belong to this cluster.
threshold
Float
Similarity threshold value used to determine cluster membership.
category
String?
Optional label or category name for the cluster.
Protocol Conformance
Codable
Enables JSON encoding and decoding
Used for persistence and API communication
Automatic synthesis as all properties are Codable-conforming types
Identifiable
Provides unique identification for SwiftUI integration
Uses the
id
property as the unique identifierEnables direct use in SwiftUI Lists and ForEach
Hashable
Custom implementation focusing on
id
propertyEnables use in Sets and as Dictionary keys
Implementation:
Initialization
Parameters
id
: Optional. Defaults to new UUID if not providedentries
: Optional. Defaults to empty arraythreshold
: Required. Similarity threshold for cluster membershipcategory
: Optional. Defaults to nil
Usage Examples
Creating an Empty Cluster
Creating a Cluster with Entries
Using in Collections
Best Practices
Choose appropriate threshold values based on your similarity requirements
Consider grouping related entries before creating a cluster
Use meaningful category names when applicable
Maintain consistency in threshold values across related clusters
Consider memory implications when storing large numbers of entries in a cluster
Common Operations
Adding Entries
Checking Entry Similarity
Related Components
EntryModel.swift
: Provides the Entry type used in clustersStorage Provider: Handles persistence of Cluster objects
Clustering Algorithm: Uses threshold to determine cluster membership
SwiftUI Views: Displays clusters and their entries
Last updated