Class: Engram::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/engram/record.rb

Overview

A single unit of memory.

‘id` is assigned by the store on persistence (nil until then); consolidation uses it to target UPDATE/FORGET. `scope` namespaces memories to an owner (e.g. “user:42”). `kind` is a memory type (fact / preference / instruction / episodic). The legacy `semantic` kind is normalized to `fact` for compatibility with pre-1.0 records.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, scope:, id: nil, embedding: nil, kind: :fact, importance: 1.0, metadata: {}, created_at: nil, last_accessed_at: nil) ⇒ Record

Returns a new instance of Record.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/engram/record.rb', line 15

def initialize(content:, scope:, id: nil, embedding: nil, kind: :fact,
  importance: 1.0, metadata: {}, created_at: nil, last_accessed_at: nil)
  @id = id
  @content = content
  @scope = scope
  @embedding = embedding
  @kind = MemoryKind.normalize(kind)
  @importance = importance
  @metadata = 
  @created_at = created_at || Time.now
  @last_accessed_at = last_accessed_at
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/engram/record.rb', line 12

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/engram/record.rb', line 12

def created_at
  @created_at
end

#embeddingObject (readonly)

Returns the value of attribute embedding.



12
13
14
# File 'lib/engram/record.rb', line 12

def embedding
  @embedding
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/engram/record.rb', line 11

def id
  @id
end

#importanceObject (readonly)

Returns the value of attribute importance.



12
13
14
# File 'lib/engram/record.rb', line 12

def importance
  @importance
end

#kindObject (readonly)

Returns the value of attribute kind.



12
13
14
# File 'lib/engram/record.rb', line 12

def kind
  @kind
end

#last_accessed_atObject

Returns the value of attribute last_accessed_at.



11
12
13
# File 'lib/engram/record.rb', line 11

def last_accessed_at
  @last_accessed_at
end

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/engram/record.rb', line 12

def 
  @metadata
end

#scopeObject (readonly)

Returns the value of attribute scope.



12
13
14
# File 'lib/engram/record.rb', line 12

def scope
  @scope
end

Instance Method Details

#to_hObject



32
33
34
35
36
37
38
# File 'lib/engram/record.rb', line 32

def to_h
  {
    id: id, content: content, scope: scope, embedding: embedding, kind: kind,
    importance: importance, metadata: ,
    created_at: created_at, last_accessed_at: last_accessed_at
  }
end

#with(**attributes) ⇒ Object



28
29
30
# File 'lib/engram/record.rb', line 28

def with(**attributes)
  self.class.new(**to_h.merge(attributes))
end