htm 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +269 -79
- data/db/migrate/00003_create_file_sources.rb +5 -0
- data/db/migrate/00004_create_nodes.rb +17 -0
- data/db/migrate/00005_create_tags.rb +7 -0
- data/db/migrate/00006_create_node_tags.rb +2 -0
- data/db/migrate/00007_create_robot_nodes.rb +7 -0
- data/db/schema.sql +41 -29
- data/docs/api/yard/HTM/Configuration.md +54 -0
- data/docs/api/yard/HTM/Database.md +13 -10
- data/docs/api/yard/HTM/EmbeddingService.md +5 -1
- data/docs/api/yard/HTM/LongTermMemory.md +18 -277
- data/docs/api/yard/HTM/PropositionError.md +18 -0
- data/docs/api/yard/HTM/PropositionService.md +66 -0
- data/docs/api/yard/HTM/QueryCache.md +88 -0
- data/docs/api/yard/HTM/RobotGroup.md +481 -0
- data/docs/api/yard/HTM/SqlBuilder.md +108 -0
- data/docs/api/yard/HTM/TagService.md +4 -0
- data/docs/api/yard/HTM/Telemetry/NullInstrument.md +13 -0
- data/docs/api/yard/HTM/Telemetry/NullMeter.md +15 -0
- data/docs/api/yard/HTM/Telemetry.md +109 -0
- data/docs/api/yard/HTM/WorkingMemoryChannel.md +176 -0
- data/docs/api/yard/HTM.md +11 -23
- data/docs/api/yard/index.csv +102 -25
- data/docs/api/yard-reference.md +8 -0
- data/docs/assets/images/multi-provider-failover.svg +51 -0
- data/docs/assets/images/robot-group-architecture.svg +65 -0
- data/docs/database/README.md +3 -3
- data/docs/database/public.file_sources.svg +29 -21
- data/docs/database/public.node_tags.md +2 -0
- data/docs/database/public.node_tags.svg +53 -41
- data/docs/database/public.nodes.md +2 -0
- data/docs/database/public.nodes.svg +52 -40
- data/docs/database/public.robot_nodes.md +2 -0
- data/docs/database/public.robot_nodes.svg +30 -22
- data/docs/database/public.robots.svg +16 -12
- data/docs/database/public.tags.md +3 -0
- data/docs/database/public.tags.svg +41 -33
- data/docs/database/schema.json +66 -0
- data/docs/database/schema.svg +60 -48
- data/docs/development/index.md +13 -0
- data/docs/development/rake-tasks.md +1068 -0
- data/docs/getting-started/quick-start.md +144 -155
- data/docs/guides/adding-memories.md +2 -3
- data/docs/guides/context-assembly.md +185 -184
- data/docs/guides/getting-started.md +154 -148
- data/docs/guides/index.md +7 -0
- data/docs/guides/long-term-memory.md +60 -92
- data/docs/guides/mcp-server.md +617 -0
- data/docs/guides/multi-robot.md +249 -345
- data/docs/guides/recalling-memories.md +153 -163
- data/docs/guides/robot-groups.md +604 -0
- data/docs/guides/search-strategies.md +61 -58
- data/docs/guides/working-memory.md +103 -136
- data/docs/index.md +30 -26
- data/examples/robot_groups/robot_worker.rb +1 -2
- data/examples/robot_groups/same_process.rb +1 -4
- data/lib/htm/robot_group.rb +721 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm/working_memory_channel.rb +250 -0
- data/lib/htm.rb +2 -0
- data/mkdocs.yml +2 -0
- metadata +18 -9
- data/db/migrate/00009_add_working_memory_to_robot_nodes.rb +0 -12
- data/db/migrate/00010_add_soft_delete_to_associations.rb +0 -29
- data/db/migrate/00011_add_performance_indexes.rb +0 -21
- data/db/migrate/00012_add_tags_trigram_index.rb +0 -18
- data/db/migrate/00013_enable_lz4_compression.rb +0 -43
- data/examples/robot_groups/lib/robot_group.rb +0 -419
- data/examples/robot_groups/lib/working_memory_channel.rb +0 -140
|
@@ -140,70 +140,60 @@ conn.close
|
|
|
140
140
|
|
|
141
141
|
### Using LongTermMemory Directly
|
|
142
142
|
|
|
143
|
-
Access the long-term memory layer:
|
|
143
|
+
Access the long-term memory layer (advanced usage):
|
|
144
144
|
|
|
145
145
|
```ruby
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
# Add a node
|
|
149
|
-
node_id = ltm.add(
|
|
150
|
-
key: "test_001",
|
|
151
|
-
value: "Test memory",
|
|
152
|
-
type: :fact,
|
|
153
|
-
importance: 7.0,
|
|
154
|
-
token_count: 10,
|
|
155
|
-
robot_id: "test-robot",
|
|
156
|
-
embedding: Array.new(1536) { rand }
|
|
157
|
-
)
|
|
146
|
+
# Access via HTM instance
|
|
147
|
+
ltm = htm.long_term_memory
|
|
158
148
|
|
|
159
|
-
# Retrieve a node
|
|
160
|
-
node = ltm.retrieve(
|
|
149
|
+
# Retrieve a node by ID
|
|
150
|
+
node = ltm.retrieve(123) # Returns Node model or nil
|
|
161
151
|
|
|
162
|
-
#
|
|
163
|
-
|
|
152
|
+
# The recommended way to add memories is via HTM
|
|
153
|
+
node_id = htm.remember(
|
|
154
|
+
"Test memory",
|
|
155
|
+
tags: ["test"],
|
|
156
|
+
metadata: { category: "fact" }
|
|
157
|
+
)
|
|
164
158
|
|
|
165
|
-
#
|
|
166
|
-
ltm.
|
|
159
|
+
# Retrieve the node
|
|
160
|
+
node = ltm.retrieve(node_id)
|
|
161
|
+
puts "Content: #{node.content}"
|
|
162
|
+
puts "Created: #{node.created_at}"
|
|
167
163
|
```
|
|
168
164
|
|
|
169
165
|
## Memory Statistics
|
|
170
166
|
|
|
171
|
-
Get
|
|
167
|
+
Get statistics using ActiveRecord:
|
|
172
168
|
|
|
173
169
|
```ruby
|
|
174
|
-
stats = htm.memory_stats
|
|
175
|
-
|
|
176
170
|
# Total nodes
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
171
|
+
total_nodes = HTM::Models::Node.count
|
|
172
|
+
puts "Total nodes: #{total_nodes}"
|
|
173
|
+
|
|
174
|
+
# Nodes by robot via robot_nodes join table
|
|
175
|
+
robot_counts = HTM::Models::RobotNode
|
|
176
|
+
.group(:robot_id)
|
|
177
|
+
.count
|
|
178
|
+
puts "Nodes by robot:"
|
|
179
|
+
robot_counts.each do |robot_id, count|
|
|
180
|
+
robot = HTM::Models::Robot.find(robot_id)
|
|
181
|
+
puts " #{robot.name}: #{count} nodes"
|
|
182
182
|
end
|
|
183
183
|
|
|
184
|
-
#
|
|
185
|
-
|
|
186
|
-
puts "Type #{row['type']}: #{row['count']} nodes"
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
# Relationships
|
|
190
|
-
puts "Total relationships: #{stats[:total_relationships]}"
|
|
191
|
-
|
|
192
|
-
# Tags
|
|
193
|
-
puts "Total tags: #{stats[:total_tags]}"
|
|
184
|
+
# Total tags
|
|
185
|
+
puts "Total tags: #{HTM::Models::Tag.count}"
|
|
194
186
|
|
|
195
187
|
# Time range
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
size_mb = stats[:database_size] / (1024.0 * 1024.0)
|
|
201
|
-
puts "Database size: #{size_mb.round(2)} MB"
|
|
188
|
+
oldest = HTM::Models::Node.minimum(:created_at)
|
|
189
|
+
newest = HTM::Models::Node.maximum(:created_at)
|
|
190
|
+
puts "Oldest memory: #{oldest}"
|
|
191
|
+
puts "Newest memory: #{newest}"
|
|
202
192
|
|
|
203
193
|
# Active robots
|
|
204
|
-
puts "Active robots: #{
|
|
205
|
-
|
|
206
|
-
puts " #{robot
|
|
194
|
+
puts "Active robots: #{HTM::Models::Robot.count}"
|
|
195
|
+
HTM::Models::Robot.order(last_active_at: :desc).each do |robot|
|
|
196
|
+
puts " #{robot.name}: last active #{robot.last_active_at}"
|
|
207
197
|
end
|
|
208
198
|
```
|
|
209
199
|
|
|
@@ -870,72 +860,50 @@ conn.close
|
|
|
870
860
|
|
|
871
861
|
```ruby
|
|
872
862
|
require 'htm'
|
|
873
|
-
require 'pg'
|
|
874
863
|
|
|
875
864
|
# Initialize HTM
|
|
876
865
|
htm = HTM.new(robot_name: "Database Admin")
|
|
877
866
|
|
|
878
867
|
# Add some test data
|
|
879
868
|
puts "Adding test data..."
|
|
869
|
+
node_ids = []
|
|
880
870
|
10.times do |i|
|
|
881
|
-
htm.
|
|
882
|
-
"test_#{i}",
|
|
871
|
+
node_id = htm.remember(
|
|
883
872
|
"Test memory number #{i}",
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
tags: ["test", "batch_#{i / 5}"]
|
|
873
|
+
tags: ["test", "batch:#{i / 5}"],
|
|
874
|
+
metadata: { category: "fact", index: i }
|
|
887
875
|
)
|
|
876
|
+
node_ids << node_id
|
|
888
877
|
end
|
|
889
878
|
|
|
890
|
-
# Get statistics
|
|
879
|
+
# Get statistics using ActiveRecord
|
|
891
880
|
puts "\n=== Database Statistics ==="
|
|
892
|
-
|
|
893
|
-
puts "Total
|
|
894
|
-
puts "
|
|
895
|
-
puts "Active robots: #{stats[:active_robots]}"
|
|
881
|
+
puts "Total nodes: #{HTM::Models::Node.count}"
|
|
882
|
+
puts "Total tags: #{HTM::Models::Tag.count}"
|
|
883
|
+
puts "Active robots: #{HTM::Models::Robot.count}"
|
|
896
884
|
|
|
897
|
-
# Query by tag
|
|
885
|
+
# Query by tag using ActiveRecord
|
|
898
886
|
puts "\n=== Query by Tag ==="
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
JOIN tags t ON n.id = t.node_id
|
|
907
|
-
WHERE t.tag = $1
|
|
908
|
-
SQL
|
|
909
|
-
['test']
|
|
910
|
-
)
|
|
911
|
-
|
|
912
|
-
puts "Found #{result.ntuples} nodes with tag 'test'"
|
|
913
|
-
result.each do |row|
|
|
914
|
-
puts "- #{row['key']}: #{row['value']}"
|
|
887
|
+
test_tag = HTM::Models::Tag.find_by(name: "test")
|
|
888
|
+
if test_tag
|
|
889
|
+
tagged_nodes = test_tag.nodes
|
|
890
|
+
puts "Found #{tagged_nodes.count} nodes with tag 'test'"
|
|
891
|
+
tagged_nodes.each do |node|
|
|
892
|
+
puts "- #{node.id}: #{node.content}"
|
|
893
|
+
end
|
|
915
894
|
end
|
|
916
895
|
|
|
917
896
|
# Performance check
|
|
918
897
|
puts "\n=== Performance Metrics ==="
|
|
919
|
-
result = conn.exec(
|
|
920
|
-
<<~SQL
|
|
921
|
-
SELECT
|
|
922
|
-
pg_size_pretty(pg_total_relation_size('nodes')) as nodes_size,
|
|
923
|
-
pg_size_pretty(pg_total_relation_size('relationships')) as rel_size,
|
|
924
|
-
pg_size_pretty(pg_total_relation_size('tags')) as tags_size
|
|
925
|
-
SQL
|
|
926
|
-
)
|
|
927
|
-
|
|
928
898
|
puts "Table sizes:"
|
|
929
|
-
puts " nodes: #{
|
|
930
|
-
puts "
|
|
931
|
-
puts "
|
|
899
|
+
puts " nodes: #{HTM::Models::Node.count} records"
|
|
900
|
+
puts " tags: #{HTM::Models::Tag.count} records"
|
|
901
|
+
puts " node_tags: #{HTM::Models::NodeTag.count} records"
|
|
932
902
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
# Cleanup test data
|
|
903
|
+
# Cleanup test data (soft delete)
|
|
936
904
|
puts "\n=== Cleanup ==="
|
|
937
|
-
|
|
938
|
-
htm.forget(
|
|
905
|
+
node_ids.each do |node_id|
|
|
906
|
+
htm.forget(node_id) # Soft delete by default
|
|
939
907
|
end
|
|
940
|
-
puts "Test data
|
|
908
|
+
puts "Test data soft-deleted (recoverable)"
|
|
941
909
|
```
|