EntryModel.swift

EntryModel Documentation

Overview

EntryModel.swift defines the Entry struct, which represents a single text entry in the application with its associated metadata and vector embeddings. This model is used for storing and processing text content throughout the application.

Structure Definition

struct Entry: Codable, Identifiable {
    let id: UUID
    let content: String
    let timestamp: Date
    let embeddings: [Float]
}

Properties

Property
Type
Description

id

UUID

Unique identifier for the entry. Automatically generated if not provided.

content

String

The actual text content of the entry.

timestamp

Date

When the entry was created. Defaults to current time if not specified.

embeddings

[Float]

Vector representation of the text content, used for similarity matching.

Protocol Conformance

Codable

  • Enables JSON encoding and decoding

  • Used for persistence and API communication

  • No custom encoding/decoding required as all properties are standard types

Identifiable

  • Provides unique identification for SwiftUI integration

  • Uses the id property as the unique identifier

  • Enables direct use in SwiftUI Lists and ForEach

Hashable

  • Custom implementation focusing on id property

  • Enables use in Sets and as Dictionary keys

  • Implementation:

    func hash(into hasher: inout Hasher) {
        hasher.combine(id)
    }
    
    static func == (lhs: Entry, rhs: Entry) -> Bool {
        lhs.id == rhs.id
    }

Initialization

init(id: UUID = UUID(), 
     content: String, 
     timestamp: Date = Date(), 
     embeddings: [Float] = [])

Parameters

  • id: Optional. Defaults to new UUID if not provided

  • content: Required. The text content of the entry

  • timestamp: Optional. Defaults to current date/time

  • embeddings: Optional. Defaults to empty array

Usage Examples

Creating a Basic Entry

let entry = Entry(content: "Sample text content")

Creating an Entry with Custom Values

let entry = Entry(
    id: UUID(),
    content: "Custom entry",
    timestamp: Date(),
    embeddings: [0.1, 0.2, 0.3]
)

Using in Collections

var entrySet = Set<Entry>()
entrySet.insert(entry)

var entryDictionary = [Entry: String]()
entryDictionary[entry] = "metadata"

Best Practices

  1. Always initialize with the content parameter at minimum

  2. Use the default initialization for id unless you need a specific UUID

  3. Only provide embeddings when they've been generated through the NLP pipeline

  4. Consider the timestamp carefully - use the default (current time) for new entries, but preserve original timestamps when loading existing data

  • ClusterModel.swift: Uses Entry objects in collections

  • Storage Provider: Handles persistence of Entry objects

  • NLP Processing: Generates embeddings for Entry content

Last updated