htm 0.0.18 → 0.0.30
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 +119 -1
- data/README.md +12 -0
- data/Rakefile +104 -18
- data/db/migrate/00001_enable_extensions.rb +9 -5
- data/db/migrate/00002_create_robots.rb +18 -6
- data/db/migrate/00003_create_file_sources.rb +30 -17
- data/db/migrate/00004_create_nodes.rb +60 -48
- data/db/migrate/00005_create_tags.rb +24 -12
- data/db/migrate/00006_create_node_tags.rb +28 -13
- data/db/migrate/00007_create_robot_nodes.rb +40 -26
- data/db/schema.sql +17 -1
- data/db/seeds.rb +34 -34
- data/docs/api/embedding-service.md +140 -110
- data/docs/api/yard/HTM/ActiveRecordConfig.md +6 -0
- data/docs/api/yard/HTM/Config.md +173 -0
- data/docs/api/yard/HTM/ConfigSection.md +28 -0
- data/docs/api/yard/HTM/Database.md +1 -1
- data/docs/api/yard/HTM/Railtie.md +2 -2
- data/docs/api/yard/HTM.md +0 -57
- data/docs/api/yard/index.csv +76 -61
- data/docs/api/yard-reference.md +2 -1
- data/docs/architecture/adrs/003-ollama-embeddings.md +45 -36
- data/docs/architecture/adrs/004-hive-mind.md +1 -1
- data/docs/architecture/adrs/008-robot-identification.md +1 -1
- data/docs/architecture/index.md +11 -9
- data/docs/architecture/overview.md +11 -7
- data/docs/assets/images/balanced-strategy-decay.svg +41 -0
- data/docs/assets/images/class-hierarchy.svg +1 -1
- data/docs/assets/images/eviction-priority.svg +43 -0
- data/docs/assets/images/exception-hierarchy.svg +2 -2
- data/docs/assets/images/hive-mind-shared-memory.svg +52 -0
- data/docs/assets/images/htm-architecture-overview.svg +3 -3
- data/docs/assets/images/htm-core-components.svg +4 -4
- data/docs/assets/images/htm-layered-architecture.svg +1 -1
- data/docs/assets/images/htm-memory-addition-flow.svg +2 -2
- data/docs/assets/images/htm-memory-recall-flow.svg +2 -2
- data/docs/assets/images/memory-topology.svg +53 -0
- data/docs/assets/images/two-tier-memory-architecture.svg +55 -0
- data/docs/database/naming-convention.md +244 -0
- data/docs/database_rake_tasks.md +31 -0
- data/docs/development/rake-tasks.md +80 -35
- data/docs/development/setup.md +76 -44
- data/docs/examples/basic-usage.md +133 -0
- data/docs/examples/config-files.md +170 -0
- data/docs/examples/file-loading.md +208 -0
- data/docs/examples/index.md +116 -0
- data/docs/examples/llm-configuration.md +168 -0
- data/docs/examples/mcp-client.md +172 -0
- data/docs/examples/rails-integration.md +173 -0
- data/docs/examples/robot-groups.md +210 -0
- data/docs/examples/sinatra-integration.md +218 -0
- data/docs/examples/standalone-app.md +216 -0
- data/docs/examples/telemetry.md +224 -0
- data/docs/examples/timeframes.md +143 -0
- data/docs/getting-started/installation.md +97 -40
- data/docs/getting-started/quick-start.md +28 -11
- data/docs/guides/configuration.md +515 -0
- data/docs/guides/file-loading.md +322 -0
- data/docs/guides/getting-started.md +40 -9
- data/docs/guides/index.md +3 -3
- data/docs/guides/mcp-server.md +100 -13
- data/docs/guides/propositions.md +264 -0
- data/docs/guides/recalling-memories.md +4 -4
- data/docs/guides/search-strategies.md +3 -3
- data/docs/guides/tags.md +318 -0
- data/docs/guides/telemetry.md +229 -0
- data/docs/index.md +8 -16
- data/docs/{architecture → robots}/hive-mind.md +8 -111
- data/docs/robots/index.md +73 -0
- data/docs/{guides → robots}/multi-robot.md +3 -3
- data/docs/{guides → robots}/robot-groups.md +8 -7
- data/docs/{architecture → robots}/two-tier-memory.md +13 -149
- data/docs/robots/why-robots.md +85 -0
- data/examples/.envrc +6 -0
- data/examples/.gitignore +2 -0
- data/examples/00_create_examples_db.rb +94 -0
- data/examples/{basic_usage.rb → 01_basic_usage.rb} +12 -16
- data/examples/{custom_llm_configuration.rb → 03_custom_llm_configuration.rb} +13 -3
- data/examples/{file_loader_usage.rb → 04_file_loader_usage.rb} +11 -14
- data/examples/{timeframe_demo.rb → 05_timeframe_demo.rb} +10 -3
- data/examples/{example_app → 06_example_app}/app.rb +15 -15
- data/examples/{cli_app → 07_cli_app}/htm_cli.rb +15 -22
- data/examples/08_sinatra_app/Gemfile.lock +241 -0
- data/examples/{sinatra_app → 08_sinatra_app}/app.rb +19 -18
- data/examples/{mcp_client.rb → 09_mcp_client.rb} +5 -8
- data/examples/{telemetry → 10_telemetry}/SETUP_README.md +1 -1
- data/examples/{telemetry → 10_telemetry}/demo.rb +14 -10
- data/examples/11_robot_groups/README.md +335 -0
- data/examples/{robot_groups → 11_robot_groups/lib}/robot_worker.rb +17 -3
- data/examples/{robot_groups → 11_robot_groups}/multi_process.rb +9 -9
- data/examples/{robot_groups → 11_robot_groups}/same_process.rb +9 -12
- data/examples/{rails_app → 12_rails_app}/Gemfile +3 -0
- data/examples/{rails_app → 12_rails_app}/Gemfile.lock +87 -58
- data/examples/{rails_app → 12_rails_app}/app/controllers/dashboard_controller.rb +10 -6
- data/examples/{rails_app → 12_rails_app}/app/controllers/files_controller.rb +5 -5
- data/examples/{rails_app → 12_rails_app}/app/controllers/memories_controller.rb +11 -7
- data/examples/{rails_app → 12_rails_app}/app/controllers/robots_controller.rb +8 -8
- data/examples/12_rails_app/app/controllers/tags_controller.rb +36 -0
- data/examples/{rails_app → 12_rails_app}/app/views/dashboard/index.html.erb +2 -2
- data/examples/{rails_app → 12_rails_app}/app/views/files/new.html.erb +5 -2
- data/examples/{rails_app → 12_rails_app}/app/views/memories/_memory_card.html.erb +3 -3
- data/examples/{rails_app → 12_rails_app}/app/views/memories/deleted.html.erb +3 -3
- data/examples/{rails_app → 12_rails_app}/app/views/memories/edit.html.erb +3 -3
- data/examples/{rails_app → 12_rails_app}/app/views/memories/show.html.erb +4 -4
- data/examples/{rails_app → 12_rails_app}/app/views/robots/index.html.erb +2 -2
- data/examples/{rails_app → 12_rails_app}/app/views/robots/show.html.erb +4 -4
- data/examples/{rails_app → 12_rails_app}/app/views/search/index.html.erb +1 -1
- data/examples/{rails_app → 12_rails_app}/app/views/tags/index.html.erb +2 -2
- data/examples/{rails_app → 12_rails_app}/app/views/tags/show.html.erb +1 -1
- data/examples/12_rails_app/config/initializers/htm.rb +7 -0
- data/examples/12_rails_app/config/initializers/rack.rb +5 -0
- data/examples/README.md +230 -211
- data/examples/examples_helper.rb +138 -0
- data/lib/htm/config/builder.rb +167 -0
- data/lib/htm/config/database.rb +317 -0
- data/lib/htm/config/defaults.yml +41 -13
- data/lib/htm/config/section.rb +74 -0
- data/lib/htm/config/validator.rb +83 -0
- data/lib/htm/config.rb +65 -361
- data/lib/htm/database.rb +85 -127
- data/lib/htm/errors.rb +14 -0
- data/lib/htm/integrations/sinatra.rb +13 -44
- data/lib/htm/job_adapter.rb +75 -1
- data/lib/htm/jobs/generate_embedding_job.rb +3 -4
- data/lib/htm/jobs/generate_propositions_job.rb +4 -5
- data/lib/htm/jobs/generate_tags_job.rb +16 -15
- data/lib/htm/loaders/defaults_loader.rb +23 -0
- data/lib/htm/loaders/markdown_loader.rb +17 -15
- data/lib/htm/loaders/xdg_config_loader.rb +9 -9
- data/lib/htm/long_term_memory/fulltext_search.rb +14 -14
- data/lib/htm/long_term_memory/hybrid_search.rb +396 -229
- data/lib/htm/long_term_memory/node_operations.rb +24 -23
- data/lib/htm/long_term_memory/relevance_scorer.rb +23 -20
- data/lib/htm/long_term_memory/robot_operations.rb +4 -4
- data/lib/htm/long_term_memory/tag_operations.rb +91 -77
- data/lib/htm/long_term_memory/vector_search.rb +4 -5
- data/lib/htm/long_term_memory.rb +13 -13
- data/lib/htm/mcp/cli.rb +115 -8
- data/lib/htm/mcp/resources.rb +4 -3
- data/lib/htm/mcp/server.rb +5 -4
- data/lib/htm/mcp/tools.rb +37 -28
- data/lib/htm/migration.rb +72 -0
- data/lib/htm/models/file_source.rb +52 -31
- data/lib/htm/models/node.rb +224 -108
- data/lib/htm/models/node_tag.rb +49 -28
- data/lib/htm/models/robot.rb +38 -27
- data/lib/htm/models/robot_node.rb +63 -35
- data/lib/htm/models/tag.rb +126 -123
- data/lib/htm/observability.rb +45 -41
- data/lib/htm/proposition_service.rb +76 -7
- data/lib/htm/railtie.rb +2 -2
- data/lib/htm/robot_group.rb +30 -18
- data/lib/htm/sequel_config.rb +215 -0
- data/lib/htm/sql_builder.rb +14 -16
- data/lib/htm/tag_service.rb +78 -0
- data/lib/htm/tasks.rb +3 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm/workflows/remember_workflow.rb +213 -0
- data/lib/htm.rb +27 -22
- data/lib/tasks/db.rake +0 -2
- data/lib/tasks/doc.rake +2 -2
- data/lib/tasks/files.rake +11 -18
- data/lib/tasks/htm.rake +190 -62
- data/lib/tasks/jobs.rake +179 -54
- data/lib/tasks/tags.rake +8 -13
- data/mkdocs.yml +33 -8
- data/scripts/backfill_parent_tags.rb +376 -0
- data/scripts/normalize_plural_tags.rb +335 -0
- metadata +168 -86
- data/docs/api/yard/HTM/Configuration.md +0 -240
- data/docs/telemetry.md +0 -391
- data/examples/rails_app/app/controllers/tags_controller.rb +0 -30
- data/examples/sinatra_app/Gemfile.lock +0 -166
- data/lib/htm/active_record_config.rb +0 -104
- /data/examples/{config_file_example → 02_config_file_example}/README.md +0 -0
- /data/examples/{config_file_example → 02_config_file_example}/config/htm.local.yml +0 -0
- /data/examples/{config_file_example → 02_config_file_example}/custom_config.yml +0 -0
- /data/examples/{config_file_example → 02_config_file_example}/show_config.rb +0 -0
- /data/examples/{example_app → 06_example_app}/Rakefile +0 -0
- /data/examples/{cli_app → 07_cli_app}/README.md +0 -0
- /data/examples/{sinatra_app → 08_sinatra_app}/Gemfile +0 -0
- /data/examples/{telemetry → 10_telemetry}/README.md +0 -0
- /data/examples/{telemetry → 10_telemetry}/grafana/dashboards/htm-metrics.json +0 -0
- /data/examples/{rails_app → 12_rails_app}/.gitignore +0 -0
- /data/examples/{rails_app → 12_rails_app}/Procfile.dev +0 -0
- /data/examples/{rails_app → 12_rails_app}/README.md +0 -0
- /data/examples/{rails_app → 12_rails_app}/Rakefile +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/assets/stylesheets/application.css +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/assets/stylesheets/inter-font.css +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/controllers/application_controller.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/controllers/search_controller.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/javascript/application.js +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/javascript/controllers/application.js +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/javascript/controllers/index.js +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/files/index.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/files/show.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/layouts/application.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/memories/index.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/memories/new.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/robots/new.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/shared/_navbar.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/app/views/shared/_stat_card.html.erb +0 -0
- /data/examples/{rails_app → 12_rails_app}/bin/dev +0 -0
- /data/examples/{rails_app → 12_rails_app}/bin/rails +0 -0
- /data/examples/{rails_app → 12_rails_app}/bin/rake +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/application.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/boot.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/database.yml +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/environment.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/importmap.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/routes.rb +0 -0
- /data/examples/{rails_app → 12_rails_app}/config/tailwind.config.js +0 -0
- /data/examples/{rails_app → 12_rails_app}/config.ru +0 -0
- /data/examples/{rails_app → 12_rails_app}/log/.keep +0 -0
- /data/examples/{rails_app → 12_rails_app}/tmp/local_secret.txt +0 -0
data/examples/README.md
CHANGED
|
@@ -2,20 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
This directory contains example applications demonstrating various ways to use the HTM (Hierarchical Temporal Memory) gem.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
All examples use the `htm_examples` database, isolated from development and production data.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# One-time setup: create and configure examples database
|
|
11
|
+
rake examples:setup
|
|
12
|
+
|
|
13
|
+
# Run the basic example
|
|
14
|
+
rake examples:basic
|
|
15
|
+
|
|
16
|
+
# Run all standalone examples
|
|
17
|
+
rake examples:all
|
|
18
|
+
|
|
19
|
+
# Check examples database status
|
|
20
|
+
rake examples:status
|
|
21
|
+
```
|
|
6
22
|
|
|
7
|
-
|
|
23
|
+
## Prerequisites
|
|
8
24
|
|
|
9
25
|
1. **PostgreSQL Database** with pgvector extension:
|
|
10
26
|
```bash
|
|
11
|
-
|
|
27
|
+
# Create the examples database (done automatically by rake examples:setup)
|
|
28
|
+
createdb htm_examples
|
|
29
|
+
psql htm_examples -c "CREATE EXTENSION IF NOT EXISTS vector; CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
12
30
|
```
|
|
13
31
|
|
|
14
|
-
> **Note**:
|
|
15
|
-
>
|
|
16
|
-
> For example, with `HTM_DATABASE__URL=...htm_development` and `HTM_ENV=test`, HTM
|
|
17
|
-
> connects to `htm_test`. When `RAILS_ENV` is unset (typical for examples),
|
|
18
|
-
> behavior is unchanged.
|
|
32
|
+
> **Note**: All examples use `HTM_ENV=examples` which connects to `htm_examples` database.
|
|
33
|
+
> This isolation prevents examples from polluting development or production data.
|
|
19
34
|
|
|
20
35
|
2. **Ollama** (recommended for local LLM):
|
|
21
36
|
```bash
|
|
@@ -28,18 +43,62 @@ All examples require:
|
|
|
28
43
|
bundle install
|
|
29
44
|
```
|
|
30
45
|
|
|
46
|
+
## Available Rake Tasks
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
rake examples:setup # Set up examples database (create + setup schema)
|
|
50
|
+
rake examples:reset # Reset examples database (drop + create + setup)
|
|
51
|
+
rake examples:basic # Run basic_usage example
|
|
52
|
+
rake examples:all # Run all standalone examples
|
|
53
|
+
rake examples:status # Show examples database status
|
|
54
|
+
rake example # Alias for examples:basic
|
|
55
|
+
```
|
|
56
|
+
|
|
31
57
|
---
|
|
32
58
|
|
|
33
|
-
##
|
|
59
|
+
## Example Progression
|
|
60
|
+
|
|
61
|
+
Examples are numbered to indicate recommended learning order, from basic concepts to advanced features.
|
|
62
|
+
|
|
63
|
+
### 00_create_examples_db.rb
|
|
64
|
+
|
|
65
|
+
**Database setup for examples.**
|
|
66
|
+
|
|
67
|
+
Creates and configures the `htm_examples` database. Run this first before other examples.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
ruby examples/00_create_examples_db.rb
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### 01_basic_usage.rb
|
|
76
|
+
|
|
77
|
+
**Getting started with HTM fundamentals.**
|
|
78
|
+
|
|
79
|
+
Demonstrates the core API: configuring HTM, registering a robot, and using the three primary methods (`remember`, `recall`, `forget`).
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
ruby examples/01_basic_usage.rb
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Features:**
|
|
86
|
+
- HTM configuration with Ollama provider
|
|
87
|
+
- Robot initialization
|
|
88
|
+
- Storing memories with `remember()`
|
|
89
|
+
- Retrieving memories with `recall()` using timeframes
|
|
90
|
+
- Understanding async embedding/tag generation
|
|
91
|
+
|
|
92
|
+
---
|
|
34
93
|
|
|
35
|
-
###
|
|
94
|
+
### 02_config_file_example/
|
|
36
95
|
|
|
37
96
|
**Configuration management with source tracing.**
|
|
38
97
|
|
|
39
98
|
Demonstrates how HTM uses `anyway_config` for layered configuration from multiple sources, with source tracing to show where each value originated.
|
|
40
99
|
|
|
41
100
|
```bash
|
|
42
|
-
cd examples/
|
|
101
|
+
cd examples/02_config_file_example
|
|
43
102
|
ruby show_config.rb
|
|
44
103
|
```
|
|
45
104
|
|
|
@@ -65,37 +124,18 @@ HTM_EMBEDDING__MODEL=mxbai-embed-large ruby show_config.rb
|
|
|
65
124
|
HTM_ENV=production ruby show_config.rb
|
|
66
125
|
```
|
|
67
126
|
|
|
68
|
-
See [
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
### basic_usage.rb
|
|
73
|
-
|
|
74
|
-
**Getting started with HTM fundamentals.**
|
|
75
|
-
|
|
76
|
-
Demonstrates the core API: configuring HTM, registering a robot, and using the three primary methods (`remember`, `recall`, `forget`).
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
ruby examples/basic_usage.rb
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
**Features:**
|
|
83
|
-
- HTM configuration with Ollama provider
|
|
84
|
-
- Robot initialization
|
|
85
|
-
- Storing memories with `remember()`
|
|
86
|
-
- Retrieving memories with `recall()` using timeframes
|
|
87
|
-
- Understanding async embedding/tag generation
|
|
127
|
+
See [02_config_file_example/README.md](02_config_file_example/README.md) for detailed documentation.
|
|
88
128
|
|
|
89
129
|
---
|
|
90
130
|
|
|
91
|
-
###
|
|
131
|
+
### 03_custom_llm_configuration.rb
|
|
92
132
|
|
|
93
133
|
**Flexible LLM integration patterns.**
|
|
94
134
|
|
|
95
135
|
Shows how to configure HTM with custom embedding and tag generation methods, supporting multiple LLM providers or custom infrastructure.
|
|
96
136
|
|
|
97
137
|
```bash
|
|
98
|
-
ruby examples/
|
|
138
|
+
ruby examples/03_custom_llm_configuration.rb
|
|
99
139
|
```
|
|
100
140
|
|
|
101
141
|
**Features:**
|
|
@@ -108,14 +148,14 @@ ruby examples/custom_llm_configuration.rb
|
|
|
108
148
|
|
|
109
149
|
---
|
|
110
150
|
|
|
111
|
-
###
|
|
151
|
+
### 04_file_loader_usage.rb
|
|
112
152
|
|
|
113
153
|
**Loading documents into long-term memory.**
|
|
114
154
|
|
|
115
155
|
Demonstrates loading markdown files with automatic paragraph chunking, YAML frontmatter extraction, and source tracking for re-sync.
|
|
116
156
|
|
|
117
157
|
```bash
|
|
118
|
-
ruby examples/
|
|
158
|
+
ruby examples/04_file_loader_usage.rb
|
|
119
159
|
```
|
|
120
160
|
|
|
121
161
|
**Features:**
|
|
@@ -129,14 +169,14 @@ ruby examples/file_loader_usage.rb
|
|
|
129
169
|
|
|
130
170
|
---
|
|
131
171
|
|
|
132
|
-
###
|
|
172
|
+
### 05_timeframe_demo.rb
|
|
133
173
|
|
|
134
174
|
**Flexible time-based filtering for recall.**
|
|
135
175
|
|
|
136
176
|
Comprehensive demonstration of all timeframe options supported by `recall()`, including natural language parsing.
|
|
137
177
|
|
|
138
178
|
```bash
|
|
139
|
-
ruby examples/
|
|
179
|
+
ruby examples/05_timeframe_demo.rb
|
|
140
180
|
```
|
|
141
181
|
|
|
142
182
|
**Features:**
|
|
@@ -150,97 +190,101 @@ ruby examples/timeframe_demo.rb
|
|
|
150
190
|
|
|
151
191
|
---
|
|
152
192
|
|
|
153
|
-
###
|
|
193
|
+
### 06_example_app/
|
|
154
194
|
|
|
155
|
-
**
|
|
195
|
+
**Full-featured HTM demonstration with RubyLLM integration.**
|
|
156
196
|
|
|
157
|
-
A complete
|
|
197
|
+
A standalone application showing complete HTM workflow with database connection, Ollama integration, memory operations, and multiple search strategies.
|
|
158
198
|
|
|
159
199
|
```bash
|
|
160
|
-
|
|
161
|
-
ruby demo.rb
|
|
200
|
+
ruby examples/06_example_app/app.rb
|
|
162
201
|
```
|
|
163
202
|
|
|
164
|
-
The demo automatically:
|
|
165
|
-
- Checks/installs Prometheus and Grafana via Homebrew
|
|
166
|
-
- Starts both services if not running
|
|
167
|
-
- Configures Prometheus to scrape the demo's metrics
|
|
168
|
-
- Cleans up previous demo data
|
|
169
|
-
- Opens Grafana in your browser
|
|
170
|
-
|
|
171
203
|
**Features:**
|
|
172
|
-
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
204
|
+
- Database connection verification
|
|
205
|
+
- RubyLLM configuration for embeddings and tags
|
|
206
|
+
- Async embedding/tag generation with wait
|
|
207
|
+
- Comparison of search strategies (:fulltext, :vector, :hybrid)
|
|
208
|
+
- Detailed output of generated tags and embeddings
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### 07_cli_app/
|
|
213
|
+
|
|
214
|
+
**Interactive command-line application.**
|
|
215
|
+
|
|
216
|
+
A REPL-style CLI demonstrating synchronous job execution with the `:inline` backend, ideal for CLI tools and scripts.
|
|
175
217
|
|
|
176
|
-
**Dependencies:**
|
|
177
218
|
```bash
|
|
178
|
-
|
|
179
|
-
gem install prometheus-client webrick
|
|
219
|
+
ruby examples/07_cli_app/htm_cli.rb
|
|
180
220
|
```
|
|
181
221
|
|
|
182
|
-
|
|
222
|
+
**Commands:**
|
|
223
|
+
- `remember <text>` - Store information (waits for embedding/tags)
|
|
224
|
+
- `recall <topic>` - Hybrid search with LLM-powered response generation
|
|
225
|
+
- `tags [prefix]` - List all tags with linked node content
|
|
226
|
+
- `stats` - Memory statistics
|
|
227
|
+
- `help` - Show help
|
|
228
|
+
- `exit` - Quit
|
|
183
229
|
|
|
184
|
-
|
|
230
|
+
**Features:**
|
|
231
|
+
- Synchronous job execution (`:inline` backend)
|
|
232
|
+
- Real-time progress feedback
|
|
233
|
+
- Tag extraction visibility during search
|
|
234
|
+
- Hybrid search with scoring (similarity, tag_boost, combined)
|
|
235
|
+
- RubyLLM chat integration for context-aware responses
|
|
236
|
+
- Response storage in long-term memory
|
|
185
237
|
|
|
186
|
-
|
|
238
|
+
See [07_cli_app/README.md](07_cli_app/README.md) for detailed documentation.
|
|
187
239
|
|
|
188
|
-
|
|
240
|
+
---
|
|
189
241
|
|
|
190
|
-
|
|
242
|
+
### 08_sinatra_app/
|
|
191
243
|
|
|
192
|
-
|
|
244
|
+
**Web application with Sidekiq background processing.**
|
|
193
245
|
|
|
194
|
-
|
|
246
|
+
A Sinatra-based web application demonstrating HTM in a multi-user web context with async job processing.
|
|
195
247
|
|
|
196
248
|
```bash
|
|
197
|
-
|
|
249
|
+
cd examples/08_sinatra_app
|
|
250
|
+
bundle install
|
|
251
|
+
bundle exec ruby app.rb
|
|
198
252
|
```
|
|
199
253
|
|
|
200
|
-
**
|
|
201
|
-
-
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
- `
|
|
205
|
-
- `
|
|
206
|
-
- `
|
|
207
|
-
- `
|
|
208
|
-
- `
|
|
209
|
-
-
|
|
210
|
-
|
|
211
|
-
**Resources exposed:**
|
|
212
|
-
- `htm://statistics` - Memory statistics as JSON
|
|
213
|
-
- `htm://tags/hierarchy` - Tag hierarchy as text tree
|
|
214
|
-
- `htm://memories/recent` - Last 20 memories
|
|
215
|
-
|
|
216
|
-
**Claude Desktop configuration** (`~/.config/claude/claude_desktop_config.json`):
|
|
217
|
-
```json
|
|
218
|
-
{
|
|
219
|
-
"mcpServers": {
|
|
220
|
-
"htm-memory": {
|
|
221
|
-
"command": "ruby",
|
|
222
|
-
"args": ["/path/to/htm/examples/mcp_server.rb"],
|
|
223
|
-
"env": {
|
|
224
|
-
"HTM_DATABASE__URL": "postgresql://user@localhost:5432/htm_development"
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
```
|
|
254
|
+
**Features:**
|
|
255
|
+
- Sidekiq integration for background jobs
|
|
256
|
+
- Session-based robot identification
|
|
257
|
+
- RESTful API endpoints:
|
|
258
|
+
- `POST /api/remember` - Store information
|
|
259
|
+
- `GET /api/recall` - Search memories with timeframe filtering
|
|
260
|
+
- `GET /api/stats` - Memory statistics
|
|
261
|
+
- `GET /api/tags` - Tag tree structure
|
|
262
|
+
- `GET /api/health` - Health check
|
|
263
|
+
- Interactive HTML UI with hybrid search scoring display
|
|
264
|
+
- Tag tree visualization
|
|
230
265
|
|
|
231
|
-
|
|
266
|
+
**Environment Variables:**
|
|
267
|
+
- `HTM_DATABASE__URL` - PostgreSQL connection (required)
|
|
268
|
+
- `REDIS_URL` - Redis for Sidekiq (default: redis://localhost:6379/0)
|
|
269
|
+
- `SESSION_SECRET` - Session encryption key
|
|
232
270
|
|
|
233
|
-
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
### 09_mcp_client.rb
|
|
274
|
+
|
|
275
|
+
**Model Context Protocol (MCP) client for AI assistants.**
|
|
276
|
+
|
|
277
|
+
An interactive chat client that connects to an MCP server via STDIO and uses a local Ollama model for conversation. This enables AI assistants like Claude Desktop to use HTM's memory capabilities.
|
|
234
278
|
|
|
235
279
|
```bash
|
|
236
|
-
ruby examples/
|
|
280
|
+
ruby examples/09_mcp_client.rb
|
|
237
281
|
```
|
|
238
282
|
|
|
239
283
|
**Features:**
|
|
240
284
|
- Prompts for robot name on startup (or uses `HTM_ROBOT_NAME` env var)
|
|
241
285
|
- Calls `SetRobotTool` to establish robot identity with the server
|
|
242
286
|
- Offers to restore previous session from working memory
|
|
243
|
-
- Connects to
|
|
287
|
+
- Connects to MCP server automatically via STDIO transport
|
|
244
288
|
- Interactive chat loop with tool calling
|
|
245
289
|
- LLM decides when to remember/recall information
|
|
246
290
|
- Logs tool calls and results for visibility
|
|
@@ -254,7 +298,7 @@ ruby examples/mcp_client.rb
|
|
|
254
298
|
|
|
255
299
|
**Example startup and conversation:**
|
|
256
300
|
```
|
|
257
|
-
$ ruby examples/
|
|
301
|
+
$ ruby examples/09_mcp_client.rb
|
|
258
302
|
Connecting to HTM MCP server...
|
|
259
303
|
[✓] Connected to HTM MCP server
|
|
260
304
|
[✓] Found 9 tools:
|
|
@@ -304,89 +348,40 @@ ollama pull gpt-oss # Or your preferred model
|
|
|
304
348
|
|
|
305
349
|
---
|
|
306
350
|
|
|
307
|
-
|
|
351
|
+
### 10_telemetry/
|
|
308
352
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
**Full-featured HTM demonstration with RubyLLM integration.**
|
|
353
|
+
**Live Grafana dashboard for HTM metrics.**
|
|
312
354
|
|
|
313
|
-
A
|
|
355
|
+
A complete telemetry demo using Homebrew-installed Prometheus and Grafana to visualize HTM metrics in real-time graphs.
|
|
314
356
|
|
|
315
357
|
```bash
|
|
316
|
-
|
|
358
|
+
cd examples/10_telemetry
|
|
359
|
+
ruby demo.rb
|
|
317
360
|
```
|
|
318
361
|
|
|
319
|
-
|
|
320
|
-
-
|
|
321
|
-
-
|
|
322
|
-
-
|
|
323
|
-
-
|
|
324
|
-
-
|
|
325
|
-
|
|
326
|
-
---
|
|
327
|
-
|
|
328
|
-
### sinatra_app/
|
|
329
|
-
|
|
330
|
-
**Web application with Sidekiq background processing.**
|
|
331
|
-
|
|
332
|
-
A Sinatra-based web application demonstrating HTM in a multi-user web context with async job processing.
|
|
333
|
-
|
|
334
|
-
```bash
|
|
335
|
-
cd examples/sinatra_app
|
|
336
|
-
bundle install
|
|
337
|
-
bundle exec ruby app.rb
|
|
338
|
-
```
|
|
362
|
+
The demo automatically:
|
|
363
|
+
- Checks/installs Prometheus and Grafana via Homebrew
|
|
364
|
+
- Starts both services if not running
|
|
365
|
+
- Configures Prometheus to scrape the demo's metrics
|
|
366
|
+
- Cleans up previous demo data
|
|
367
|
+
- Opens Grafana in your browser
|
|
339
368
|
|
|
340
369
|
**Features:**
|
|
341
|
-
-
|
|
342
|
-
-
|
|
343
|
-
-
|
|
344
|
-
- `POST /api/remember` - Store information
|
|
345
|
-
- `GET /api/recall` - Search memories with timeframe filtering
|
|
346
|
-
- `GET /api/stats` - Memory statistics
|
|
347
|
-
- `GET /api/tags` - Tag tree structure
|
|
348
|
-
- `GET /api/health` - Health check
|
|
349
|
-
- Interactive HTML UI with hybrid search scoring display
|
|
350
|
-
- Tag tree visualization
|
|
351
|
-
|
|
352
|
-
**Environment Variables:**
|
|
353
|
-
- `HTM_DATABASE__URL` - PostgreSQL connection (required)
|
|
354
|
-
- `REDIS_URL` - Redis for Sidekiq (default: redis://localhost:6379/0)
|
|
355
|
-
- `SESSION_SECRET` - Session encryption key
|
|
356
|
-
|
|
357
|
-
---
|
|
358
|
-
|
|
359
|
-
### cli_app/
|
|
360
|
-
|
|
361
|
-
**Interactive command-line application.**
|
|
362
|
-
|
|
363
|
-
A REPL-style CLI demonstrating synchronous job execution with the `:inline` backend, ideal for CLI tools and scripts.
|
|
370
|
+
- Live updating dashboard with job counts, latencies, cache hit rates
|
|
371
|
+
- Pre-built Grafana dashboard JSON
|
|
372
|
+
- No Docker required - uses native macOS services
|
|
364
373
|
|
|
374
|
+
**Dependencies:**
|
|
365
375
|
```bash
|
|
366
|
-
|
|
376
|
+
brew install prometheus grafana
|
|
377
|
+
gem install prometheus-client webrick
|
|
367
378
|
```
|
|
368
379
|
|
|
369
|
-
|
|
370
|
-
- `remember <text>` - Store information (waits for embedding/tags)
|
|
371
|
-
- `recall <topic>` - Hybrid search with LLM-powered response generation
|
|
372
|
-
- `tags [prefix]` - List all tags with linked node content
|
|
373
|
-
- `stats` - Memory statistics
|
|
374
|
-
- `help` - Show help
|
|
375
|
-
- `exit` - Quit
|
|
376
|
-
|
|
377
|
-
**Features:**
|
|
378
|
-
- Synchronous job execution (`:inline` backend)
|
|
379
|
-
- Real-time progress feedback
|
|
380
|
-
- Tag extraction visibility during search
|
|
381
|
-
- Hybrid search with scoring (similarity, tag_boost, combined)
|
|
382
|
-
- RubyLLM chat integration for context-aware responses
|
|
383
|
-
- Response storage in long-term memory
|
|
384
|
-
|
|
385
|
-
See [cli_app/README.md](cli_app/README.md) for detailed documentation.
|
|
380
|
+
See [10_telemetry/README.md](10_telemetry/README.md) for detailed setup instructions.
|
|
386
381
|
|
|
387
382
|
---
|
|
388
383
|
|
|
389
|
-
###
|
|
384
|
+
### 11_robot_groups/
|
|
390
385
|
|
|
391
386
|
**Multi-robot coordination with shared working memory.**
|
|
392
387
|
|
|
@@ -397,7 +392,7 @@ Demonstrates high-availability patterns with shared working memory, failover, an
|
|
|
397
392
|
Single-process demonstration of robot groups:
|
|
398
393
|
|
|
399
394
|
```bash
|
|
400
|
-
ruby examples/
|
|
395
|
+
ruby examples/11_robot_groups/same_process.rb
|
|
401
396
|
```
|
|
402
397
|
|
|
403
398
|
**Scenarios demonstrated:**
|
|
@@ -415,7 +410,7 @@ ruby examples/robot_groups/same_process.rb
|
|
|
415
410
|
Cross-process demonstration with separate Ruby processes:
|
|
416
411
|
|
|
417
412
|
```bash
|
|
418
|
-
ruby examples/
|
|
413
|
+
ruby examples/11_robot_groups/multi_process.rb
|
|
419
414
|
```
|
|
420
415
|
|
|
421
416
|
**Scenarios demonstrated:**
|
|
@@ -433,45 +428,68 @@ ruby examples/robot_groups/multi_process.rb
|
|
|
433
428
|
|
|
434
429
|
---
|
|
435
430
|
|
|
431
|
+
### 12_rails_app/
|
|
432
|
+
|
|
433
|
+
**Rails integration example.**
|
|
434
|
+
|
|
435
|
+
A complete Rails application demonstrating HTM integration with Rails controllers, views, and background jobs.
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
cd examples/12_rails_app
|
|
439
|
+
bundle install
|
|
440
|
+
bin/rails db:create db:migrate
|
|
441
|
+
bin/dev
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
See [12_rails_app/README.md](12_rails_app/README.md) for detailed documentation.
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
436
448
|
## Directory Structure
|
|
437
449
|
|
|
438
450
|
```
|
|
439
451
|
examples/
|
|
440
|
-
├── README.md
|
|
441
|
-
├──
|
|
442
|
-
├──
|
|
443
|
-
├──
|
|
444
|
-
├──
|
|
445
|
-
├──
|
|
446
|
-
│ ├──
|
|
447
|
-
│ ├──
|
|
448
|
-
│ ├── README.md # Configuration documentation
|
|
452
|
+
├── README.md # This file
|
|
453
|
+
├── examples_helper.rb # Shared setup for all examples
|
|
454
|
+
├── 00_create_examples_db.rb # Database setup
|
|
455
|
+
├── 01_basic_usage.rb # Core API demonstration
|
|
456
|
+
├── 02_config_file_example/
|
|
457
|
+
│ ├── show_config.rb # Config source tracing demo
|
|
458
|
+
│ ├── custom_config.yml # Example for HTM_CONF
|
|
459
|
+
│ ├── README.md # Configuration documentation
|
|
449
460
|
│ └── config/
|
|
450
|
-
│ └── htm.local.yml
|
|
451
|
-
├──
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
│
|
|
456
|
-
├── mcp_server.rb # MCP server exposing HTM tools
|
|
457
|
-
├── mcp_client.rb # MCP client with chat interface
|
|
458
|
-
├── example_app/
|
|
459
|
-
│ ├── app.rb # Full-featured demo app
|
|
461
|
+
│ └── htm.local.yml # Auto-loaded local overrides
|
|
462
|
+
├── 03_custom_llm_configuration.rb # LLM integration patterns
|
|
463
|
+
├── 04_file_loader_usage.rb # Document loading
|
|
464
|
+
├── 05_timeframe_demo.rb # Time-based filtering
|
|
465
|
+
├── 06_example_app/
|
|
466
|
+
│ ├── app.rb # Full-featured demo app
|
|
460
467
|
│ └── Rakefile
|
|
461
|
-
├──
|
|
462
|
-
│ ├──
|
|
468
|
+
├── 07_cli_app/
|
|
469
|
+
│ ├── htm_cli.rb # Interactive CLI
|
|
470
|
+
│ └── README.md # Detailed CLI documentation
|
|
471
|
+
├── 08_sinatra_app/
|
|
472
|
+
│ ├── app.rb # Sinatra web application
|
|
463
473
|
│ ├── Gemfile
|
|
464
474
|
│ └── Gemfile.lock
|
|
465
|
-
├──
|
|
466
|
-
|
|
467
|
-
│
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
+
├── 09_mcp_client.rb # MCP client with chat interface
|
|
476
|
+
├── 10_telemetry/
|
|
477
|
+
│ ├── demo.rb # Live Grafana metrics dashboard
|
|
478
|
+
│ ├── README.md
|
|
479
|
+
│ ├── SETUP_README.md
|
|
480
|
+
│ └── grafana/dashboards/htm-metrics.json
|
|
481
|
+
├── 11_robot_groups/
|
|
482
|
+
│ ├── same_process.rb # Single-process robot groups
|
|
483
|
+
│ ├── multi_process.rb # Multi-process coordination
|
|
484
|
+
│ ├── robot_worker.rb # Worker process for multi_process.rb
|
|
485
|
+
│ └── lib/
|
|
486
|
+
│ ├── robot_group.rb # RobotGroup coordination class
|
|
487
|
+
│ └── working_memory_channel.rb # PostgreSQL pub/sub
|
|
488
|
+
└── 12_rails_app/
|
|
489
|
+
├── app/ # Rails application files
|
|
490
|
+
├── config/ # Rails configuration
|
|
491
|
+
├── Gemfile
|
|
492
|
+
└── README.md
|
|
475
493
|
```
|
|
476
494
|
|
|
477
495
|
---
|
|
@@ -480,15 +498,16 @@ examples/
|
|
|
480
498
|
|
|
481
499
|
| Use Case | Example |
|
|
482
500
|
|----------|---------|
|
|
483
|
-
|
|
|
484
|
-
|
|
|
485
|
-
|
|
|
486
|
-
|
|
|
487
|
-
|
|
|
488
|
-
|
|
|
489
|
-
|
|
|
490
|
-
|
|
|
491
|
-
| Web application | `
|
|
492
|
-
|
|
|
493
|
-
|
|
|
494
|
-
|
|
|
501
|
+
| Database setup | `00_create_examples_db.rb` |
|
|
502
|
+
| Learning HTM basics | `01_basic_usage.rb` |
|
|
503
|
+
| Configuration management | `02_config_file_example/` |
|
|
504
|
+
| Custom LLM integration | `03_custom_llm_configuration.rb` |
|
|
505
|
+
| Loading documents/files | `04_file_loader_usage.rb` |
|
|
506
|
+
| Time-based queries | `05_timeframe_demo.rb` |
|
|
507
|
+
| Full-featured demo | `06_example_app/` |
|
|
508
|
+
| CLI tool | `07_cli_app/` |
|
|
509
|
+
| Web application | `08_sinatra_app/` |
|
|
510
|
+
| MCP client with chat | `09_mcp_client.rb` |
|
|
511
|
+
| Production observability | `10_telemetry/` |
|
|
512
|
+
| Multi-robot coordination | `11_robot_groups/` |
|
|
513
|
+
| Rails integration | `12_rails_app/` |
|