Class: RubyLLM::SemanticCache::Entry
- Inherits:
-
Object
- Object
- RubyLLM::SemanticCache::Entry
- Defined in:
- lib/ruby_llm/semantic_cache/entry.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#embedding ⇒ Object
readonly
Returns the value of attribute embedding.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query:, response:, embedding:, metadata: {}, id: nil, created_at: nil) ⇒ Entry
constructor
A new instance of Entry.
- #to_h ⇒ Object
Constructor Details
#initialize(query:, response:, embedding:, metadata: {}, id: nil, created_at: nil) ⇒ Entry
Returns a new instance of Entry.
11 12 13 14 15 16 17 18 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 11 def initialize(query:, response:, embedding:, metadata: {}, id: nil, created_at: nil) @id = id || SecureRandom.uuid @query = query @response = response = = @created_at = created_at || Time.now end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 9 def created_at @created_at end |
#embedding ⇒ Object (readonly)
Returns the value of attribute embedding.
9 10 11 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 9 def end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 9 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 9 def end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
9 10 11 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 9 def query @query end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 9 def response @response end |
Class Method Details
.from_h(hash) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 30 def self.from_h(hash) new( id: hash[:id] || hash["id"], query: hash[:query] || hash["query"], response: hash[:response] || hash["response"], embedding: hash[:embedding] || hash["embedding"], metadata: hash[:metadata] || hash["metadata"] || {}, created_at: parse_time(hash[:created_at] || hash["created_at"]) ) end |
.parse_time(value) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 41 def self.parse_time(value) case value when Time then value when String then Time.parse(value) when nil then Time.now else value end end |
Instance Method Details
#to_h ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_llm/semantic_cache/entry.rb', line 20 def to_h { id: @id, query: @query, response: @response, metadata: , created_at: @created_at.iso8601 } end |