htm 0.0.18 → 0.0.20

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -1
  3. data/README.md +12 -0
  4. data/db/seeds.rb +1 -1
  5. data/docs/api/embedding-service.md +140 -110
  6. data/docs/api/yard/HTM/ActiveRecordConfig.md +6 -0
  7. data/docs/api/yard/HTM/Config.md +173 -0
  8. data/docs/api/yard/HTM/ConfigSection.md +28 -0
  9. data/docs/api/yard/HTM/Database.md +1 -1
  10. data/docs/api/yard/HTM/Railtie.md +2 -2
  11. data/docs/api/yard/HTM.md +0 -57
  12. data/docs/api/yard/index.csv +76 -61
  13. data/docs/api/yard-reference.md +2 -1
  14. data/docs/architecture/adrs/003-ollama-embeddings.md +45 -36
  15. data/docs/architecture/adrs/004-hive-mind.md +1 -1
  16. data/docs/architecture/adrs/008-robot-identification.md +1 -1
  17. data/docs/architecture/index.md +11 -9
  18. data/docs/architecture/overview.md +11 -7
  19. data/docs/assets/images/balanced-strategy-decay.svg +41 -0
  20. data/docs/assets/images/class-hierarchy.svg +1 -1
  21. data/docs/assets/images/eviction-priority.svg +43 -0
  22. data/docs/assets/images/exception-hierarchy.svg +2 -2
  23. data/docs/assets/images/hive-mind-shared-memory.svg +52 -0
  24. data/docs/assets/images/htm-architecture-overview.svg +3 -3
  25. data/docs/assets/images/htm-core-components.svg +4 -4
  26. data/docs/assets/images/htm-layered-architecture.svg +1 -1
  27. data/docs/assets/images/htm-memory-addition-flow.svg +2 -2
  28. data/docs/assets/images/htm-memory-recall-flow.svg +2 -2
  29. data/docs/assets/images/memory-topology.svg +53 -0
  30. data/docs/assets/images/two-tier-memory-architecture.svg +55 -0
  31. data/docs/development/setup.md +76 -44
  32. data/docs/examples/basic-usage.md +133 -0
  33. data/docs/examples/config-files.md +170 -0
  34. data/docs/examples/file-loading.md +208 -0
  35. data/docs/examples/index.md +116 -0
  36. data/docs/examples/llm-configuration.md +168 -0
  37. data/docs/examples/mcp-client.md +172 -0
  38. data/docs/examples/rails-integration.md +173 -0
  39. data/docs/examples/robot-groups.md +210 -0
  40. data/docs/examples/sinatra-integration.md +218 -0
  41. data/docs/examples/standalone-app.md +216 -0
  42. data/docs/examples/telemetry.md +224 -0
  43. data/docs/examples/timeframes.md +143 -0
  44. data/docs/getting-started/installation.md +97 -40
  45. data/docs/getting-started/quick-start.md +28 -11
  46. data/docs/guides/configuration.md +515 -0
  47. data/docs/guides/file-loading.md +322 -0
  48. data/docs/guides/getting-started.md +40 -9
  49. data/docs/guides/index.md +3 -3
  50. data/docs/guides/mcp-server.md +30 -12
  51. data/docs/guides/propositions.md +264 -0
  52. data/docs/guides/recalling-memories.md +4 -4
  53. data/docs/guides/search-strategies.md +3 -3
  54. data/docs/guides/tags.md +318 -0
  55. data/docs/guides/telemetry.md +229 -0
  56. data/docs/index.md +8 -16
  57. data/docs/{architecture → robots}/hive-mind.md +8 -111
  58. data/docs/robots/index.md +73 -0
  59. data/docs/{guides → robots}/multi-robot.md +3 -3
  60. data/docs/{guides → robots}/robot-groups.md +8 -7
  61. data/docs/{architecture → robots}/two-tier-memory.md +13 -149
  62. data/docs/robots/why-robots.md +85 -0
  63. data/lib/htm/config/defaults.yml +4 -4
  64. data/lib/htm/config.rb +2 -2
  65. data/lib/htm/job_adapter.rb +75 -1
  66. data/lib/htm/version.rb +1 -1
  67. data/lib/htm/workflows/remember_workflow.rb +212 -0
  68. data/lib/htm.rb +1 -0
  69. data/mkdocs.yml +33 -8
  70. metadata +60 -7
  71. data/docs/api/yard/HTM/Configuration.md +0 -240
  72. data/docs/telemetry.md +0 -391
data/docs/telemetry.md DELETED
@@ -1,391 +0,0 @@
1
- # Telemetry (OpenTelemetry Metrics)
2
-
3
- HTM includes optional OpenTelemetry-based metrics for production observability. This document provides detailed configuration and usage information.
4
-
5
- ## Overview
6
-
7
- HTM uses [OpenTelemetry](https://opentelemetry.io/) for metrics collection, the industry-standard observability framework. This provides:
8
-
9
- - **Universal compatibility**: Works with 50+ observability backends
10
- - **Zero vendor lock-in**: Emit standard OTLP, route anywhere
11
- - **Zero overhead when disabled**: Null object pattern ensures no performance impact
12
-
13
- ## Quick Start
14
-
15
- ### 1. Install Dependencies
16
-
17
- Add the OpenTelemetry gems to your Gemfile:
18
-
19
- ```ruby
20
- gem 'opentelemetry-sdk'
21
- gem 'opentelemetry-metrics-sdk'
22
- gem 'opentelemetry-exporter-otlp' # For OTLP export
23
- ```
24
-
25
- ### 2. Enable Telemetry
26
-
27
- ```ruby
28
- HTM.configure do |config|
29
- config.telemetry_enabled = true
30
- end
31
- ```
32
-
33
- Or via environment variable:
34
-
35
- ```bash
36
- export HTM_TELEMETRY_ENABLED="true"
37
- ```
38
-
39
- ### 3. Configure Destination
40
-
41
- Set standard OpenTelemetry environment variables:
42
-
43
- ```bash
44
- export OTEL_METRICS_EXPORTER="otlp"
45
- export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
46
- ```
47
-
48
- ## Configuration Options
49
-
50
- ### HTM Configuration
51
-
52
- | Option | Type | Default | Description |
53
- |--------|------|---------|-------------|
54
- | `telemetry_enabled` | Boolean | `false` | Enable/disable telemetry |
55
-
56
- ```ruby
57
- HTM.configure do |config|
58
- config.telemetry_enabled = true
59
- end
60
- ```
61
-
62
- ### Environment Variables
63
-
64
- #### HTM-specific
65
-
66
- | Variable | Default | Description |
67
- |----------|---------|-------------|
68
- | `HTM_TELEMETRY_ENABLED` | `false` | Enable telemetry (`true`/`false`) |
69
-
70
- #### OpenTelemetry Standard
71
-
72
- These are standard OpenTelemetry environment variables (not HTM-specific):
73
-
74
- | Variable | Example | Description |
75
- |----------|---------|-------------|
76
- | `OTEL_SERVICE_NAME` | `htm` | Service name in telemetry data |
77
- | `OTEL_METRICS_EXPORTER` | `otlp` | Metrics exporter type |
78
- | `OTEL_EXPORTER_OTLP_ENDPOINT` | `http://localhost:4318` | OTLP collector endpoint |
79
- | `OTEL_EXPORTER_OTLP_HEADERS` | `Authorization=Bearer token` | Headers for OTLP requests |
80
-
81
- ## Available Metrics
82
-
83
- ### htm.jobs (Counter)
84
-
85
- Counts job executions by type and outcome.
86
-
87
- **Attributes:**
88
- - `job`: Job type (`embedding`, `tags`)
89
- - `status`: Outcome (`success`, `error`, `circuit_open`)
90
-
91
- **Example queries (PromQL):**
92
- ```promql
93
- # Jobs per minute by type
94
- rate(htm_jobs_total[1m])
95
-
96
- # Error rate for embedding jobs
97
- rate(htm_jobs_total{job="embedding",status="error"}[5m])
98
- / rate(htm_jobs_total{job="embedding"}[5m])
99
- ```
100
-
101
- ### htm.embedding.latency (Histogram)
102
-
103
- Measures embedding generation time in milliseconds.
104
-
105
- **Attributes:**
106
- - `provider`: LLM provider (`ollama`, `openai`, etc.)
107
- - `status`: Outcome (`success`, `error`)
108
-
109
- **Example queries (PromQL):**
110
- ```promql
111
- # p95 embedding latency
112
- histogram_quantile(0.95, rate(htm_embedding_latency_bucket[5m]))
113
-
114
- # Average latency by provider
115
- rate(htm_embedding_latency_sum[5m]) / rate(htm_embedding_latency_count[5m])
116
- ```
117
-
118
- ### htm.tag.latency (Histogram)
119
-
120
- Measures tag extraction time in milliseconds.
121
-
122
- **Attributes:**
123
- - `provider`: LLM provider (`ollama`, `openai`, etc.)
124
- - `status`: Outcome (`success`, `error`)
125
-
126
- **Example queries (PromQL):**
127
- ```promql
128
- # p99 tag extraction latency
129
- histogram_quantile(0.99, rate(htm_tag_latency_bucket[5m]))
130
- ```
131
-
132
- ### htm.search.latency (Histogram)
133
-
134
- Measures search operation time in milliseconds.
135
-
136
- **Attributes:**
137
- - `strategy`: Search strategy (`vector`, `fulltext`, `hybrid`)
138
-
139
- **Example queries (PromQL):**
140
- ```promql
141
- # Search latency by strategy
142
- histogram_quantile(0.95, rate(htm_search_latency_bucket[5m])) by (strategy)
143
-
144
- # Hybrid search avg latency
145
- rate(htm_search_latency_sum{strategy="hybrid"}[5m])
146
- / rate(htm_search_latency_count{strategy="hybrid"}[5m])
147
- ```
148
-
149
- ### htm.cache.operations (Counter)
150
-
151
- Counts cache hits and misses.
152
-
153
- **Attributes:**
154
- - `operation`: Operation type (`hit`, `miss`)
155
-
156
- **Example queries (PromQL):**
157
- ```promql
158
- # Cache hit rate
159
- rate(htm_cache_operations_total{operation="hit"}[5m])
160
- / (rate(htm_cache_operations_total{operation="hit"}[5m])
161
- + rate(htm_cache_operations_total{operation="miss"}[5m]))
162
- ```
163
-
164
- ## Compatible Backends
165
-
166
- HTM metrics work with any OTLP-compatible platform:
167
-
168
- ### Open Source / Self-Hosted
169
-
170
- | Platform | OTLP Support | Notes |
171
- |----------|--------------|-------|
172
- | **Jaeger** | Native (v1.35+) | Distributed tracing with metrics |
173
- | **Prometheus** | Via receiver | Popular metrics platform |
174
- | **Grafana Tempo** | Native | Traces with metrics correlation |
175
- | **Grafana Mimir** | Native | Scalable Prometheus-compatible |
176
- | **SigNoz** | Native | Full-stack observability |
177
- | **Uptrace** | Native | Open source APM |
178
-
179
- ### Commercial / SaaS
180
-
181
- | Platform | OTLP Support | Notes |
182
- |----------|--------------|-------|
183
- | **Datadog** | Native | Full-stack observability |
184
- | **New Relic** | Native | APM and infrastructure |
185
- | **Honeycomb** | Native (preferred) | High-cardinality observability |
186
- | **Splunk APM** | Native | Enterprise observability |
187
- | **Dynatrace** | Native | AI-powered monitoring |
188
- | **AWS X-Ray** | Via ADOT | AWS native tracing |
189
- | **Google Cloud Trace** | Native | GCP native tracing |
190
- | **Azure Monitor** | Native | Azure native monitoring |
191
- | **Grafana Cloud** | Native | Managed Grafana stack |
192
-
193
- ## Setup Examples
194
-
195
- ### Jaeger (Local Development)
196
-
197
- ```bash
198
- # Start Jaeger with OTLP support
199
- docker run -d --name jaeger \
200
- -p 4318:4318 \
201
- -p 16686:16686 \
202
- jaegertracing/all-in-one:latest
203
-
204
- # Configure HTM
205
- export HTM_TELEMETRY_ENABLED="true"
206
- export OTEL_METRICS_EXPORTER="otlp"
207
- export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
208
- ```
209
-
210
- ### Prometheus (via OpenTelemetry Collector)
211
-
212
- ```yaml
213
- # otel-collector-config.yaml
214
- receivers:
215
- otlp:
216
- protocols:
217
- grpc:
218
- http:
219
-
220
- exporters:
221
- prometheus:
222
- endpoint: "0.0.0.0:8889"
223
-
224
- service:
225
- pipelines:
226
- metrics:
227
- receivers: [otlp]
228
- exporters: [prometheus]
229
- ```
230
-
231
- ```bash
232
- docker run -d \
233
- -p 4317:4317 \
234
- -p 4318:4318 \
235
- -p 8889:8889 \
236
- -v $(pwd)/otel-collector-config.yaml:/etc/otel-collector-config.yaml \
237
- otel/opentelemetry-collector:latest \
238
- --config=/etc/otel-collector-config.yaml
239
- ```
240
-
241
- ### Datadog
242
-
243
- ```bash
244
- export HTM_TELEMETRY_ENABLED="true"
245
- export OTEL_METRICS_EXPORTER="otlp"
246
- export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp.datadoghq.com"
247
- export OTEL_EXPORTER_OTLP_HEADERS="DD-API-KEY=your-api-key"
248
- ```
249
-
250
- ### Honeycomb
251
-
252
- ```bash
253
- export HTM_TELEMETRY_ENABLED="true"
254
- export OTEL_METRICS_EXPORTER="otlp"
255
- export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.honeycomb.io"
256
- export OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=your-api-key"
257
- ```
258
-
259
- ### New Relic
260
-
261
- ```bash
262
- export HTM_TELEMETRY_ENABLED="true"
263
- export OTEL_METRICS_EXPORTER="otlp"
264
- export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp.nr-data.net"
265
- export OTEL_EXPORTER_OTLP_HEADERS="api-key=your-license-key"
266
- ```
267
-
268
- ## Architecture
269
-
270
- ### Null Object Pattern
271
-
272
- HTM uses a null object pattern for telemetry. When disabled:
273
-
274
- ```ruby
275
- # This code runs identically whether telemetry is enabled or not
276
- HTM::Telemetry.job_counter.add(1, attributes: { 'job' => 'embedding' })
277
- ```
278
-
279
- When telemetry is disabled or the SDK is not installed:
280
- - `HTM::Telemetry.meter` returns a `NullMeter`
281
- - All instruments return `NullInstrument` instances
282
- - All operations (`add`, `record`) are no-ops returning `nil`
283
- - Zero memory allocation, zero CPU overhead
284
-
285
- ### Code Flow
286
-
287
- ![HTM Telemetry Architecture](images/telemetry-architecture.svg)
288
-
289
- ### Instrumentation Points
290
-
291
- HTM instruments these key operations:
292
-
293
- | Component | Metrics Recorded |
294
- |-----------|-----------------|
295
- | `GenerateEmbeddingJob` | `htm.jobs`, `htm.embedding.latency` |
296
- | `GenerateTagsJob` | `htm.jobs`, `htm.tag.latency` |
297
- | `VectorSearch#search` | `htm.search.latency` (strategy: vector) |
298
- | `FulltextSearch#search_fulltext` | `htm.search.latency` (strategy: fulltext) |
299
- | `HybridSearch#search_hybrid` | `htm.search.latency` (strategy: hybrid) |
300
- | `QueryCache#fetch` | `htm.cache.operations` |
301
-
302
- ## Testing
303
-
304
- When writing tests, reset telemetry state between tests:
305
-
306
- ```ruby
307
- def setup
308
- HTM::Telemetry.reset!
309
- HTM.configuration.telemetry_enabled = false
310
- end
311
-
312
- def teardown
313
- HTM::Telemetry.reset!
314
- end
315
- ```
316
-
317
- ### Verifying Metrics in Tests
318
-
319
- ```ruby
320
- def test_records_embedding_latency
321
- # Create a mock histogram
322
- recorded = []
323
- mock_histogram = Object.new
324
- mock_histogram.define_singleton_method(:record) do |value, **kwargs|
325
- recorded << { value: value, attributes: kwargs[:attributes] }
326
- end
327
-
328
- # Inject mock (requires test helper)
329
- HTM::Telemetry.instance_variable_set(:@embedding_latency, mock_histogram)
330
-
331
- # Run operation
332
- HTM::Jobs::GenerateEmbeddingJob.perform(node_id: node.id)
333
-
334
- # Verify
335
- assert recorded.any? { |r| r[:attributes]['status'] == 'success' }
336
- end
337
- ```
338
-
339
- ## Troubleshooting
340
-
341
- ### Metrics Not Appearing
342
-
343
- 1. **Check telemetry is enabled:**
344
- ```ruby
345
- puts HTM.configuration.telemetry_enabled # Should be true
346
- puts HTM::Telemetry.enabled? # Should be true
347
- ```
348
-
349
- 2. **Check SDK is installed:**
350
- ```ruby
351
- puts HTM::Telemetry.sdk_available? # Should be true
352
- ```
353
-
354
- 3. **Check environment variables:**
355
- ```bash
356
- echo $OTEL_METRICS_EXPORTER
357
- echo $OTEL_EXPORTER_OTLP_ENDPOINT
358
- ```
359
-
360
- 4. **Check collector is running:**
361
- ```bash
362
- curl http://localhost:4318/v1/metrics # Should not 404
363
- ```
364
-
365
- ### High Cardinality Issues
366
-
367
- Avoid high-cardinality attributes in metrics. HTM uses low-cardinality attributes by design:
368
-
369
- - `job`: 2-3 values (embedding, tags, propositions)
370
- - `status`: 3 values (success, error, circuit_open)
371
- - `provider`: ~10 values (ollama, openai, etc.)
372
- - `strategy`: 3 values (vector, fulltext, hybrid)
373
- - `operation`: 2 values (hit, miss)
374
-
375
- ### Performance Concerns
376
-
377
- With telemetry disabled (default), there is zero overhead:
378
- - No gem loading
379
- - No object allocation
380
- - No method calls beyond the null check
381
-
382
- With telemetry enabled, overhead is minimal:
383
- - ~1-5μs per metric recording
384
- - Memory for histogram buckets (~1KB per histogram)
385
-
386
- ## References
387
-
388
- - [OpenTelemetry Ruby SDK](https://github.com/open-telemetry/opentelemetry-ruby)
389
- - [OpenTelemetry Metrics SDK](https://github.com/open-telemetry/opentelemetry-ruby/tree/main/metrics_sdk)
390
- - [OpenTelemetry Specification](https://opentelemetry.io/docs/specs/otel/)
391
- - [OTLP Protocol](https://opentelemetry.io/docs/specs/otlp/)