Class: Pikuri::Memory::Record

Inherits:
Data
  • Object
show all
Defined in:
lib/pikuri/memory/record.rb

Overview

One memory row as returned by a mem0 server, normalized into a plain value object. The same shape backs all three read/write surfaces — add (carries event, no score), search (carries score, no event), and get_all (neither) — with the absent fields left nil, so callers can pattern-match on what's present rather than juggling three near-identical types.

Field provenance (mem0 v3 JSON → this)

  • id"id" — the memory's UUID; the handle for delete.
  • text"memory" — the fact string. Named text so it doesn't shadow the enclosing module (+record.memory+ reads oddly).
  • score"score" — Qdrant similarity (higher = more relevant); nil outside search results.
  • created_at"created_at" — ISO-8601 String. Load-bearing for recall: recency is the consuming LLM's tiebreaker when resolving a stale fact against its correction, so it must travel with the text.
  • metadata"metadata" — arbitrary Hash; {} when absent.
  • event"event""ADD" / "UPDATE" / "DELETE" / "NONE" on an add response; nil on reads.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at

Returns:

  • (Object)

    the current value of created_at



27
28
29
# File 'lib/pikuri/memory/record.rb', line 27

def created_at
  @created_at
end

#eventObject (readonly)

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



27
28
29
# File 'lib/pikuri/memory/record.rb', line 27

def event
  @event
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



27
28
29
# File 'lib/pikuri/memory/record.rb', line 27

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



27
28
29
# File 'lib/pikuri/memory/record.rb', line 27

def 
  @metadata
end

#scoreObject (readonly)

Returns the value of attribute score

Returns:

  • (Object)

    the current value of score



27
28
29
# File 'lib/pikuri/memory/record.rb', line 27

def score
  @score
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



27
28
29
# File 'lib/pikuri/memory/record.rb', line 27

def text
  @text
end

Class Method Details

.from(hash) ⇒ Record

Build a Pikuri::Memory::Record from one mem0 result Hash (String keys, as Faraday's JSON middleware deserializes them). Tolerant of missing keys — every field but metadata defaults to nil, and metadata to {} — so the one factory serves add / search / get_all rows alike.

Parameters:

  • hash (Hash)

    one element of a mem0 "results" array

Returns:



36
37
38
39
40
41
42
43
44
45
# File 'lib/pikuri/memory/record.rb', line 36

def self.from(hash)
  new(
    id: hash['id'],
    text: hash['memory'],
    score: hash['score'],
    created_at: hash['created_at'],
    metadata: hash['metadata'] || {},
    event: hash['event']
  )
end

Instance Method Details

#created_labelString?

created_at trimmed to whole-second wall-clock for the prompt: +"2026-06-01T17:04:11.884889+00:00"+ → "2026-06-01 17:04:11" (sub-second precision and offset machinery are token noise when the timestamp is only a recency tiebreaker). nil when created_at is absent; falls back to the raw String on an unparseable value.

Returns:

  • (String, nil)


54
55
56
57
58
59
60
# File 'lib/pikuri/memory/record.rb', line 54

def created_label
  return nil unless created_at

  Time.parse(created_at).strftime('%Y-%m-%d %H:%M:%S')
rescue ArgumentError
  created_at
end