Class: Documentrix::Documents::Cache::Records::Record

Inherits:
JSON::GenericObject
  • Object
show all
Defined in:
lib/documentrix/documents/cache/records.rb

Overview

A record class for caching document embeddings and their associated metadata.

This class extends JSON::GenericObject and is used to represent cached document entries in the Documentrix library. It stores text content, embedding vectors, normalization values, source information, and tags associated with each document record. The class provides methods for string representation, tag handling, and equality comparison based on text content.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Record

The initialize method sets default values for the text and norm attributes.

Parameters:

  • options (Hash) (defaults to: {})

    A hash containing optional parameters.



21
22
23
24
25
# File 'lib/documentrix/documents/cache/records.rb', line 21

def initialize(options = {})
  super
  self.text ||= ''
  self.norm ||= 0.0
end

Instance Method Details

#==(other) ⇒ FalseClass, TrueClass

The == method compares this record with another one by comparing their text fields.

Parameters:

Returns:

  • (FalseClass, TrueClass)

    true if both records have the same text, false otherwise.



52
53
54
# File 'lib/documentrix/documents/cache/records.rb', line 52

def ==(other)
  text == other.text
end

#tags_setDocumentrix::Utils::Tags

The tags_set method creates a new Documentrix::Utils::Tags object from the tags and source of this instance.

Returns:



41
42
43
# File 'lib/documentrix/documents/cache/records.rb', line 41

def tags_set
  Documentrix::Utils::Tags.new(tags, source:)
end

#to_sString Also known as: inspect

The to_s method returns a string representation of the object.

Returns:

  • (String)

    A string containing the text and tags of the record, along with its similarity score.



31
32
33
34
35
# File 'lib/documentrix/documents/cache/records.rb', line 31

def to_s
  my_tags = tags_set
  my_tags.empty? or my_tags = " #{my_tags}"
  "#<#{self.class} #{text.inspect}#{my_tags} #{similarity || 'n/a'}>"
end