htm 0.0.11 → 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.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.dictate.toml +46 -0
  3. data/.envrc +2 -0
  4. data/CHANGELOG.md +85 -2
  5. data/README.md +348 -79
  6. data/Rakefile +14 -2
  7. data/bin/htm_mcp.rb +94 -0
  8. data/config/database.yml +20 -13
  9. data/db/migrate/00003_create_file_sources.rb +5 -0
  10. data/db/migrate/00004_create_nodes.rb +17 -0
  11. data/db/migrate/00005_create_tags.rb +7 -0
  12. data/db/migrate/00006_create_node_tags.rb +2 -0
  13. data/db/migrate/00007_create_robot_nodes.rb +7 -0
  14. data/db/schema.sql +69 -100
  15. data/docs/api/index.md +1 -1
  16. data/docs/api/yard/HTM/Configuration.md +54 -0
  17. data/docs/api/yard/HTM/Database.md +13 -10
  18. data/docs/api/yard/HTM/EmbeddingService.md +5 -1
  19. data/docs/api/yard/HTM/LongTermMemory.md +18 -277
  20. data/docs/api/yard/HTM/PropositionError.md +18 -0
  21. data/docs/api/yard/HTM/PropositionService.md +66 -0
  22. data/docs/api/yard/HTM/QueryCache.md +88 -0
  23. data/docs/api/yard/HTM/RobotGroup.md +481 -0
  24. data/docs/api/yard/HTM/SqlBuilder.md +108 -0
  25. data/docs/api/yard/HTM/TagService.md +4 -0
  26. data/docs/api/yard/HTM/Telemetry/NullInstrument.md +13 -0
  27. data/docs/api/yard/HTM/Telemetry/NullMeter.md +15 -0
  28. data/docs/api/yard/HTM/Telemetry.md +109 -0
  29. data/docs/api/yard/HTM/WorkingMemoryChannel.md +176 -0
  30. data/docs/api/yard/HTM.md +8 -22
  31. data/docs/api/yard/index.csv +102 -25
  32. data/docs/api/yard-reference.md +8 -0
  33. data/docs/architecture/index.md +1 -1
  34. data/docs/assets/images/multi-provider-failover.svg +51 -0
  35. data/docs/assets/images/robot-group-architecture.svg +65 -0
  36. data/docs/database/README.md +3 -3
  37. data/docs/database/public.file_sources.svg +29 -21
  38. data/docs/database/public.node_tags.md +2 -0
  39. data/docs/database/public.node_tags.svg +53 -41
  40. data/docs/database/public.nodes.md +2 -0
  41. data/docs/database/public.nodes.svg +52 -40
  42. data/docs/database/public.robot_nodes.md +2 -0
  43. data/docs/database/public.robot_nodes.svg +30 -22
  44. data/docs/database/public.robots.svg +16 -12
  45. data/docs/database/public.tags.md +3 -0
  46. data/docs/database/public.tags.svg +41 -33
  47. data/docs/database/schema.json +66 -0
  48. data/docs/database/schema.svg +60 -48
  49. data/docs/development/index.md +14 -1
  50. data/docs/development/rake-tasks.md +1068 -0
  51. data/docs/getting-started/index.md +1 -1
  52. data/docs/getting-started/quick-start.md +144 -155
  53. data/docs/guides/adding-memories.md +2 -3
  54. data/docs/guides/context-assembly.md +185 -184
  55. data/docs/guides/getting-started.md +154 -148
  56. data/docs/guides/index.md +8 -1
  57. data/docs/guides/long-term-memory.md +60 -92
  58. data/docs/guides/mcp-server.md +617 -0
  59. data/docs/guides/multi-robot.md +249 -345
  60. data/docs/guides/recalling-memories.md +153 -163
  61. data/docs/guides/robot-groups.md +604 -0
  62. data/docs/guides/search-strategies.md +61 -58
  63. data/docs/guides/working-memory.md +103 -136
  64. data/docs/images/telemetry-architecture.svg +153 -0
  65. data/docs/index.md +30 -26
  66. data/docs/telemetry.md +391 -0
  67. data/examples/README.md +46 -1
  68. data/examples/cli_app/README.md +1 -1
  69. data/examples/cli_app/htm_cli.rb +1 -1
  70. data/examples/robot_groups/robot_worker.rb +1 -2
  71. data/examples/robot_groups/same_process.rb +1 -4
  72. data/examples/sinatra_app/app.rb +1 -1
  73. data/examples/telemetry/README.md +147 -0
  74. data/examples/telemetry/SETUP_README.md +169 -0
  75. data/examples/telemetry/demo.rb +498 -0
  76. data/examples/telemetry/grafana/dashboards/htm-metrics.json +457 -0
  77. data/lib/htm/configuration.rb +261 -70
  78. data/lib/htm/database.rb +46 -22
  79. data/lib/htm/embedding_service.rb +24 -14
  80. data/lib/htm/errors.rb +15 -1
  81. data/lib/htm/jobs/generate_embedding_job.rb +19 -0
  82. data/lib/htm/jobs/generate_propositions_job.rb +103 -0
  83. data/lib/htm/jobs/generate_tags_job.rb +24 -0
  84. data/lib/htm/loaders/markdown_chunker.rb +79 -0
  85. data/lib/htm/loaders/markdown_loader.rb +41 -15
  86. data/lib/htm/long_term_memory/fulltext_search.rb +138 -0
  87. data/lib/htm/long_term_memory/hybrid_search.rb +324 -0
  88. data/lib/htm/long_term_memory/node_operations.rb +209 -0
  89. data/lib/htm/long_term_memory/relevance_scorer.rb +355 -0
  90. data/lib/htm/long_term_memory/robot_operations.rb +34 -0
  91. data/lib/htm/long_term_memory/tag_operations.rb +428 -0
  92. data/lib/htm/long_term_memory/vector_search.rb +109 -0
  93. data/lib/htm/long_term_memory.rb +51 -1153
  94. data/lib/htm/models/node.rb +35 -2
  95. data/lib/htm/models/node_tag.rb +31 -0
  96. data/lib/htm/models/robot_node.rb +31 -0
  97. data/lib/htm/models/tag.rb +44 -0
  98. data/lib/htm/proposition_service.rb +169 -0
  99. data/lib/htm/query_cache.rb +214 -0
  100. data/lib/htm/robot_group.rb +721 -0
  101. data/lib/htm/sql_builder.rb +178 -0
  102. data/lib/htm/tag_service.rb +16 -6
  103. data/lib/htm/tasks.rb +8 -2
  104. data/lib/htm/telemetry.rb +224 -0
  105. data/lib/htm/version.rb +1 -1
  106. data/lib/htm/working_memory_channel.rb +250 -0
  107. data/lib/htm.rb +66 -3
  108. data/lib/tasks/doc.rake +1 -1
  109. data/lib/tasks/htm.rake +259 -13
  110. data/mkdocs.yml +98 -96
  111. metadata +55 -20
  112. data/.aigcm_msg +0 -1
  113. data/.claude/settings.local.json +0 -95
  114. data/CLAUDE.md +0 -603
  115. data/db/migrate/00009_add_working_memory_to_robot_nodes.rb +0 -12
  116. data/examples/cli_app/temp.log +0 -93
  117. data/examples/robot_groups/lib/robot_group.rb +0 -419
  118. data/examples/robot_groups/lib/working_memory_channel.rb +0 -140
  119. data/lib/htm/loaders/paragraph_chunker.rb +0 -112
  120. data/notes/ARCHITECTURE_REVIEW.md +0 -1167
  121. data/notes/IMPLEMENTATION_SUMMARY.md +0 -606
  122. data/notes/MULTI_FRAMEWORK_IMPLEMENTATION.md +0 -451
  123. data/notes/next_steps.md +0 -100
  124. data/notes/plan.md +0 -627
  125. data/notes/tag_ontology_enhancement_ideas.md +0 -222
  126. data/notes/timescaledb_removal_summary.md +0 -200
@@ -0,0 +1,147 @@
1
+ # HTM Telemetry Demo
2
+
3
+ This demo shows HTM metrics in a **live Grafana dashboard** using locally installed Prometheus and Grafana via Homebrew.
4
+
5
+ > **First time setup?** See [SETUP_README.md](SETUP_README.md) for detailed installation and configuration instructions.
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ # 1. Install Prometheus and Grafana via Homebrew
11
+ brew install prometheus grafana
12
+
13
+ # 2. Install required Ruby gems
14
+ gem install prometheus-client webrick
15
+
16
+ # 3. Run the demo
17
+ cd examples/telemetry
18
+ ruby demo.rb
19
+ ```
20
+
21
+ The demo will automatically:
22
+ - Check that Prometheus and Grafana are installed
23
+ - Start both services if not already running
24
+ - Configure Prometheus to scrape the demo's metrics
25
+ - Clean up any previous demo data (hard delete)
26
+ - Open Grafana in your browser
27
+ - Run HTM operations and export live metrics
28
+
29
+ ## What You'll See
30
+
31
+ Once running, open Grafana at http://localhost:3000 (login: admin/admin) and import the dashboard.
32
+
33
+ ### Dashboard Panels
34
+
35
+ | Panel | Description |
36
+ |-------|-------------|
37
+ | **Total Successful Jobs** | Count of completed embedding and tag jobs |
38
+ | **Total Failed Jobs** | Count of failed jobs |
39
+ | **Cache Hit Rate** | Percentage of queries served from cache |
40
+ | **LLM Job Latency (p95)** | 95th percentile latency for embedding/tag generation |
41
+ | **Search Latency by Strategy** | p95 latency for vector, fulltext, hybrid search |
42
+ | **Jobs per Minute** | Throughput by job type |
43
+ | **Cache Operations** | Hit/miss rate over time |
44
+
45
+ ## Importing the Dashboard
46
+
47
+ 1. Open Grafana: http://localhost:3000
48
+ 2. Go to: **Dashboards** → **Import**
49
+ 3. Click "Upload JSON file"
50
+ 4. Select: `examples/telemetry/grafana/dashboards/htm-metrics.json`
51
+ 5. Select your Prometheus datasource
52
+ 6. Click **Import**
53
+
54
+ If you don't have a Prometheus datasource configured:
55
+ 1. Go to: **Connections** → **Data sources** → **Add data source**
56
+ 2. Select **Prometheus**
57
+ 3. URL: `http://localhost:9090`
58
+ 4. Click **Save & test**
59
+
60
+ ## Architecture
61
+
62
+ ```
63
+ ┌─────────────┐ ┌─────────────────┐
64
+ │ demo.rb │ ──── scrapes ────▶ │ Prometheus │
65
+ │ (metrics │ :9394 │ :9090 │
66
+ │ server) │ └────────┬────────┘
67
+ └─────────────┘ │
68
+ │ PromQL queries
69
+ │ │
70
+ ▼ ▼
71
+ ┌─────────────┐ ┌─────────────────┐
72
+ │ HTM │ │ Grafana │
73
+ │ operations │ │ :3000 │
74
+ └─────────────┘ └─────────────────┘
75
+ ```
76
+
77
+ ## Available Metrics
78
+
79
+ | Metric | Type | Labels | Description |
80
+ |--------|------|--------|-------------|
81
+ | `htm_jobs_total` | Counter | job, status | Job execution count |
82
+ | `htm_embedding_latency_milliseconds` | Histogram | provider, status | Embedding time |
83
+ | `htm_tag_latency_milliseconds` | Histogram | provider, status | Tag extraction time |
84
+ | `htm_search_latency_milliseconds` | Histogram | strategy | Search operation time |
85
+ | `htm_cache_operations_total` | Counter | operation | Cache hit/miss count |
86
+
87
+ ## Endpoints
88
+
89
+ | Service | URL | Purpose |
90
+ |---------|-----|---------|
91
+ | Demo Metrics | http://localhost:9394/metrics | Raw Prometheus metrics |
92
+ | Prometheus | http://localhost:9090 | Metrics storage & queries |
93
+ | Grafana | http://localhost:3000 | Visualization (admin/admin) |
94
+
95
+ ## Stopping Services
96
+
97
+ The demo leaves Prometheus and Grafana running for convenience. To stop them:
98
+
99
+ ```bash
100
+ brew services stop prometheus grafana
101
+ ```
102
+
103
+ ## Troubleshooting
104
+
105
+ ### No metrics in Grafana
106
+
107
+ 1. Verify the demo is running and exposing metrics:
108
+ ```bash
109
+ curl http://localhost:9394/metrics
110
+ ```
111
+
112
+ 2. Check Prometheus is scraping:
113
+ - Open http://localhost:9090/targets
114
+ - Look for `htm-demo` target with state "UP"
115
+
116
+ 3. If target is missing, check Prometheus config:
117
+ ```bash
118
+ cat /opt/homebrew/etc/prometheus.yml
119
+ # Should include htm-demo job
120
+ ```
121
+
122
+ ### Port already in use
123
+
124
+ If port 9394 is busy, edit `demo.rb` and change `METRICS_PORT`.
125
+
126
+ ### Services won't start
127
+
128
+ ```bash
129
+ # Check service status
130
+ brew services list
131
+
132
+ # View logs
133
+ brew services info prometheus
134
+ brew services info grafana
135
+ ```
136
+
137
+ ## Files
138
+
139
+ ```
140
+ examples/telemetry/
141
+ ├── README.md # This file
142
+ ├── SETUP_README.md # Detailed setup instructions
143
+ ├── demo.rb # Main demo script
144
+ └── grafana/
145
+ └── dashboards/
146
+ └── htm-metrics.json # Import this into Grafana
147
+ ```
@@ -0,0 +1,169 @@
1
+ # HTM Telemetry Demo Setup
2
+
3
+ This guide walks you through setting up Prometheus and Grafana to visualize HTM metrics.
4
+
5
+ ## Prerequisites
6
+
7
+ ### 1. Install Prometheus and Grafana via Homebrew
8
+
9
+ ```bash
10
+ brew install prometheus grafana
11
+ ```
12
+
13
+ ### 2. Install Required Ruby Gems
14
+
15
+ ```bash
16
+ gem install prometheus-client webrick
17
+ ```
18
+
19
+ ## Starting the Services
20
+
21
+ ### Start Prometheus and Grafana
22
+
23
+ ```bash
24
+ brew services start prometheus
25
+ brew services start grafana
26
+ ```
27
+
28
+ Verify they're running:
29
+
30
+ ```bash
31
+ brew services list | grep -E 'prometheus|grafana'
32
+ ```
33
+
34
+ Both should show `started` status.
35
+
36
+ ## Configure Grafana
37
+
38
+ ### 1. Access Grafana
39
+
40
+ Open http://localhost:3000 in your browser.
41
+
42
+ **Default credentials:**
43
+ - Username: `admin`
44
+ - Password: `admin`
45
+
46
+ You'll be prompted to change the password on first login.
47
+
48
+ ### 2. Add Prometheus Data Source
49
+
50
+ 1. Go to **Connections** → **Data sources**
51
+ 2. Click **Add data source**
52
+ 3. Select **Prometheus**
53
+ 4. Enter URL: `http://localhost:9090`
54
+ 5. Click **Save & test**
55
+
56
+ You should see "Successfully queried the Prometheus API."
57
+
58
+ ### 3. Import the HTM Dashboard
59
+
60
+ 1. Go to **Dashboards** → **Import**
61
+ 2. Click **Upload JSON file**
62
+ 3. Select: `examples/telemetry/grafana/dashboards/htm-metrics.json`
63
+ 4. Select your Prometheus datasource from the dropdown
64
+ 5. Click **Import**
65
+
66
+ ## Running the Demo
67
+
68
+ ```bash
69
+ cd examples/telemetry
70
+ ./demo.rb
71
+ ```
72
+
73
+ The demo will:
74
+ - Verify Prometheus and Grafana are installed and running
75
+ - Configure Prometheus to scrape metrics from port 9394
76
+ - Clean up any previous demo data
77
+ - Open Grafana in your browser
78
+ - Run HTM operations in a loop, exporting metrics
79
+
80
+ ## Viewing Metrics
81
+
82
+ Once the demo is running, view the dashboard at:
83
+
84
+ http://localhost:3000/d/htm-metrics/htm-metrics
85
+
86
+ The dashboard shows:
87
+ - **Total Successful Jobs** - Embedding and tag job completions
88
+ - **Total Failed Jobs** - Job failures
89
+ - **Cache Hit Rate** - Query cache effectiveness
90
+ - **LLM Job Latency (p95)** - Embedding and tag generation times
91
+ - **Search Latency by Strategy** - Vector, fulltext, and hybrid search times
92
+ - **Jobs per Minute** - Throughput by job type
93
+ - **Cache Operations** - Hit/miss rate over time
94
+
95
+ ## Troubleshooting
96
+
97
+ ### Prometheus won't start
98
+
99
+ Check the error log:
100
+
101
+ ```bash
102
+ cat /opt/homebrew/var/log/prometheus.err.log
103
+ ```
104
+
105
+ Common issue: YAML syntax error in config. Verify the config:
106
+
107
+ ```bash
108
+ cat /opt/homebrew/etc/prometheus.yml
109
+ ```
110
+
111
+ The config should look like:
112
+
113
+ ```yaml
114
+ global:
115
+ scrape_interval: 15s
116
+
117
+ scrape_configs:
118
+ - job_name: "prometheus"
119
+ static_configs:
120
+ - targets: ["localhost:9090"]
121
+
122
+ - job_name: 'htm-demo'
123
+ scrape_interval: 5s
124
+ static_configs:
125
+ - targets: ['localhost:9394']
126
+ ```
127
+
128
+ ### Grafana can't connect to Prometheus
129
+
130
+ 1. Verify Prometheus is running:
131
+ ```bash
132
+ curl http://localhost:9090/api/v1/status/config
133
+ ```
134
+
135
+ 2. If connection refused, restart Prometheus:
136
+ ```bash
137
+ brew services restart prometheus
138
+ ```
139
+
140
+ ### No metrics in Grafana
141
+
142
+ 1. Verify the demo is running and exposing metrics:
143
+ ```bash
144
+ curl http://localhost:9394/metrics
145
+ ```
146
+
147
+ 2. Check Prometheus is scraping the target:
148
+ - Open http://localhost:9090/targets
149
+ - Look for `htm-demo` target with state "UP"
150
+
151
+ ### Port conflicts
152
+
153
+ If port 9394 is in use, edit `demo.rb` and change `METRICS_PORT`.
154
+
155
+ ## Stopping Services
156
+
157
+ The demo leaves services running for convenience. To stop them:
158
+
159
+ ```bash
160
+ brew services stop prometheus grafana
161
+ ```
162
+
163
+ ## Service Endpoints
164
+
165
+ | Service | URL | Purpose |
166
+ |---------|-----|---------|
167
+ | Demo Metrics | http://localhost:9394/metrics | Raw Prometheus metrics |
168
+ | Prometheus | http://localhost:9090 | Metrics storage & queries |
169
+ | Grafana | http://localhost:3000 | Visualization dashboard |