htm 0.0.1
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 +7 -0
- data/.architecture/decisions/adrs/001-use-postgresql-timescaledb-storage.md +227 -0
- data/.architecture/decisions/adrs/002-two-tier-memory-architecture.md +322 -0
- data/.architecture/decisions/adrs/003-ollama-default-embedding-provider.md +339 -0
- data/.architecture/decisions/adrs/004-multi-robot-shared-memory-hive-mind.md +374 -0
- data/.architecture/decisions/adrs/005-rag-based-retrieval-with-hybrid-search.md +443 -0
- data/.architecture/decisions/adrs/006-context-assembly-strategies.md +444 -0
- data/.architecture/decisions/adrs/007-working-memory-eviction-strategy.md +461 -0
- data/.architecture/decisions/adrs/008-robot-identification-system.md +550 -0
- data/.architecture/decisions/adrs/009-never-forget-explicit-deletion-only.md +570 -0
- data/.architecture/decisions/adrs/010-redis-working-memory-rejected.md +323 -0
- data/.architecture/decisions/adrs/011-database-side-embedding-generation-with-pgai.md +585 -0
- data/.architecture/decisions/adrs/012-llm-driven-ontology-topic-extraction.md +583 -0
- data/.architecture/decisions/adrs/013-activerecord-orm-and-many-to-many-tagging.md +299 -0
- data/.architecture/decisions/adrs/014-client-side-embedding-generation-workflow.md +569 -0
- data/.architecture/decisions/adrs/015-hierarchical-tag-ontology-and-llm-extraction.md +701 -0
- data/.architecture/decisions/adrs/016-async-embedding-and-tag-generation.md +694 -0
- data/.architecture/members.yml +144 -0
- data/.architecture/reviews/2025-10-29-llm-configuration-and-async-processing-review.md +1137 -0
- data/.architecture/reviews/initial-system-analysis.md +330 -0
- data/.envrc +32 -0
- data/.irbrc +145 -0
- data/CHANGELOG.md +150 -0
- data/COMMITS.md +196 -0
- data/LICENSE +21 -0
- data/README.md +1347 -0
- data/Rakefile +51 -0
- data/SETUP.md +268 -0
- data/config/database.yml +67 -0
- data/db/migrate/20250101000001_enable_extensions.rb +14 -0
- data/db/migrate/20250101000002_create_robots.rb +14 -0
- data/db/migrate/20250101000003_create_nodes.rb +42 -0
- data/db/migrate/20250101000005_create_tags.rb +38 -0
- data/db/migrate/20250101000007_add_node_vector_indexes.rb +30 -0
- data/db/schema.sql +473 -0
- data/db/seed_data/README.md +100 -0
- data/db/seed_data/presidents.md +136 -0
- data/db/seed_data/states.md +151 -0
- data/db/seeds.rb +208 -0
- data/dbdoc/README.md +173 -0
- data/dbdoc/public.node_stats.md +48 -0
- data/dbdoc/public.node_stats.svg +41 -0
- data/dbdoc/public.node_tags.md +40 -0
- data/dbdoc/public.node_tags.svg +112 -0
- data/dbdoc/public.nodes.md +54 -0
- data/dbdoc/public.nodes.svg +118 -0
- data/dbdoc/public.nodes_tags.md +39 -0
- data/dbdoc/public.nodes_tags.svg +112 -0
- data/dbdoc/public.ontology_structure.md +48 -0
- data/dbdoc/public.ontology_structure.svg +38 -0
- data/dbdoc/public.operations_log.md +42 -0
- data/dbdoc/public.operations_log.svg +130 -0
- data/dbdoc/public.relationships.md +39 -0
- data/dbdoc/public.relationships.svg +41 -0
- data/dbdoc/public.robot_activity.md +46 -0
- data/dbdoc/public.robot_activity.svg +35 -0
- data/dbdoc/public.robots.md +35 -0
- data/dbdoc/public.robots.svg +90 -0
- data/dbdoc/public.schema_migrations.md +29 -0
- data/dbdoc/public.schema_migrations.svg +26 -0
- data/dbdoc/public.tags.md +35 -0
- data/dbdoc/public.tags.svg +60 -0
- data/dbdoc/public.topic_relationships.md +45 -0
- data/dbdoc/public.topic_relationships.svg +32 -0
- data/dbdoc/schema.json +1437 -0
- data/dbdoc/schema.svg +154 -0
- data/docs/api/database.md +806 -0
- data/docs/api/embedding-service.md +532 -0
- data/docs/api/htm.md +797 -0
- data/docs/api/index.md +259 -0
- data/docs/api/long-term-memory.md +1096 -0
- data/docs/api/working-memory.md +665 -0
- data/docs/architecture/adrs/001-postgresql-timescaledb.md +314 -0
- data/docs/architecture/adrs/002-two-tier-memory.md +411 -0
- data/docs/architecture/adrs/003-ollama-embeddings.md +421 -0
- data/docs/architecture/adrs/004-hive-mind.md +437 -0
- data/docs/architecture/adrs/005-rag-retrieval.md +531 -0
- data/docs/architecture/adrs/006-context-assembly.md +496 -0
- data/docs/architecture/adrs/007-eviction-strategy.md +645 -0
- data/docs/architecture/adrs/008-robot-identification.md +625 -0
- data/docs/architecture/adrs/009-never-forget.md +648 -0
- data/docs/architecture/adrs/010-redis-working-memory-rejected.md +323 -0
- data/docs/architecture/adrs/011-pgai-integration.md +494 -0
- data/docs/architecture/adrs/index.md +215 -0
- data/docs/architecture/hive-mind.md +736 -0
- data/docs/architecture/index.md +351 -0
- data/docs/architecture/overview.md +538 -0
- data/docs/architecture/two-tier-memory.md +873 -0
- data/docs/assets/css/custom.css +83 -0
- data/docs/assets/images/htm-core-components.svg +63 -0
- data/docs/assets/images/htm-database-schema.svg +93 -0
- data/docs/assets/images/htm-hive-mind-architecture.svg +125 -0
- data/docs/assets/images/htm-importance-scoring-framework.svg +83 -0
- data/docs/assets/images/htm-layered-architecture.svg +71 -0
- data/docs/assets/images/htm-long-term-memory-architecture.svg +115 -0
- data/docs/assets/images/htm-working-memory-architecture.svg +120 -0
- data/docs/assets/images/htm.jpg +0 -0
- data/docs/assets/images/htm_demo.gif +0 -0
- data/docs/assets/js/mathjax.js +18 -0
- data/docs/assets/videos/htm_video.mp4 +0 -0
- data/docs/database_rake_tasks.md +322 -0
- data/docs/development/contributing.md +787 -0
- data/docs/development/index.md +336 -0
- data/docs/development/schema.md +596 -0
- data/docs/development/setup.md +719 -0
- data/docs/development/testing.md +819 -0
- data/docs/guides/adding-memories.md +824 -0
- data/docs/guides/context-assembly.md +1009 -0
- data/docs/guides/getting-started.md +577 -0
- data/docs/guides/index.md +118 -0
- data/docs/guides/long-term-memory.md +941 -0
- data/docs/guides/multi-robot.md +866 -0
- data/docs/guides/recalling-memories.md +927 -0
- data/docs/guides/search-strategies.md +953 -0
- data/docs/guides/working-memory.md +717 -0
- data/docs/index.md +214 -0
- data/docs/installation.md +477 -0
- data/docs/multi_framework_support.md +519 -0
- data/docs/quick-start.md +655 -0
- data/docs/setup_local_database.md +302 -0
- data/docs/using_rake_tasks_in_your_app.md +383 -0
- data/examples/basic_usage.rb +93 -0
- data/examples/cli_app/README.md +317 -0
- data/examples/cli_app/htm_cli.rb +270 -0
- data/examples/custom_llm_configuration.rb +183 -0
- data/examples/example_app/Rakefile +71 -0
- data/examples/example_app/app.rb +206 -0
- data/examples/sinatra_app/Gemfile +21 -0
- data/examples/sinatra_app/app.rb +335 -0
- data/lib/htm/active_record_config.rb +113 -0
- data/lib/htm/configuration.rb +342 -0
- data/lib/htm/database.rb +594 -0
- data/lib/htm/embedding_service.rb +115 -0
- data/lib/htm/errors.rb +34 -0
- data/lib/htm/job_adapter.rb +154 -0
- data/lib/htm/jobs/generate_embedding_job.rb +65 -0
- data/lib/htm/jobs/generate_tags_job.rb +82 -0
- data/lib/htm/long_term_memory.rb +965 -0
- data/lib/htm/models/node.rb +109 -0
- data/lib/htm/models/node_tag.rb +33 -0
- data/lib/htm/models/robot.rb +52 -0
- data/lib/htm/models/tag.rb +76 -0
- data/lib/htm/railtie.rb +76 -0
- data/lib/htm/sinatra.rb +157 -0
- data/lib/htm/tag_service.rb +135 -0
- data/lib/htm/tasks.rb +38 -0
- data/lib/htm/version.rb +5 -0
- data/lib/htm/working_memory.rb +182 -0
- data/lib/htm.rb +400 -0
- data/lib/tasks/db.rake +19 -0
- data/lib/tasks/htm.rake +147 -0
- data/lib/tasks/jobs.rake +312 -0
- data/mkdocs.yml +190 -0
- data/scripts/install_local_database.sh +309 -0
- metadata +341 -0
data/docs/index.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="assets/images/htm_demo.gif" alt="Tree of Knowledge" width="800">
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<p>A hierarchical and temporal system for encoding, storing, and retrieving information—operating across varying levels of abstraction (from simple to detailed concepts and their relationships) and across time (from the present to the past).<br/>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
## What does it mean?
|
|
9
|
+
|
|
10
|
+
- **Hierarchical**: operates across multiple levels of abstraction, from simple concepts to detailed relationships
|
|
11
|
+
- **Temporal**: functions across time, from the present moment to historical data
|
|
12
|
+
- **Memory function**: encodes, stores, and retrieves information
|
|
13
|
+
|
|
14
|
+
**HTM**: a hierarchical and temporal memory system that organizes and recalls information at multiple levels of detail over extended timeframes.
|
|
15
|
+
|
|
16
|
+
## Key Features
|
|
17
|
+
|
|
18
|
+
### Two-Tier Memory Architecture
|
|
19
|
+
|
|
20
|
+
HTM implements a realistic memory model inspired by human cognition:
|
|
21
|
+
|
|
22
|
+
- **Working Memory**: Token-limited active context optimized for immediate LLM consumption
|
|
23
|
+
- **Long-term Memory**: Durable PostgreSQL storage that persists forever
|
|
24
|
+
|
|
25
|
+
The two tiers work seamlessly together - working memory pulls from long-term storage as needed, and automatically evicts less important memories back to long-term storage when space is limited.
|
|
26
|
+
|
|
27
|
+
### Never-Forget Philosophy
|
|
28
|
+
|
|
29
|
+
HTM follows a "never forget unless explicitly told" principle:
|
|
30
|
+
|
|
31
|
+
- All memories persist in long-term storage indefinitely
|
|
32
|
+
- Working memory evictions move data to long-term storage, never delete it
|
|
33
|
+
- Only explicit `forget()` commands with confirmation actually delete data
|
|
34
|
+
- Complete audit trail of all memory operations
|
|
35
|
+
|
|
36
|
+
### RAG-Based Retrieval
|
|
37
|
+
|
|
38
|
+
HTM uses advanced Retrieval-Augmented Generation techniques:
|
|
39
|
+
|
|
40
|
+
- **Vector Similarity Search**: Semantic search using pgvector with embeddings from Ollama
|
|
41
|
+
- **Full-Text Search**: PostgreSQL full-text search for keyword matching
|
|
42
|
+
- **Hybrid Search**: Combines both vector and full-text for best results
|
|
43
|
+
- **Temporal Filtering**: Natural language time queries like "last week" or "yesterday"
|
|
44
|
+
- **Importance Scoring**: Prioritize critical memories over trivial ones
|
|
45
|
+
|
|
46
|
+
### Multi-Robot Hive Mind
|
|
47
|
+
|
|
48
|
+
HTM enables multiple AI robots to share a collective memory:
|
|
49
|
+
|
|
50
|
+
- All robots share access to global long-term memory
|
|
51
|
+
- Track which robot said what and when
|
|
52
|
+
- Cross-robot context awareness and conversation continuity
|
|
53
|
+
- Query conversation timelines across multiple robots
|
|
54
|
+
|
|
55
|
+
### Knowledge Graph
|
|
56
|
+
|
|
57
|
+
Build rich relationship networks between memories:
|
|
58
|
+
|
|
59
|
+
- Link related memories together
|
|
60
|
+
- Tag-based categorization
|
|
61
|
+
- Importance scoring for prioritization
|
|
62
|
+
- Navigate memory relationships programmatically
|
|
63
|
+
|
|
64
|
+
## Quick Example
|
|
65
|
+
|
|
66
|
+
Here's how simple it is to get started with HTM:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
require 'htm'
|
|
70
|
+
|
|
71
|
+
# Initialize HTM for your robot
|
|
72
|
+
htm = HTM.new(
|
|
73
|
+
robot_name: "Code Helper",
|
|
74
|
+
working_memory_size: 128_000, # 128k tokens
|
|
75
|
+
embedding_service: :ollama, # Use Ollama for embeddings
|
|
76
|
+
embedding_model: 'gpt-oss' # Default embedding model
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Add memories (embeddings generated automatically)
|
|
80
|
+
htm.add_node(
|
|
81
|
+
"decision_001",
|
|
82
|
+
"We decided to use PostgreSQL for HTM storage",
|
|
83
|
+
type: :decision,
|
|
84
|
+
category: "architecture",
|
|
85
|
+
importance: 9.0,
|
|
86
|
+
tags: ["database", "architecture"]
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Recall memories from the past
|
|
90
|
+
memories = htm.recall(
|
|
91
|
+
timeframe: "last week",
|
|
92
|
+
topic: "database decisions",
|
|
93
|
+
strategy: :hybrid
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Create context for your LLM
|
|
97
|
+
context = htm.create_context(
|
|
98
|
+
strategy: :balanced,
|
|
99
|
+
max_tokens: 50_000
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# Use context in your LLM prompt
|
|
103
|
+
response = llm.chat(
|
|
104
|
+
system: "You are a helpful assistant. " \
|
|
105
|
+
"Here's your memory context:\n#{context}",
|
|
106
|
+
user: "What database did we decide to use?"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Explicit deletion only when needed
|
|
110
|
+
htm.forget("old_decision", confirm: :confirmed)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Use Cases
|
|
114
|
+
|
|
115
|
+
HTM is perfect for:
|
|
116
|
+
|
|
117
|
+
- **AI Coding Assistants**: Remember project decisions, code patterns, and user preferences
|
|
118
|
+
- **Customer Service Bots**: Maintain conversation history and customer context
|
|
119
|
+
- **Personal AI Assistants**: Remember user preferences, habits, and important information
|
|
120
|
+
- **Research Assistants**: Build knowledge graphs from documents and conversations
|
|
121
|
+
- **Multi-Agent Systems**: Enable collaborative memory across multiple AI agents
|
|
122
|
+
|
|
123
|
+
## Architecture Overview
|
|
124
|
+
|
|
125
|
+
HTM consists of several key components working together:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
┌─────────────────────────────────────────────────┐
|
|
129
|
+
│ Your LLM │
|
|
130
|
+
│ (Claude, GPT, etc.) │
|
|
131
|
+
└─────────────────┬───────────────────────────────┘
|
|
132
|
+
│
|
|
133
|
+
▼
|
|
134
|
+
┌─────────────────────────────────────────────────┐
|
|
135
|
+
│ HTM API │
|
|
136
|
+
│ add_node(), recall(), create_context(), etc. │
|
|
137
|
+
└──────┬──────────────────────────────────┬──────┘
|
|
138
|
+
│ │
|
|
139
|
+
▼ ▼
|
|
140
|
+
┌─────────────────┐ ┌──────────────────┐
|
|
141
|
+
│ Working Memory │ │ Long-term Memory │
|
|
142
|
+
│ (In-Memory) │◄────────────►│ (PostgreSQL) │
|
|
143
|
+
│ 128k tokens │ Eviction │ ∞ storage │
|
|
144
|
+
│ Fast access │ & Recall │ │
|
|
145
|
+
└─────────────────┘ └──────────────────┘
|
|
146
|
+
│
|
|
147
|
+
▼
|
|
148
|
+
┌──────────────────┐
|
|
149
|
+
│ Embedding Service│
|
|
150
|
+
│ (Ollama/RubyLLM)│
|
|
151
|
+
│ gpt-oss model │
|
|
152
|
+
└──────────────────┘
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Component Breakdown
|
|
156
|
+
|
|
157
|
+
- **HTM API**: Main interface for all memory operations
|
|
158
|
+
- **WorkingMemory**: Token-limited in-memory cache for immediate LLM use
|
|
159
|
+
- **LongTermMemory**: PostgreSQL-backed durable storage
|
|
160
|
+
- **EmbeddingService**: Generates vector embeddings via RubyLLM and Ollama
|
|
161
|
+
- **Database**: Schema management and connection pooling
|
|
162
|
+
|
|
163
|
+
## Memory Types
|
|
164
|
+
|
|
165
|
+
HTM supports different categories of memories:
|
|
166
|
+
|
|
167
|
+
- **`:fact`**: Immutable facts ("User's name is Dewayne")
|
|
168
|
+
- **`:context`**: Conversation state and context
|
|
169
|
+
- **`:code`**: Code snippets and programming patterns
|
|
170
|
+
- **`:preference`**: User preferences and settings
|
|
171
|
+
- **`:decision`**: Architectural and design decisions
|
|
172
|
+
- **`:question`**: Unresolved questions needing answers
|
|
173
|
+
|
|
174
|
+
Each type can have custom importance scores, tags, and relationships.
|
|
175
|
+
|
|
176
|
+
## Getting Started
|
|
177
|
+
|
|
178
|
+
Ready to add intelligent memory to your LLM application? Follow these steps:
|
|
179
|
+
|
|
180
|
+
1. **[Installation](installation.md)**: Set up HTM, PostgreSQL, TimescaleDB, and Ollama
|
|
181
|
+
2. **[Quick Start](quick-start.md)**: Build your first HTM-powered application in 5 minutes
|
|
182
|
+
3. **[User Guide](guides/getting-started.md)**: Deep dive into all HTM features
|
|
183
|
+
4. **[API Reference](api/htm.md)**: Complete API documentation
|
|
184
|
+
|
|
185
|
+
## Community and Support
|
|
186
|
+
|
|
187
|
+
- **GitHub**: [https://github.com/madbomber/htm](https://github.com/madbomber/htm)
|
|
188
|
+
- **Issues**: Report bugs and request features
|
|
189
|
+
- **Discussions**: Ask questions and share your projects
|
|
190
|
+
|
|
191
|
+
## Philosophy
|
|
192
|
+
|
|
193
|
+
HTM is built on several core principles:
|
|
194
|
+
|
|
195
|
+
1. **Never Forget**: Data should persist unless explicitly deleted
|
|
196
|
+
2. **Context is King**: LLMs need rich, relevant context to perform well
|
|
197
|
+
3. **Time Matters**: Recent and temporal context is crucial for AI cognition
|
|
198
|
+
4. **Relationships Count**: Memories are interconnected, not isolated
|
|
199
|
+
5. **Hive Mind**: Multiple agents should share collective intelligence
|
|
200
|
+
|
|
201
|
+
## Credits
|
|
202
|
+
|
|
203
|
+
HTM is developed by [Dewayne VanHoozer](https://github.com/madbomber) with design assistance from Claude (Anthropic).
|
|
204
|
+
|
|
205
|
+
Licensed under the MIT License.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
**Next Steps:**
|
|
210
|
+
|
|
211
|
+
- [Install HTM](installation.md) and set up your environment
|
|
212
|
+
- Follow the [Quick Start Guide](quick-start.md) to build your first application
|
|
213
|
+
- Explore the [User Guide](guides/getting-started.md) for advanced features
|
|
214
|
+
- Check out the [API Reference](api/htm.md) for detailed documentation
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
# Installation Guide
|
|
2
|
+
|
|
3
|
+
This guide will walk you through setting up HTM and all its dependencies.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before installing HTM, ensure you have:
|
|
8
|
+
|
|
9
|
+
- **Ruby 3.0 or higher** - HTM requires modern Ruby features
|
|
10
|
+
- **PostgreSQL 17+** - For the database backend
|
|
11
|
+
- **Ollama** - For generating vector embeddings (via RubyLLM)
|
|
12
|
+
|
|
13
|
+
### Check Your Ruby Version
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ruby --version
|
|
17
|
+
# Should show: ruby 3.0.0 or higher
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If you need to install or upgrade Ruby, we recommend using [rbenv](https://github.com/rbenv/rbenv):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Install rbenv (macOS)
|
|
24
|
+
brew install rbenv ruby-build
|
|
25
|
+
|
|
26
|
+
# Install Ruby 3.3 (latest stable)
|
|
27
|
+
rbenv install 3.3.0
|
|
28
|
+
rbenv global 3.3.0
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Step 1: Install the HTM Gem
|
|
32
|
+
|
|
33
|
+
### Option A: Install via Bundler (Recommended)
|
|
34
|
+
|
|
35
|
+
Add HTM to your application's `Gemfile`:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
# Gemfile
|
|
39
|
+
source 'https://rubygems.org'
|
|
40
|
+
|
|
41
|
+
gem 'htm'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then install:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bundle install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Option B: Install Directly
|
|
51
|
+
|
|
52
|
+
Install HTM directly via RubyGems:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
gem install htm
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Step 2: Database Setup
|
|
59
|
+
|
|
60
|
+
HTM requires PostgreSQL 17+ with the pgvector extension.
|
|
61
|
+
|
|
62
|
+
### Option A: Local PostgreSQL Installation
|
|
63
|
+
|
|
64
|
+
#### macOS (using Homebrew)
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Install PostgreSQL
|
|
68
|
+
brew install postgresql@17
|
|
69
|
+
|
|
70
|
+
# Start PostgreSQL service
|
|
71
|
+
brew services start postgresql@17
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Linux (Ubuntu/Debian)
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Add PostgreSQL repository
|
|
78
|
+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
|
79
|
+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
|
80
|
+
|
|
81
|
+
# Install PostgreSQL
|
|
82
|
+
sudo apt-get update
|
|
83
|
+
sudo apt-get install postgresql-17 postgresql-client-17
|
|
84
|
+
|
|
85
|
+
# Start PostgreSQL service
|
|
86
|
+
sudo systemctl start postgresql
|
|
87
|
+
sudo systemctl enable postgresql
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Create Database
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Create database and user
|
|
94
|
+
createdb htm_db
|
|
95
|
+
psql htm_db
|
|
96
|
+
|
|
97
|
+
# In psql console:
|
|
98
|
+
CREATE EXTENSION IF NOT EXISTS pgvector;
|
|
99
|
+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Configure Environment Variables
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Add to ~/.bashrc or your preferred config file
|
|
106
|
+
export HTM_DBURL="postgres://username:password@localhost:5432/htm_db"
|
|
107
|
+
export HTM_DBNAME="htm_db"
|
|
108
|
+
export HTM_DBUSER="your_username"
|
|
109
|
+
export HTM_DBPASS="your_password"
|
|
110
|
+
export HTM_DBPORT="5432"
|
|
111
|
+
export HTM_DBHOST="localhost"
|
|
112
|
+
|
|
113
|
+
# Load the configuration
|
|
114
|
+
source ~/.bashrc
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
!!! tip "Environment Configuration"
|
|
118
|
+
HTM automatically uses the `HTM_DBURL` environment variable if available. You can also pass database configuration directly to `HTM.new()`.
|
|
119
|
+
|
|
120
|
+
Set environment variable:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
export HTM_DBURL="postgres://localhost/htm_db"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Step 3: Enable PostgreSQL Extensions
|
|
127
|
+
|
|
128
|
+
HTM requires two PostgreSQL extensions:
|
|
129
|
+
|
|
130
|
+
- **pgvector**: Vector similarity search
|
|
131
|
+
- **pg_trgm**: Full-text search
|
|
132
|
+
|
|
133
|
+
### Verify Extensions
|
|
134
|
+
|
|
135
|
+
Test your database connection and verify extensions:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Download or use the included test script
|
|
139
|
+
cd /path/to/your/project
|
|
140
|
+
ruby -e "
|
|
141
|
+
require 'pg'
|
|
142
|
+
conn = PG.connect(ENV['HTM_DBURL'])
|
|
143
|
+
result = conn.exec('SELECT extname, extversion FROM pg_extension ORDER BY extname')
|
|
144
|
+
result.each { |row| puts \"✓ #{row['extname']}: Version #{row['extversion']}\" }
|
|
145
|
+
conn.close
|
|
146
|
+
"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Expected output:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
✓ pg_trgm: Version 1.6
|
|
153
|
+
✓ pgvector: Version 0.8.1
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
!!! warning "Missing Extensions"
|
|
157
|
+
If extensions are missing, you may need to install them. On Debian/Ubuntu: `sudo apt-get install postgresql-17-pgvector`. On macOS: `brew install pgvector`.
|
|
158
|
+
|
|
159
|
+
## Step 4: Install Ollama
|
|
160
|
+
|
|
161
|
+
HTM uses [Ollama](https://ollama.ai/) via RubyLLM for generating vector embeddings.
|
|
162
|
+
|
|
163
|
+
### Install Ollama
|
|
164
|
+
|
|
165
|
+
#### macOS
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Option 1: Direct download
|
|
169
|
+
curl https://ollama.ai/install.sh | sh
|
|
170
|
+
|
|
171
|
+
# Option 2: Homebrew
|
|
172
|
+
brew install ollama
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Linux
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
curl https://ollama.ai/install.sh | sh
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Windows
|
|
182
|
+
|
|
183
|
+
Download the installer from [https://ollama.ai/download](https://ollama.ai/download)
|
|
184
|
+
|
|
185
|
+
### Start Ollama Service
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# Ollama typically starts automatically
|
|
189
|
+
# Verify it's running:
|
|
190
|
+
curl http://localhost:11434/api/version
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Expected output:
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{"version":"0.1.x"}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Pull the gpt-oss Model
|
|
200
|
+
|
|
201
|
+
HTM uses the `gpt-oss` model by default:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Download the model
|
|
205
|
+
ollama pull gpt-oss
|
|
206
|
+
|
|
207
|
+
# Verify the model is available
|
|
208
|
+
ollama list
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
You should see `gpt-oss` in the list.
|
|
212
|
+
|
|
213
|
+
### Test Embedding Generation
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Test that embeddings work
|
|
217
|
+
ollama run gpt-oss "Hello, world!"
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Custom Ollama URL (Optional)
|
|
221
|
+
|
|
222
|
+
If Ollama is running on a different host or port:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
export OLLAMA_URL="http://custom-host:11434"
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
!!! tip "Ollama Model Selection"
|
|
229
|
+
HTM defaults to `gpt-oss`, but you can use any embedding model supported by Ollama. Just pass `embedding_model: 'your-model'` to `HTM.new()`.
|
|
230
|
+
|
|
231
|
+
## Step 5: Initialize HTM Database Schema
|
|
232
|
+
|
|
233
|
+
Run the database setup to create HTM's tables and schema:
|
|
234
|
+
|
|
235
|
+
### Option A: Using Ruby
|
|
236
|
+
|
|
237
|
+
```ruby
|
|
238
|
+
require 'htm'
|
|
239
|
+
|
|
240
|
+
# Run database setup
|
|
241
|
+
HTM::Database.setup
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Option B: Using Command Line
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
ruby -r ./lib/htm -e "HTM::Database.setup"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Option C: Using Rake Task (if available)
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
rake db:setup
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
This creates the following tables:
|
|
257
|
+
|
|
258
|
+
- **`nodes`**: Main memory storage with vector embeddings
|
|
259
|
+
- **`relationships`**: Knowledge graph connections
|
|
260
|
+
- **`tags`**: Flexible categorization
|
|
261
|
+
- **`robots`**: Robot registry
|
|
262
|
+
- **`operations_log`**: Audit trail
|
|
263
|
+
|
|
264
|
+
!!! success "Schema Created"
|
|
265
|
+
You'll see confirmation messages as each table and index is created.
|
|
266
|
+
|
|
267
|
+
## Step 6: Verify Installation
|
|
268
|
+
|
|
269
|
+
Create a test script to verify everything works:
|
|
270
|
+
|
|
271
|
+
```ruby
|
|
272
|
+
# test_htm_setup.rb
|
|
273
|
+
require 'htm'
|
|
274
|
+
|
|
275
|
+
puts "Testing HTM Installation..."
|
|
276
|
+
|
|
277
|
+
# Initialize HTM
|
|
278
|
+
htm = HTM.new(
|
|
279
|
+
robot_name: "Test Robot",
|
|
280
|
+
working_memory_size: 128_000,
|
|
281
|
+
embedding_service: :ollama,
|
|
282
|
+
embedding_model: 'gpt-oss'
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
puts "✓ HTM initialized successfully"
|
|
286
|
+
puts " Robot ID: #{htm.robot_id}"
|
|
287
|
+
puts " Robot Name: #{htm.robot_name}"
|
|
288
|
+
|
|
289
|
+
# Add a test memory
|
|
290
|
+
htm.add_node(
|
|
291
|
+
"test_001",
|
|
292
|
+
"This is a test memory to verify HTM installation.",
|
|
293
|
+
type: :fact,
|
|
294
|
+
importance: 5.0,
|
|
295
|
+
tags: ["test"]
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
puts "✓ Memory node added successfully"
|
|
299
|
+
|
|
300
|
+
# Retrieve the memory
|
|
301
|
+
node = htm.retrieve("test_001")
|
|
302
|
+
if node
|
|
303
|
+
puts "✓ Memory retrieval works"
|
|
304
|
+
puts " Content: #{node['value']}"
|
|
305
|
+
else
|
|
306
|
+
puts "✗ Failed to retrieve memory"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Get stats
|
|
310
|
+
stats = htm.memory_stats
|
|
311
|
+
puts "✓ Memory stats:"
|
|
312
|
+
puts " Total nodes: #{stats[:total_nodes]}"
|
|
313
|
+
puts " Working memory: #{stats[:working_memory][:node_count]} nodes"
|
|
314
|
+
|
|
315
|
+
# Clean up test data
|
|
316
|
+
htm.forget("test_001", confirm: :confirmed)
|
|
317
|
+
puts "✓ Memory deletion works"
|
|
318
|
+
|
|
319
|
+
puts "\n" + "=" * 60
|
|
320
|
+
puts "✓ HTM installation verified successfully!"
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Run the test:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
ruby test_htm_setup.rb
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## Environment Variables Reference
|
|
330
|
+
|
|
331
|
+
HTM uses the following environment variables:
|
|
332
|
+
|
|
333
|
+
| Variable | Description | Default | Required |
|
|
334
|
+
|----------|-------------|---------|----------|
|
|
335
|
+
| `HTM_DBURL` | PostgreSQL connection URL | - | Yes |
|
|
336
|
+
| `HTM_DBNAME` | Database name | `htm_db` | No |
|
|
337
|
+
| `HTM_DBUSER` | Database user | `postgres` | No |
|
|
338
|
+
| `HTM_DBPASS` | Database password | - | No |
|
|
339
|
+
| `HTM_DBPORT` | Database port | `5432` | No |
|
|
340
|
+
| `OLLAMA_URL` | Ollama API URL | `http://localhost:11434` | No |
|
|
341
|
+
|
|
342
|
+
### Example Configuration File
|
|
343
|
+
|
|
344
|
+
Create a configuration file for easy loading:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
# ~/.bashrc__htm
|
|
348
|
+
export HTM_DBURL="postgres://user:pass@host:port/db?sslmode=require"
|
|
349
|
+
export OLLAMA_URL="http://localhost:11434"
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Load it in your shell:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# Add to ~/.bashrc or ~/.zshrc
|
|
356
|
+
source ~/.bashrc__htm
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Troubleshooting
|
|
360
|
+
|
|
361
|
+
### Database Connection Issues
|
|
362
|
+
|
|
363
|
+
**Error**: `PG::ConnectionBad: connection failed`
|
|
364
|
+
|
|
365
|
+
**Solutions**:
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
# 1. Verify HTM_DBURL is set
|
|
369
|
+
echo $HTM_DBURL
|
|
370
|
+
|
|
371
|
+
# 2. Test connection manually
|
|
372
|
+
psql $HTM_DBURL
|
|
373
|
+
|
|
374
|
+
# 3. Check if PostgreSQL is running (local installs)
|
|
375
|
+
pg_ctl status
|
|
376
|
+
|
|
377
|
+
# 4. Verify SSL mode for cloud databases
|
|
378
|
+
# Ensure URL includes: ?sslmode=require
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Ollama Connection Issues
|
|
382
|
+
|
|
383
|
+
**Error**: `Connection refused - connect(2) for localhost:11434`
|
|
384
|
+
|
|
385
|
+
**Solutions**:
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
# 1. Check if Ollama is running
|
|
389
|
+
curl http://localhost:11434/api/version
|
|
390
|
+
|
|
391
|
+
# 2. Start Ollama (macOS)
|
|
392
|
+
# Check Activity Monitor or menu bar
|
|
393
|
+
|
|
394
|
+
# 3. Restart Ollama service
|
|
395
|
+
killall ollama
|
|
396
|
+
ollama serve
|
|
397
|
+
|
|
398
|
+
# 4. Verify gpt-oss model is installed
|
|
399
|
+
ollama list | grep gpt-oss
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Missing Extensions
|
|
403
|
+
|
|
404
|
+
**Error**: `PG::UndefinedObject: extension "pgvector" is not available`
|
|
405
|
+
|
|
406
|
+
**Solutions**:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
# Install pgvector
|
|
410
|
+
git clone https://github.com/pgvector/pgvector.git
|
|
411
|
+
cd pgvector
|
|
412
|
+
make
|
|
413
|
+
sudo make install
|
|
414
|
+
|
|
415
|
+
# Enable in database
|
|
416
|
+
psql $HTM_DBURL -c "CREATE EXTENSION IF NOT EXISTS pgvector;"
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Ruby Version Issues
|
|
420
|
+
|
|
421
|
+
**Error**: `htm requires Ruby version >= 3.0.0`
|
|
422
|
+
|
|
423
|
+
**Solutions**:
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
# Check current version
|
|
427
|
+
ruby --version
|
|
428
|
+
|
|
429
|
+
# Install newer Ruby via rbenv
|
|
430
|
+
rbenv install 3.3.0
|
|
431
|
+
rbenv global 3.3.0
|
|
432
|
+
|
|
433
|
+
# Verify
|
|
434
|
+
ruby --version
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Permission Issues
|
|
438
|
+
|
|
439
|
+
**Error**: `PG::InsufficientPrivilege: permission denied`
|
|
440
|
+
|
|
441
|
+
**Solutions**:
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Ensure your database user has necessary permissions
|
|
445
|
+
psql $HTM_DBURL -c "
|
|
446
|
+
GRANT ALL PRIVILEGES ON DATABASE your_db TO your_user;
|
|
447
|
+
GRANT ALL ON ALL TABLES IN SCHEMA public TO your_user;
|
|
448
|
+
"
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## Next Steps
|
|
452
|
+
|
|
453
|
+
Now that HTM is installed, you're ready to start building:
|
|
454
|
+
|
|
455
|
+
1. **[Quick Start Guide](quick-start.md)**: Build your first HTM application in 5 minutes
|
|
456
|
+
2. **[User Guide](guides/getting-started.md)**: Learn all HTM features in depth
|
|
457
|
+
3. **[API Reference](api/htm.md)**: Explore the complete API documentation
|
|
458
|
+
4. **[Examples](https://github.com/madbomber/htm/tree/main/examples)**: See real-world usage examples
|
|
459
|
+
|
|
460
|
+
## Getting Help
|
|
461
|
+
|
|
462
|
+
If you encounter issues:
|
|
463
|
+
|
|
464
|
+
1. Check the [Troubleshooting](#troubleshooting) section above
|
|
465
|
+
2. Review [GitHub Issues](https://github.com/madbomber/htm/issues)
|
|
466
|
+
3. Open a new issue with:
|
|
467
|
+
- Your Ruby version (`ruby --version`)
|
|
468
|
+
- Your PostgreSQL version (`psql --version`)
|
|
469
|
+
- Error messages and stack traces
|
|
470
|
+
- Steps to reproduce
|
|
471
|
+
|
|
472
|
+
## Additional Resources
|
|
473
|
+
|
|
474
|
+
- **Ollama Documentation**: [https://ollama.ai/](https://ollama.ai/)
|
|
475
|
+
- **pgvector Documentation**: [https://github.com/pgvector/pgvector](https://github.com/pgvector/pgvector)
|
|
476
|
+
- **PostgreSQL Documentation**: [https://www.postgresql.org/docs/](https://www.postgresql.org/docs/)
|
|
477
|
+
- **RubyLLM Documentation**: [https://github.com/madbomber/ruby_llm](https://github.com/madbomber/ruby_llm)
|