Class: LangGraphRB::Stores::InMemoryStore
- Defined in:
- lib/langgraph_rb/stores/memory.rb
Overview
In-memory store (not persistent across process restarts)
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(thread_id) ⇒ Object
-
#initialize ⇒ InMemoryStore
constructor
A new instance of InMemoryStore.
- #list_steps(thread_id) ⇒ Object
- #list_threads ⇒ Object
- #load(thread_id, step_number = nil) ⇒ Object
- #save(thread_id, state, step_number, metadata = {}) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryStore
Returns a new instance of InMemoryStore.
32 33 34 |
# File 'lib/langgraph_rb/stores/memory.rb', line 32 def initialize @data = {} end |
Instance Method Details
#clear ⇒ Object
89 90 91 |
# File 'lib/langgraph_rb/stores/memory.rb', line 89 def clear @data.clear end |
#delete(thread_id) ⇒ Object
78 79 80 |
# File 'lib/langgraph_rb/stores/memory.rb', line 78 def delete(thread_id) @data.delete(thread_id) end |
#list_steps(thread_id) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/langgraph_rb/stores/memory.rb', line 82 def list_steps(thread_id) thread_data = @data[thread_id] return [] unless thread_data thread_data.keys.sort end |
#list_threads ⇒ Object
74 75 76 |
# File 'lib/langgraph_rb/stores/memory.rb', line 74 def list_threads @data.keys end |
#load(thread_id, step_number = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/langgraph_rb/stores/memory.rb', line 45 def load(thread_id, step_number = nil) thread_data = @data[thread_id] return nil unless thread_data if step_number checkpoint = thread_data[step_number] return nil unless checkpoint { state: deep_copy(checkpoint[:state]), step_number: step_number, timestamp: checkpoint[:timestamp], metadata: checkpoint[:metadata] } else # Return latest checkpoint latest_step = thread_data.keys.max return nil unless latest_step checkpoint = thread_data[latest_step] { state: deep_copy(checkpoint[:state]), step_number: latest_step, timestamp: checkpoint[:timestamp], metadata: checkpoint[:metadata] } end end |
#save(thread_id, state, step_number, metadata = {}) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/langgraph_rb/stores/memory.rb', line 36 def save(thread_id, state, step_number, = {}) @data[thread_id] ||= {} @data[thread_id][step_number] = { state: deep_copy(state), timestamp: Time.now, metadata: } end |