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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +59 -1
- data/README.md +12 -0
- data/db/seeds.rb +1 -1
- 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/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 +30 -12
- 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/lib/htm/config/defaults.yml +4 -4
- data/lib/htm/config.rb +2 -2
- data/lib/htm/job_adapter.rb +75 -1
- data/lib/htm/version.rb +1 -1
- data/lib/htm/workflows/remember_workflow.rb +212 -0
- data/lib/htm.rb +1 -0
- data/mkdocs.yml +33 -8
- metadata +60 -7
- data/docs/api/yard/HTM/Configuration.md +0 -240
- data/docs/telemetry.md +0 -391
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Standalone Application Example
|
|
2
|
+
|
|
3
|
+
A simple Ruby application demonstrating HTM's core features with full RubyLLM integration.
|
|
4
|
+
|
|
5
|
+
**Source:** [`examples/example_app/`](https://github.com/madbomber/htm/tree/main/examples/example_app)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The standalone example demonstrates:
|
|
10
|
+
|
|
11
|
+
- HTM initialization and configuration
|
|
12
|
+
- RubyLLM integration for embeddings and tags
|
|
13
|
+
- Remembering information with automatic processing
|
|
14
|
+
- Comparing search strategies (fulltext, vector, hybrid)
|
|
15
|
+
- Background job processing for embeddings and tags
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# PostgreSQL with pgvector
|
|
21
|
+
export HTM_DATABASE__URL="postgresql://user@localhost:5432/htm_development"
|
|
22
|
+
|
|
23
|
+
# Ollama for embeddings and tags
|
|
24
|
+
ollama pull nomic-embed-text
|
|
25
|
+
ollama pull gemma3:latest
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Running
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
cd examples/example_app
|
|
32
|
+
ruby app.rb
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Code Walkthrough
|
|
36
|
+
|
|
37
|
+
### Configuration
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
require_relative '../../lib/htm'
|
|
41
|
+
require 'ruby_llm'
|
|
42
|
+
|
|
43
|
+
HTM.configure do |c|
|
|
44
|
+
# Logger
|
|
45
|
+
c.logger = Logger.new($stdout)
|
|
46
|
+
c.logger.level = Logger::INFO
|
|
47
|
+
|
|
48
|
+
# Embedding generation (using Ollama)
|
|
49
|
+
c.embedding.provider = :ollama
|
|
50
|
+
c.embedding.model = 'nomic-embed-text'
|
|
51
|
+
c.embedding.dimensions = 768
|
|
52
|
+
c.providers.ollama.url = ENV['OLLAMA_URL'] || 'http://localhost:11434'
|
|
53
|
+
|
|
54
|
+
# Tag extraction (using Ollama)
|
|
55
|
+
c.tag.provider = :ollama
|
|
56
|
+
c.tag.model = 'gemma3'
|
|
57
|
+
|
|
58
|
+
# Apply default implementations
|
|
59
|
+
c.reset_to_defaults
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Creating an HTM Instance
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
htm = HTM.new(robot_name: "Example App Robot")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Remembering Information
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
# Store conversation messages
|
|
73
|
+
node_1 = htm.remember(
|
|
74
|
+
"HTM provides intelligent memory management for LLM-based applications"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
node_2 = htm.remember(
|
|
78
|
+
"The two-tier architecture includes working memory and long-term storage"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
node_3 = htm.remember(
|
|
82
|
+
"Can you explain how the working memory eviction algorithm works?"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
puts "Remembered 3 messages (nodes #{node_1}, #{node_2}, #{node_3})"
|
|
86
|
+
puts "Embeddings and tags are being generated asynchronously..."
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Waiting for Background Jobs
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
# Tag generation with LLM can take 10-15 seconds
|
|
93
|
+
puts "Waiting for background jobs to complete..."
|
|
94
|
+
sleep 15
|
|
95
|
+
|
|
96
|
+
# Check generated tags
|
|
97
|
+
[node_1, node_2, node_3].each do |node_id|
|
|
98
|
+
node = HTM::Models::Node.includes(:tags).find(node_id)
|
|
99
|
+
puts "Node #{node_id}: #{node.tags.map(&:name).join(', ')}"
|
|
100
|
+
end
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Comparing Search Strategies
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
# 1. Full-text search (doesn't require embeddings)
|
|
107
|
+
fulltext_memories = htm.recall(
|
|
108
|
+
"memory",
|
|
109
|
+
timeframe: (Time.now - 3600)..Time.now,
|
|
110
|
+
strategy: :fulltext,
|
|
111
|
+
limit: 3
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# 2. Vector search (requires embeddings)
|
|
115
|
+
vector_memories = htm.recall(
|
|
116
|
+
"intelligent memory system",
|
|
117
|
+
timeframe: (Time.now - 3600)..Time.now,
|
|
118
|
+
strategy: :vector,
|
|
119
|
+
limit: 3
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
# 3. Hybrid search (combines both)
|
|
123
|
+
hybrid_memories = htm.recall(
|
|
124
|
+
"working memory architecture",
|
|
125
|
+
timeframe: (Time.now - 3600)..Time.now,
|
|
126
|
+
strategy: :hybrid,
|
|
127
|
+
limit: 3
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Example Output
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
=== HTM Full-Featured Example Application ===
|
|
135
|
+
|
|
136
|
+
Checking database connection...
|
|
137
|
+
✓ Database configured: htm_development @ localhost
|
|
138
|
+
|
|
139
|
+
Configuring HTM with RubyLLM...
|
|
140
|
+
✓ Configured with Ollama:
|
|
141
|
+
- Embeddings: nomic-embed-text
|
|
142
|
+
- Tags: gemma3
|
|
143
|
+
- Ollama URL: http://localhost:11434
|
|
144
|
+
|
|
145
|
+
Checking Ollama connection...
|
|
146
|
+
✓ Ollama is running
|
|
147
|
+
|
|
148
|
+
Initializing HTM...
|
|
149
|
+
|
|
150
|
+
Remembering example conversation...
|
|
151
|
+
✓ Remembered 3 conversation messages (nodes 1, 2, 3)
|
|
152
|
+
|
|
153
|
+
Waiting for background jobs to complete (15 seconds)...
|
|
154
|
+
|
|
155
|
+
--- Generated Tags ---
|
|
156
|
+
Node 1:
|
|
157
|
+
- ai:memory-management
|
|
158
|
+
- software:architecture
|
|
159
|
+
Node 2:
|
|
160
|
+
- architecture:two-tier
|
|
161
|
+
- memory:working
|
|
162
|
+
- memory:long-term
|
|
163
|
+
Node 3:
|
|
164
|
+
- algorithm:eviction
|
|
165
|
+
- memory:working
|
|
166
|
+
|
|
167
|
+
--- Embedding Status ---
|
|
168
|
+
Node 1: ✓ Generated (768 dimensions)
|
|
169
|
+
Node 2: ✓ Generated (768 dimensions)
|
|
170
|
+
Node 3: ✓ Generated (768 dimensions)
|
|
171
|
+
|
|
172
|
+
--- Recall Strategies Comparison ---
|
|
173
|
+
|
|
174
|
+
1. Full-text Search for 'memory':
|
|
175
|
+
Found 3 memories:
|
|
176
|
+
- HTM provides intelligent memory management for LLM-based...
|
|
177
|
+
- The two-tier architecture includes working memory and...
|
|
178
|
+
- Can you explain how the working memory eviction algorit...
|
|
179
|
+
|
|
180
|
+
2. Vector Search for 'intelligent memory system':
|
|
181
|
+
Found 3 memories:
|
|
182
|
+
- HTM provides intelligent memory management for LLM-based...
|
|
183
|
+
- The two-tier architecture includes working memory and...
|
|
184
|
+
- Can you explain how the working memory eviction algorit...
|
|
185
|
+
|
|
186
|
+
3. Hybrid Search for 'working memory architecture':
|
|
187
|
+
Found 3 memories:
|
|
188
|
+
- The two-tier architecture includes working memory and...
|
|
189
|
+
- Can you explain how the working memory eviction algorit...
|
|
190
|
+
- HTM provides intelligent memory management for LLM-based...
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## HTM Core API Summary
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
# 1. Remember - Store information
|
|
197
|
+
htm.remember(content, tags: [], metadata: {})
|
|
198
|
+
# - Stores in long-term memory
|
|
199
|
+
# - Adds to working memory for immediate use
|
|
200
|
+
# - Generates embeddings and tags in background
|
|
201
|
+
|
|
202
|
+
# 2. Recall - Retrieve relevant memories
|
|
203
|
+
htm.recall(topic, timeframe:, strategy:, limit:)
|
|
204
|
+
# - Strategies: :fulltext, :vector, :hybrid
|
|
205
|
+
# - Results added to working memory
|
|
206
|
+
|
|
207
|
+
# 3. Forget - Delete a memory
|
|
208
|
+
htm.forget(node_id) # Soft delete (default)
|
|
209
|
+
htm.forget(node_id, soft: false, confirm: :confirmed) # Permanent
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## See Also
|
|
213
|
+
|
|
214
|
+
- [Basic Usage Example](basic-usage.md)
|
|
215
|
+
- [LLM Configuration Example](llm-configuration.md)
|
|
216
|
+
- [Search Strategies Guide](../guides/search-strategies.md)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Telemetry Demo
|
|
2
|
+
|
|
3
|
+
This example demonstrates HTM's OpenTelemetry-based metrics with live Prometheus and Grafana visualization.
|
|
4
|
+
|
|
5
|
+
**Source:** [`examples/telemetry/demo.rb`](https://github.com/madbomber/htm/blob/main/examples/telemetry/demo.rb)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The telemetry demo shows:
|
|
10
|
+
|
|
11
|
+
- Setting up Prometheus metrics collection
|
|
12
|
+
- Visualizing metrics in Grafana dashboards
|
|
13
|
+
- Available HTM metrics (jobs, latency, cache)
|
|
14
|
+
- Real-time monitoring during HTM operations
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
### macOS (Homebrew)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Install Prometheus and Grafana
|
|
22
|
+
brew install prometheus grafana
|
|
23
|
+
|
|
24
|
+
# Install Ruby gems (system gems, not bundled)
|
|
25
|
+
gem install prometheus-client webrick
|
|
26
|
+
|
|
27
|
+
# Set database connection
|
|
28
|
+
export HTM_DATABASE__URL="postgresql://user@localhost:5432/htm_development"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Running the Demo
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
cd examples/telemetry
|
|
35
|
+
ruby demo.rb
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The demo will:
|
|
39
|
+
|
|
40
|
+
1. Check and start Prometheus/Grafana services
|
|
41
|
+
2. Configure Prometheus to scrape HTM metrics
|
|
42
|
+
3. Start a metrics server on port 9394
|
|
43
|
+
4. Run HTM operations in a loop
|
|
44
|
+
5. Open Grafana in your browser
|
|
45
|
+
|
|
46
|
+
## Available Metrics
|
|
47
|
+
|
|
48
|
+
| Metric | Type | Labels | Description |
|
|
49
|
+
|--------|------|--------|-------------|
|
|
50
|
+
| `htm_jobs_total` | Counter | job, status | Job execution counts |
|
|
51
|
+
| `htm_embedding_latency_milliseconds` | Histogram | provider, status | Embedding generation time |
|
|
52
|
+
| `htm_tag_latency_milliseconds` | Histogram | provider, status | Tag extraction time |
|
|
53
|
+
| `htm_search_latency_milliseconds` | Histogram | strategy | Search operation time |
|
|
54
|
+
| `htm_cache_operations_total` | Counter | operation | Cache hit/miss counts |
|
|
55
|
+
|
|
56
|
+
## Enabling Telemetry in Your App
|
|
57
|
+
|
|
58
|
+
### Configuration
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
HTM.configure do |config|
|
|
62
|
+
config.telemetry_enabled = true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Or via environment variable
|
|
66
|
+
# HTM_TELEMETRY_ENABLED=true
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Required Gems
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
# Add to your Gemfile
|
|
73
|
+
gem 'opentelemetry-sdk'
|
|
74
|
+
gem 'opentelemetry-metrics-sdk'
|
|
75
|
+
gem 'opentelemetry-exporter-otlp' # For OTLP export
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### OpenTelemetry Configuration
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Export to OTLP-compatible backend
|
|
82
|
+
export OTEL_METRICS_EXPORTER="otlp"
|
|
83
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Grafana Dashboard
|
|
87
|
+
|
|
88
|
+
The demo includes a pre-configured Grafana dashboard:
|
|
89
|
+
|
|
90
|
+
**Location:** `examples/telemetry/grafana/dashboards/htm-metrics.json`
|
|
91
|
+
|
|
92
|
+
### Import Dashboard
|
|
93
|
+
|
|
94
|
+
1. Open Grafana at http://localhost:3000
|
|
95
|
+
2. Default login: admin / admin
|
|
96
|
+
3. Go to Dashboards > Import
|
|
97
|
+
4. Upload the JSON file
|
|
98
|
+
|
|
99
|
+
### Dashboard Panels
|
|
100
|
+
|
|
101
|
+
- **Job Success Rate**: Percentage of successful jobs
|
|
102
|
+
- **Embedding Latency**: P50, P95, P99 latencies
|
|
103
|
+
- **Tag Latency**: Tag extraction performance
|
|
104
|
+
- **Search Performance**: Query latency by strategy
|
|
105
|
+
- **Cache Hit Rate**: Cache effectiveness
|
|
106
|
+
|
|
107
|
+
## Architecture
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
┌─────────────────────────────────────────────────────────┐
|
|
111
|
+
│ HTM Application │
|
|
112
|
+
│ │
|
|
113
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
114
|
+
│ │ remember │ │ recall │ │ jobs │ │
|
|
115
|
+
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
|
|
116
|
+
│ │ │ │ │
|
|
117
|
+
│ └────────────────┼────────────────┘ │
|
|
118
|
+
│ │ │
|
|
119
|
+
│ ┌───────────▼───────────┐ │
|
|
120
|
+
│ │ Telemetry Collector │ │
|
|
121
|
+
│ └───────────┬───────────┘ │
|
|
122
|
+
└──────────────────────────┼──────────────────────────────┘
|
|
123
|
+
│
|
|
124
|
+
┌────────────▼────────────┐
|
|
125
|
+
│ /metrics endpoint │
|
|
126
|
+
│ (port 9394) │
|
|
127
|
+
└────────────┬────────────┘
|
|
128
|
+
│
|
|
129
|
+
┌────────────▼────────────┐
|
|
130
|
+
│ Prometheus │
|
|
131
|
+
│ (scrapes /metrics) │
|
|
132
|
+
└────────────┬────────────┘
|
|
133
|
+
│
|
|
134
|
+
┌────────────▼────────────┐
|
|
135
|
+
│ Grafana │
|
|
136
|
+
│ (visualization) │
|
|
137
|
+
└─────────────────────────┘
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Compatible Backends
|
|
141
|
+
|
|
142
|
+
HTM telemetry is OTLP-compatible and works with:
|
|
143
|
+
|
|
144
|
+
### Open Source
|
|
145
|
+
|
|
146
|
+
- Jaeger
|
|
147
|
+
- Prometheus + Grafana
|
|
148
|
+
- Grafana Tempo/Mimir
|
|
149
|
+
- SigNoz
|
|
150
|
+
- Uptrace
|
|
151
|
+
|
|
152
|
+
### Commercial
|
|
153
|
+
|
|
154
|
+
- Datadog
|
|
155
|
+
- New Relic
|
|
156
|
+
- Honeycomb
|
|
157
|
+
- Splunk
|
|
158
|
+
- Dynatrace
|
|
159
|
+
- AWS X-Ray
|
|
160
|
+
- Google Cloud Trace
|
|
161
|
+
- Azure Monitor
|
|
162
|
+
|
|
163
|
+
## Demo Output
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
╔══════════════════════════════════════════════════════════════════╗
|
|
167
|
+
║ HTM Telemetry Demo - Live Grafana Visualization ║
|
|
168
|
+
╚══════════════════════════════════════════════════════════════════╝
|
|
169
|
+
|
|
170
|
+
Checking Ruby dependencies...
|
|
171
|
+
[OK] prometheus-client gem
|
|
172
|
+
[OK] webrick gem
|
|
173
|
+
|
|
174
|
+
Loading HTM...
|
|
175
|
+
[OK] HTM 0.1.0
|
|
176
|
+
|
|
177
|
+
Starting services...
|
|
178
|
+
prometheus: already running
|
|
179
|
+
grafana: already running
|
|
180
|
+
|
|
181
|
+
Starting metrics server on port 9394...
|
|
182
|
+
[OK] Metrics available at http://localhost:9394/metrics
|
|
183
|
+
|
|
184
|
+
Opening Grafana...
|
|
185
|
+
Default login: admin / admin
|
|
186
|
+
|
|
187
|
+
============================================================
|
|
188
|
+
Starting demo loop...
|
|
189
|
+
Metrics: http://localhost:9394/metrics
|
|
190
|
+
Grafana: http://localhost:3000
|
|
191
|
+
============================================================
|
|
192
|
+
|
|
193
|
+
Press Ctrl+C to stop
|
|
194
|
+
|
|
195
|
+
[10:30:15] Iteration 1
|
|
196
|
+
> Remember: PostgreSQL supports vector similarity search... node 42
|
|
197
|
+
> Recall (fulltext): 'database ' -> 3 results (12ms)
|
|
198
|
+
> Recall (vector ): 'database ' -> 3 results (45ms)
|
|
199
|
+
> Recall (hybrid ): 'database ' -> 3 results (52ms)
|
|
200
|
+
Metrics exported to Prometheus
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Cleanup
|
|
204
|
+
|
|
205
|
+
The demo prompts to stop services on exit:
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
Stop Prometheus and Grafana services? (y/N): y
|
|
209
|
+
Stopping prometheus... done
|
|
210
|
+
Stopping grafana... done
|
|
211
|
+
Services stopped.
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Or stop manually:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
brew services stop prometheus grafana
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## See Also
|
|
221
|
+
|
|
222
|
+
- [Telemetry Guide](../guides/telemetry.md)
|
|
223
|
+
- [Observability API](../api/yard/HTM/Observability.md)
|
|
224
|
+
- [OpenTelemetry Ruby](https://opentelemetry.io/docs/languages/ruby/)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Timeframe Demo
|
|
2
|
+
|
|
3
|
+
This example demonstrates the flexible timeframe options for filtering memories by time in HTM recall queries.
|
|
4
|
+
|
|
5
|
+
**Source:** [`examples/timeframe_demo.rb`](https://github.com/madbomber/htm/blob/main/examples/timeframe_demo.rb)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
HTM supports natural language time expressions for filtering memories. This example shows:
|
|
10
|
+
|
|
11
|
+
- Date and Time object filtering
|
|
12
|
+
- Range-based precise filtering
|
|
13
|
+
- Natural language expressions ("yesterday", "last week")
|
|
14
|
+
- Automatic timeframe extraction from queries (`:auto`)
|
|
15
|
+
- Multiple time windows
|
|
16
|
+
|
|
17
|
+
## Running the Example
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export HTM_DATABASE__URL="postgresql://user@localhost:5432/htm_development"
|
|
21
|
+
ruby examples/timeframe_demo.rb
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Timeframe Options
|
|
25
|
+
|
|
26
|
+
### No Filter (nil)
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
# Search all memories regardless of time
|
|
30
|
+
htm.recall("PostgreSQL", timeframe: nil)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Date Object
|
|
34
|
+
|
|
35
|
+
A Date is expanded to cover the entire day (00:00:00 to 23:59:59):
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
htm.recall("meetings", timeframe: Date.today)
|
|
39
|
+
htm.recall("notes", timeframe: Date.new(2025, 11, 15))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Range (Precise Control)
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
start_time = Time.now - (7 * 24 * 60 * 60) # 7 days ago
|
|
46
|
+
end_time = Time.now
|
|
47
|
+
|
|
48
|
+
htm.recall("updates", timeframe: start_time..end_time)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Natural Language
|
|
52
|
+
|
|
53
|
+
HTM uses the Chronic gem for parsing natural language time expressions:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
htm.recall("notes", timeframe: "yesterday")
|
|
57
|
+
htm.recall("discussions", timeframe: "last week")
|
|
58
|
+
htm.recall("decisions", timeframe: "last month")
|
|
59
|
+
htm.recall("tasks", timeframe: "this morning")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Supported Expressions
|
|
63
|
+
|
|
64
|
+
| Expression | Meaning |
|
|
65
|
+
|------------|---------|
|
|
66
|
+
| `"yesterday"` | Previous day |
|
|
67
|
+
| `"last week"` | Previous 7 days |
|
|
68
|
+
| `"last month"` | Previous 30 days |
|
|
69
|
+
| `"today"` | Current day |
|
|
70
|
+
| `"this morning"` | Today before noon |
|
|
71
|
+
| `"few days ago"` | 3 days ago |
|
|
72
|
+
| `"last weekend"` | Previous Saturday-Monday |
|
|
73
|
+
| `"2 weekends ago"` | Two weekends back |
|
|
74
|
+
|
|
75
|
+
### Automatic Extraction (`:auto`)
|
|
76
|
+
|
|
77
|
+
Extract timeframe from the query text automatically:
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
# The timeframe is extracted and removed from the search query
|
|
81
|
+
htm.recall("what did we discuss last week about databases", timeframe: :auto)
|
|
82
|
+
# Searches for: "what did we discuss about databases"
|
|
83
|
+
# Timeframe: last week's date range
|
|
84
|
+
|
|
85
|
+
htm.recall("show me notes from yesterday about PostgreSQL", timeframe: :auto)
|
|
86
|
+
# Searches for: "show me notes about PostgreSQL"
|
|
87
|
+
# Timeframe: yesterday's date range
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Multiple Time Windows
|
|
91
|
+
|
|
92
|
+
Search across multiple date ranges (OR'd together):
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
today = Date.today
|
|
96
|
+
last_friday = today - ((today.wday + 2) % 7)
|
|
97
|
+
two_fridays_ago = last_friday - 7
|
|
98
|
+
|
|
99
|
+
htm.recall("standup notes", timeframe: [last_friday, two_fridays_ago])
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
SQL equivalent:
|
|
103
|
+
```sql
|
|
104
|
+
WHERE (created_at BETWEEN '...' AND '...')
|
|
105
|
+
OR (created_at BETWEEN '...' AND '...')
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Configuration
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
HTM.configure do |config|
|
|
112
|
+
# Configure week start for "last weekend" calculations
|
|
113
|
+
config.week_start = :sunday # or :monday
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Summary Table
|
|
118
|
+
|
|
119
|
+
| Input Type | Behavior |
|
|
120
|
+
|------------|----------|
|
|
121
|
+
| `nil` | No time filter |
|
|
122
|
+
| `Date` | Entire day (00:00:00 to 23:59:59) |
|
|
123
|
+
| `DateTime` | Entire day (same as Date) |
|
|
124
|
+
| `Time` | Entire day (same as Date) |
|
|
125
|
+
| `Range` | Exact time window |
|
|
126
|
+
| `String` | Natural language parsing via Chronic |
|
|
127
|
+
| `:auto` | Extract from query, return cleaned query |
|
|
128
|
+
| `Array<Range>` | Multiple time windows OR'd together |
|
|
129
|
+
|
|
130
|
+
## Special Keywords
|
|
131
|
+
|
|
132
|
+
| Keyword | Meaning |
|
|
133
|
+
|---------|---------|
|
|
134
|
+
| `few`, `a few`, `several` | Maps to 3 |
|
|
135
|
+
| `recently`, `recent` | Last 3 days |
|
|
136
|
+
| `weekend before last` | 2 weekends ago (Sat-Mon) |
|
|
137
|
+
| `N weekends ago` | N weekends back (Sat-Mon range) |
|
|
138
|
+
|
|
139
|
+
## See Also
|
|
140
|
+
|
|
141
|
+
- [Recalling Memories Guide](../guides/recalling-memories.md)
|
|
142
|
+
- [Search Strategies Guide](../guides/search-strategies.md)
|
|
143
|
+
- [Timeframe API Reference](../api/yard/HTM/Timeframe.md)
|