Class: SwarmSDK::V3::Memory::Edge
- Inherits:
-
Object
- Object
- SwarmSDK::V3::Memory::Edge
- Defined in:
- lib/swarm_sdk/v3/memory/edge.rb
Overview
A typed relationship between two memory cards
Edges form a knowledge graph connecting related cards. They enable graph-based retrieval — when a card is relevant, its neighbors can be pulled in for richer context.
Constant Summary collapse
- TYPES =
[ :elaborates, :depends_on, :supports, :contradicts, :same_entity, :same_episode, :decision_reason, ].freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Creation timestamp.
-
#from_id ⇒ String
readonly
Source card ID.
-
#to_id ⇒ String
readonly
Target card ID.
-
#type ⇒ Symbol
readonly
Relationship type.
-
#weight ⇒ Float
readonly
Edge weight (0.0-1.0).
Class Method Summary collapse
-
.from_h(hash) ⇒ Edge
Deserialize from a hash.
Instance Method Summary collapse
-
#initialize(from_id:, to_id:, type:, weight: 1.0, created_at: nil) ⇒ Edge
constructor
Create a new edge.
-
#to_h ⇒ Hash
Serialize to a hash.
Constructor Details
#initialize(from_id:, to_id:, type:, weight: 1.0, created_at: nil) ⇒ Edge
Create a new edge
54 55 56 57 58 59 60 61 62 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 54 def initialize(from_id:, to_id:, type:, weight: 1.0, created_at: nil) @from_id = from_id @to_id = to_id @type = type.to_sym @weight = weight.to_f.clamp(0.0, 1.0) @created_at = created_at || Time.now validate! end |
Instance Attribute Details
#created_at ⇒ Time (readonly)
Returns Creation timestamp.
43 44 45 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 43 def created_at @created_at end |
#from_id ⇒ String (readonly)
Returns Source card ID.
31 32 33 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 31 def from_id @from_id end |
#to_id ⇒ String (readonly)
Returns Target card ID.
34 35 36 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 34 def to_id @to_id end |
#type ⇒ Symbol (readonly)
Returns Relationship type.
37 38 39 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 37 def type @type end |
#weight ⇒ Float (readonly)
Returns Edge weight (0.0-1.0).
40 41 42 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 40 def weight @weight end |
Class Method Details
.from_h(hash) ⇒ Edge
Deserialize from a hash
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 82 def from_h(hash) hash = hash.transform_keys(&:to_sym) new( from_id: hash[:from_id], to_id: hash[:to_id], type: hash[:type]&.to_sym, weight: hash[:weight] || 1.0, created_at: hash[:created_at] ? Time.parse(hash[:created_at]) : nil, ) end |
Instance Method Details
#to_h ⇒ Hash
Serialize to a hash
67 68 69 70 71 72 73 74 75 |
# File 'lib/swarm_sdk/v3/memory/edge.rb', line 67 def to_h { from_id: @from_id, to_id: @to_id, type: @type.to_s, weight: @weight, created_at: @created_at.iso8601, } end |