htm 0.0.1 → 0.0.2
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/.envrc +1 -0
- data/.tbls.yml +30 -0
- data/CHANGELOG.md +30 -0
- data/SETUP.md +132 -101
- data/db/migrate/20250125000001_add_content_hash_to_nodes.rb +14 -0
- data/db/migrate/20250125000002_create_robot_nodes.rb +35 -0
- data/db/migrate/20250125000003_remove_source_and_robot_id_from_nodes.rb +28 -0
- data/db/migrate/20250126000001_create_working_memories.rb +19 -0
- data/db/migrate/20250126000002_remove_unused_columns.rb +12 -0
- data/db/schema.sql +226 -43
- data/docs/api/database.md +20 -232
- data/docs/api/embedding-service.md +1 -7
- data/docs/api/htm.md +195 -449
- data/docs/api/index.md +1 -7
- data/docs/api/long-term-memory.md +342 -590
- data/docs/architecture/adrs/001-postgresql-timescaledb.md +1 -1
- data/docs/architecture/adrs/003-ollama-embeddings.md +1 -1
- data/docs/architecture/adrs/010-redis-working-memory-rejected.md +2 -27
- data/docs/architecture/adrs/index.md +2 -13
- data/docs/architecture/hive-mind.md +165 -166
- data/docs/architecture/index.md +2 -2
- data/docs/architecture/overview.md +5 -171
- data/docs/architecture/two-tier-memory.md +1 -35
- data/docs/assets/images/adr-010-current-architecture.svg +37 -0
- data/docs/assets/images/adr-010-proposed-architecture.svg +48 -0
- data/docs/assets/images/adr-dependency-tree.svg +93 -0
- data/docs/assets/images/class-hierarchy.svg +55 -0
- data/docs/assets/images/exception-hierarchy.svg +45 -0
- data/docs/assets/images/htm-architecture-overview.svg +83 -0
- data/docs/assets/images/htm-complete-memory-flow.svg +160 -0
- data/docs/assets/images/htm-context-assembly-flow.svg +148 -0
- data/docs/assets/images/htm-eviction-process.svg +141 -0
- data/docs/assets/images/htm-memory-addition-flow.svg +138 -0
- data/docs/assets/images/htm-memory-recall-flow.svg +152 -0
- data/docs/assets/images/htm-node-states.svg +123 -0
- data/docs/assets/images/project-structure.svg +78 -0
- data/docs/assets/images/test-directory-structure.svg +38 -0
- data/{dbdoc → docs/database}/README.md +5 -3
- data/{dbdoc → docs/database}/public.node_tags.md +4 -5
- data/docs/database/public.node_tags.svg +106 -0
- data/{dbdoc → docs/database}/public.nodes.md +3 -8
- data/docs/database/public.nodes.svg +152 -0
- data/docs/database/public.robot_nodes.md +44 -0
- data/docs/database/public.robot_nodes.svg +121 -0
- data/{dbdoc → docs/database}/public.robots.md +1 -2
- data/docs/database/public.robots.svg +106 -0
- data/docs/database/public.working_memories.md +40 -0
- data/docs/database/public.working_memories.svg +112 -0
- data/{dbdoc → docs/database}/schema.json +342 -110
- data/docs/database/schema.svg +223 -0
- data/docs/development/index.md +1 -29
- data/docs/development/schema.md +84 -324
- data/docs/development/testing.md +1 -9
- data/docs/getting-started/index.md +47 -0
- data/docs/{installation.md → getting-started/installation.md} +2 -2
- data/docs/{quick-start.md → getting-started/quick-start.md} +5 -5
- data/docs/guides/adding-memories.md +221 -655
- data/docs/guides/search-strategies.md +85 -51
- data/docs/images/htm-er-diagram.svg +156 -0
- data/docs/index.md +16 -31
- data/docs/multi_framework_support.md +4 -4
- data/examples/basic_usage.rb +18 -16
- data/examples/cli_app/htm_cli.rb +86 -8
- data/examples/custom_llm_configuration.rb +1 -2
- data/examples/example_app/app.rb +11 -14
- data/examples/sinatra_app/Gemfile +1 -0
- data/examples/sinatra_app/Gemfile.lock +166 -0
- data/examples/sinatra_app/app.rb +219 -24
- data/lib/htm/active_record_config.rb +10 -3
- data/lib/htm/configuration.rb +265 -78
- data/lib/htm/{sinatra.rb → integrations/sinatra.rb} +87 -12
- data/lib/htm/job_adapter.rb +10 -3
- data/lib/htm/long_term_memory.rb +220 -57
- data/lib/htm/models/node.rb +36 -7
- data/lib/htm/models/robot.rb +30 -4
- data/lib/htm/models/robot_node.rb +50 -0
- data/lib/htm/models/tag.rb +52 -0
- data/lib/htm/models/working_memory_entry.rb +88 -0
- data/lib/htm/tasks.rb +4 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm.rb +34 -13
- data/lib/tasks/htm.rake +32 -1
- data/lib/tasks/jobs.rake +7 -3
- data/lib/tasks/tags.rake +34 -0
- data/mkdocs.yml +56 -9
- metadata +61 -31
- data/dbdoc/public.node_tags.svg +0 -112
- data/dbdoc/public.nodes.svg +0 -118
- data/dbdoc/public.robots.svg +0 -90
- data/dbdoc/schema.svg +0 -154
- /data/{dbdoc → docs/database}/public.node_stats.md +0 -0
- /data/{dbdoc → docs/database}/public.node_stats.svg +0 -0
- /data/{dbdoc → docs/database}/public.nodes_tags.md +0 -0
- /data/{dbdoc → docs/database}/public.nodes_tags.svg +0 -0
- /data/{dbdoc → docs/database}/public.ontology_structure.md +0 -0
- /data/{dbdoc → docs/database}/public.ontology_structure.svg +0 -0
- /data/{dbdoc → docs/database}/public.operations_log.md +0 -0
- /data/{dbdoc → docs/database}/public.operations_log.svg +0 -0
- /data/{dbdoc → docs/database}/public.relationships.md +0 -0
- /data/{dbdoc → docs/database}/public.relationships.svg +0 -0
- /data/{dbdoc → docs/database}/public.robot_activity.md +0 -0
- /data/{dbdoc → docs/database}/public.robot_activity.svg +0 -0
- /data/{dbdoc → docs/database}/public.schema_migrations.md +0 -0
- /data/{dbdoc → docs/database}/public.schema_migrations.svg +0 -0
- /data/{dbdoc → docs/database}/public.tags.md +0 -0
- /data/{dbdoc → docs/database}/public.tags.svg +0 -0
- /data/{dbdoc → docs/database}/public.topic_relationships.md +0 -0
- /data/{dbdoc → docs/database}/public.topic_relationships.svg +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d381f41347974376534b3f6da3e1cbff46320e8ada7e078d432b27abed546165
|
|
4
|
+
data.tar.gz: 7d387e9daddbafef1f9bdc6d3538fe80c3c03ad0a78220b4b6722e56214e2682
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 660b77256ddb31aeb4ae7cf2eff34dae9099b41303527291fe3640d991071df3691ed76b17ad5c2404ce3e1fafcde483ffea8359b0629dddf9cd86dafc0f3e45
|
|
7
|
+
data.tar.gz: fee193c2e2138abfd2dfdd9bb20806de8e51751a61dcea44e8b840ed12d6fb41098e1980d1755acf81f70e69d4286772c6770bbc2520cc2a44dd6fc12adcdab3
|
data/.envrc
CHANGED
|
@@ -9,6 +9,7 @@ export HTM_DBNAME=htm_development
|
|
|
9
9
|
export HTM_DBUSER=${USER}
|
|
10
10
|
export HTM_DBPASS=
|
|
11
11
|
export HTM_DBURL="postgresql://${HTM_DBUSER}@${HTM_DBHOST}:${HTM_DBPORT}/${HTM_DBNAME}?sslmode=disable"
|
|
12
|
+
# export HTM_DBURL="postgresql://dewayne@localhost:5432/htm_development"
|
|
12
13
|
|
|
13
14
|
# Uncomment if using TimescaleDB Cloud instead:
|
|
14
15
|
# export HTM_SERVICE_NAME=$TIGER_SERVICE_NAME
|
data/.tbls.yml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# tbls configuration for HTM database documentation
|
|
2
|
+
# https://github.com/k1LoW/tbls
|
|
3
|
+
|
|
4
|
+
# Database connection - uses HTM_DBURL environment variable
|
|
5
|
+
dsn: env://HTM_DBURL
|
|
6
|
+
|
|
7
|
+
# Output documentation to docs/database directory
|
|
8
|
+
docPath: docs/database
|
|
9
|
+
|
|
10
|
+
# Documentation format options
|
|
11
|
+
format:
|
|
12
|
+
adjust_table_width: true
|
|
13
|
+
sort: true
|
|
14
|
+
|
|
15
|
+
# ER diagram settings
|
|
16
|
+
er:
|
|
17
|
+
format: svg
|
|
18
|
+
comment: true
|
|
19
|
+
distance: 2
|
|
20
|
+
|
|
21
|
+
# Include schema metadata
|
|
22
|
+
include:
|
|
23
|
+
- public.*
|
|
24
|
+
|
|
25
|
+
# Lint rules for schema quality
|
|
26
|
+
lint:
|
|
27
|
+
requireColumnComment:
|
|
28
|
+
enabled: false
|
|
29
|
+
requireTableComment:
|
|
30
|
+
enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
|
+
- **Multi-provider LLM support via RubyLLM** - HTM now supports 9 LLM providers:
|
|
12
|
+
- OpenAI (`text-embedding-3-small`, `gpt-4o-mini`)
|
|
13
|
+
- Anthropic (`claude-3-haiku-20240307`)
|
|
14
|
+
- Google Gemini (`text-embedding-004`)
|
|
15
|
+
- Azure OpenAI
|
|
16
|
+
- Ollama (default, local-first)
|
|
17
|
+
- HuggingFace Inference API
|
|
18
|
+
- OpenRouter
|
|
19
|
+
- AWS Bedrock
|
|
20
|
+
- DeepSeek
|
|
21
|
+
- Provider-specific configuration attributes:
|
|
22
|
+
- `openai_api_key`, `openai_organization`, `openai_project`
|
|
23
|
+
- `anthropic_api_key`
|
|
24
|
+
- `gemini_api_key`
|
|
25
|
+
- `azure_api_key`, `azure_endpoint`, `azure_api_version`
|
|
26
|
+
- `ollama_url`
|
|
27
|
+
- `huggingface_api_key`
|
|
28
|
+
- `openrouter_api_key`
|
|
29
|
+
- `bedrock_access_key`, `bedrock_secret_key`, `bedrock_region`
|
|
30
|
+
- `deepseek_api_key`
|
|
31
|
+
- `HTM::Configuration#configure_ruby_llm` method for provider credential setup
|
|
32
|
+
- `SUPPORTED_PROVIDERS` constant listing all available providers
|
|
33
|
+
- `DEFAULT_DIMENSIONS` hash with typical embedding dimensions per provider
|
|
11
34
|
- Architecture documentation using ai-software-architect framework
|
|
12
35
|
- Comprehensive ADRs (Architecture Decision Records):
|
|
13
36
|
- ADR-001: PostgreSQL with TimescaleDB for storage
|
|
@@ -22,6 +45,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
22
45
|
- Architecture review team with 8 specialist perspectives
|
|
23
46
|
- Had the robot convert my notss and system analysis documentation into Architectural Decision Records (ADR)
|
|
24
47
|
|
|
48
|
+
### Changed
|
|
49
|
+
- **Embedding generator now uses `RubyLLM.embed()`** instead of raw HTTP calls to Ollama
|
|
50
|
+
- **Tag extractor now uses `RubyLLM.chat()`** instead of raw HTTP calls to Ollama
|
|
51
|
+
- Configuration validation now checks provider is in `SUPPORTED_PROVIDERS`
|
|
52
|
+
- Updated CLAUDE.md with multi-provider documentation and examples
|
|
53
|
+
- Environment variables section expanded with all provider API keys
|
|
54
|
+
|
|
25
55
|
## [0.1.0] - 2025-10-25
|
|
26
56
|
|
|
27
57
|
### Added
|
data/SETUP.md
CHANGED
|
@@ -3,122 +3,165 @@
|
|
|
3
3
|
## Prerequisites
|
|
4
4
|
|
|
5
5
|
1. **Ruby** (version 3.0 or higher)
|
|
6
|
-
2. **
|
|
7
|
-
3. **
|
|
8
|
-
4. **Ollama** (for embeddings via RubyLLM)
|
|
6
|
+
2. **PostgreSQL** (14+ with pgvector and pg_trgm extensions)
|
|
7
|
+
3. **Ollama** (for embeddings via RubyLLM)
|
|
9
8
|
|
|
10
|
-
##
|
|
9
|
+
## PostgreSQL Setup
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
### 1. Install PostgreSQL
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
**macOS (via Homebrew):**
|
|
14
|
+
```bash
|
|
15
|
+
brew install postgresql@17
|
|
16
|
+
brew services start postgresql@17
|
|
17
|
+
```
|
|
15
18
|
|
|
16
|
-
**
|
|
19
|
+
**Ubuntu/Debian:**
|
|
17
20
|
```bash
|
|
18
|
-
|
|
21
|
+
sudo apt install postgresql postgresql-contrib
|
|
22
|
+
sudo systemctl start postgresql
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
### 2. Install pgvector Extension
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
**macOS:**
|
|
28
|
+
```bash
|
|
29
|
+
brew install pgvector
|
|
30
|
+
```
|
|
24
31
|
|
|
32
|
+
**Ubuntu/Debian:**
|
|
25
33
|
```bash
|
|
26
|
-
|
|
27
|
-
# Verify it's running:
|
|
28
|
-
curl http://localhost:11434/api/version
|
|
34
|
+
sudo apt install postgresql-17-pgvector
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
**From source:**
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/pgvector/pgvector.git
|
|
40
|
+
cd pgvector
|
|
41
|
+
make
|
|
42
|
+
sudo make install
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3. Create Database and Enable Extensions
|
|
32
46
|
|
|
33
47
|
```bash
|
|
34
|
-
#
|
|
35
|
-
|
|
48
|
+
# Create the development database
|
|
49
|
+
createdb htm_development
|
|
36
50
|
|
|
37
|
-
#
|
|
38
|
-
|
|
51
|
+
# Enable required extensions
|
|
52
|
+
psql htm_development -c "CREATE EXTENSION IF NOT EXISTS vector;"
|
|
53
|
+
psql htm_development -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
54
|
+
|
|
55
|
+
# Verify extensions
|
|
56
|
+
psql htm_development -c "SELECT extname, extversion FROM pg_extension;"
|
|
39
57
|
```
|
|
40
58
|
|
|
41
|
-
### 4.
|
|
59
|
+
### 4. Set Environment Variable
|
|
42
60
|
|
|
43
61
|
```bash
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
```
|
|
62
|
+
# Add to your ~/.bashrc or ~/.zshrc
|
|
63
|
+
export HTM_DBURL="postgresql://postgres@localhost:5432/htm_development"
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
# Or for a specific user with password
|
|
66
|
+
export HTM_DBURL="postgresql://username:password@localhost:5432/htm_development"
|
|
67
|
+
```
|
|
49
68
|
|
|
50
|
-
|
|
69
|
+
### 5. Verify Connection
|
|
51
70
|
|
|
52
71
|
```bash
|
|
53
|
-
|
|
72
|
+
cd /path/to/HTM
|
|
73
|
+
ruby test_connection.rb
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
You should see:
|
|
77
|
+
```
|
|
78
|
+
✓ Connected successfully!
|
|
79
|
+
✓ pgvector Extension: Version 0.8.x
|
|
80
|
+
✓ pg_trgm Extension: Version 1.6
|
|
54
81
|
```
|
|
55
82
|
|
|
56
|
-
##
|
|
83
|
+
## Ollama Setup
|
|
57
84
|
|
|
58
|
-
|
|
85
|
+
HTM uses RubyLLM with the Ollama provider for generating embeddings. You need to install and run Ollama locally.
|
|
59
86
|
|
|
60
|
-
|
|
87
|
+
### 1. Install Ollama
|
|
61
88
|
|
|
89
|
+
**macOS:**
|
|
62
90
|
```bash
|
|
63
|
-
|
|
64
|
-
source ~/.bashrc__tiger
|
|
91
|
+
curl https://ollama.ai/install.sh | sh
|
|
65
92
|
```
|
|
66
93
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
### 2. Verify Connection
|
|
94
|
+
**Or download from:** https://ollama.ai/download
|
|
70
95
|
|
|
71
|
-
|
|
96
|
+
### 2. Start Ollama Service
|
|
72
97
|
|
|
73
98
|
```bash
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
# Ollama typically starts automatically after installation
|
|
100
|
+
# Verify it's running:
|
|
101
|
+
curl http://localhost:11434/api/version
|
|
76
102
|
```
|
|
77
103
|
|
|
78
|
-
|
|
104
|
+
### 3. Pull Required Models
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Pull the embedding model
|
|
108
|
+
ollama pull nomic-embed-text
|
|
109
|
+
|
|
110
|
+
# Pull the chat model (for tag extraction)
|
|
111
|
+
ollama pull llama3
|
|
112
|
+
|
|
113
|
+
# Verify models are available
|
|
114
|
+
ollama list
|
|
79
115
|
```
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
116
|
+
|
|
117
|
+
### 4. Test Embedding Generation
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Test that embeddings work
|
|
121
|
+
curl http://localhost:11434/api/embeddings -d '{
|
|
122
|
+
"model": "nomic-embed-text",
|
|
123
|
+
"prompt": "Hello, world!"
|
|
124
|
+
}'
|
|
84
125
|
```
|
|
85
126
|
|
|
86
|
-
###
|
|
127
|
+
### Optional: Custom Ollama URL
|
|
87
128
|
|
|
88
|
-
|
|
129
|
+
If Ollama is running on a different host/port, set the environment variable:
|
|
89
130
|
|
|
90
131
|
```bash
|
|
91
|
-
|
|
132
|
+
export OLLAMA_URL="http://custom-host:11434"
|
|
92
133
|
```
|
|
93
134
|
|
|
94
135
|
## Environment Variables Reference
|
|
95
136
|
|
|
96
|
-
After sourcing `~/.bashrc__tiger`, these variables are available:
|
|
97
|
-
|
|
98
137
|
| Variable | Description | Example Value |
|
|
99
138
|
|----------|-------------|---------------|
|
|
100
|
-
| `
|
|
101
|
-
| `HTM_DBNAME` | Database name | `
|
|
102
|
-
| `HTM_DBUSER` | Database user | `
|
|
103
|
-
| `HTM_DBPASS` | Database password |
|
|
104
|
-
| `
|
|
105
|
-
| `HTM_DBPORT` | Database port | `
|
|
139
|
+
| `HTM_DBURL` | Full PostgreSQL connection URL (preferred) | `postgresql://postgres@localhost:5432/htm_development` |
|
|
140
|
+
| `HTM_DBNAME` | Database name (fallback) | `htm_development` |
|
|
141
|
+
| `HTM_DBUSER` | Database user (fallback) | `postgres` |
|
|
142
|
+
| `HTM_DBPASS` | Database password (fallback) | `` |
|
|
143
|
+
| `HTM_DBHOST` | Database host (fallback) | `localhost` |
|
|
144
|
+
| `HTM_DBPORT` | Database port (fallback) | `5432` |
|
|
145
|
+
| `OLLAMA_URL` | Ollama server URL | `http://localhost:11434` |
|
|
106
146
|
|
|
107
147
|
## Development Workflow
|
|
108
148
|
|
|
109
149
|
### Quick Start
|
|
110
150
|
|
|
111
151
|
```bash
|
|
112
|
-
# 1.
|
|
113
|
-
|
|
152
|
+
# 1. Set database URL (if not in shell config)
|
|
153
|
+
export HTM_DBURL="postgresql://postgres@localhost:5432/htm_development"
|
|
114
154
|
|
|
115
|
-
# 2. Install dependencies
|
|
155
|
+
# 2. Install dependencies
|
|
116
156
|
bundle install
|
|
117
157
|
|
|
118
|
-
# 3. Initialize database schema
|
|
119
|
-
|
|
158
|
+
# 3. Initialize database schema
|
|
159
|
+
rake db_setup
|
|
160
|
+
|
|
161
|
+
# 4. Run tests
|
|
162
|
+
rake test
|
|
120
163
|
|
|
121
|
-
#
|
|
164
|
+
# 5. Try the basic example
|
|
122
165
|
ruby examples/basic_usage.rb
|
|
123
166
|
```
|
|
124
167
|
|
|
@@ -130,10 +173,8 @@ HTM uses Minitest for testing:
|
|
|
130
173
|
# Run all tests
|
|
131
174
|
rake test
|
|
132
175
|
|
|
133
|
-
# Or run directly with Ruby
|
|
134
|
-
ruby test/htm_test.rb
|
|
135
|
-
|
|
136
176
|
# Run specific test file
|
|
177
|
+
ruby test/htm_test.rb
|
|
137
178
|
ruby test/embedding_service_test.rb
|
|
138
179
|
|
|
139
180
|
# Run integration tests (requires database)
|
|
@@ -150,14 +191,18 @@ HTM/
|
|
|
150
191
|
│ │ ├── database.rb # Database setup and schema
|
|
151
192
|
│ │ ├── long_term_memory.rb # PostgreSQL-backed storage
|
|
152
193
|
│ │ ├── working_memory.rb # In-memory active context
|
|
153
|
-
│ │ ├── embedding_service.rb # RubyLLM embedding generation
|
|
194
|
+
│ │ ├── embedding_service.rb # RubyLLM embedding generation
|
|
195
|
+
│ │ ├── tag_service.rb # Hierarchical tag extraction
|
|
196
|
+
│ │ ├── configuration.rb # Multi-provider LLM config
|
|
154
197
|
│ │ └── version.rb # Version constant
|
|
155
|
-
├──
|
|
198
|
+
├── config/
|
|
199
|
+
│ └── database.yml # Database configuration
|
|
200
|
+
├── db/
|
|
156
201
|
│ └── schema.sql # Database schema
|
|
157
202
|
├── test/
|
|
158
203
|
│ ├── test_helper.rb # Minitest configuration
|
|
159
204
|
│ ├── htm_test.rb # Basic HTM tests
|
|
160
|
-
│ ├── embedding_service_test.rb # Embedding tests
|
|
205
|
+
│ ├── embedding_service_test.rb # Embedding tests
|
|
161
206
|
│ └── integration_test.rb # Full integration tests
|
|
162
207
|
├── examples/
|
|
163
208
|
│ └── basic_usage.rb # Basic usage example
|
|
@@ -165,24 +210,12 @@ HTM/
|
|
|
165
210
|
├── enable_extensions.rb # Enable PostgreSQL extensions
|
|
166
211
|
├── SETUP.md # This file
|
|
167
212
|
├── README.md # Project overview
|
|
168
|
-
├──
|
|
213
|
+
├── CLAUDE.md # AI assistant instructions
|
|
169
214
|
├── Gemfile
|
|
170
215
|
├── htm.gemspec
|
|
171
216
|
└── Rakefile # Rake tasks
|
|
172
217
|
```
|
|
173
218
|
|
|
174
|
-
## Next Steps
|
|
175
|
-
|
|
176
|
-
1. **Phase 1**: Create basic gem structure
|
|
177
|
-
2. **Phase 2**: Implement database schema
|
|
178
|
-
3. **Phase 3**: Implement LongTermMemory class
|
|
179
|
-
4. **Phase 4**: Implement WorkingMemory class
|
|
180
|
-
5. **Phase 5**: Implement HTM main class
|
|
181
|
-
6. **Phase 6**: Add tests
|
|
182
|
-
7. **Phase 7**: Create examples
|
|
183
|
-
|
|
184
|
-
See `htm_teamwork.md` for detailed roadmap.
|
|
185
|
-
|
|
186
219
|
## Troubleshooting
|
|
187
220
|
|
|
188
221
|
### Ollama Issues
|
|
@@ -193,24 +226,20 @@ If you encounter embedding errors:
|
|
|
193
226
|
# Verify Ollama is running
|
|
194
227
|
curl http://localhost:11434/api/version
|
|
195
228
|
|
|
196
|
-
# Check if
|
|
197
|
-
ollama list
|
|
229
|
+
# Check if models are available
|
|
230
|
+
ollama list
|
|
198
231
|
|
|
199
232
|
# Test embedding generation
|
|
200
|
-
|
|
233
|
+
curl http://localhost:11434/api/embeddings -d '{"model": "nomic-embed-text", "prompt": "Test"}'
|
|
201
234
|
|
|
202
|
-
# View Ollama logs
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
# Restart Ollama service
|
|
206
|
-
# On macOS, Ollama runs as a background service
|
|
207
|
-
# Check Activity Monitor or restart from the menu bar
|
|
235
|
+
# View Ollama logs (macOS)
|
|
236
|
+
# Check Console.app or Activity Monitor
|
|
208
237
|
```
|
|
209
238
|
|
|
210
239
|
**Common Ollama Errors:**
|
|
211
240
|
|
|
212
241
|
- **"connection refused"**: Ollama service is not running. Start Ollama from Applications or via CLI.
|
|
213
|
-
- **"model not found"**: Run `ollama pull
|
|
242
|
+
- **"model not found"**: Run `ollama pull nomic-embed-text` to download the model.
|
|
214
243
|
- **Custom URL not working**: Ensure `OLLAMA_URL` environment variable is set correctly.
|
|
215
244
|
|
|
216
245
|
### Database Connection Issues
|
|
@@ -218,14 +247,15 @@ ollama logs
|
|
|
218
247
|
If you get connection errors:
|
|
219
248
|
|
|
220
249
|
```bash
|
|
221
|
-
# Verify environment
|
|
250
|
+
# Verify environment variable is set
|
|
222
251
|
echo $HTM_DBURL
|
|
223
252
|
|
|
224
253
|
# Test connection manually
|
|
225
|
-
psql $HTM_DBURL
|
|
254
|
+
psql $HTM_DBURL -c "SELECT 1"
|
|
226
255
|
|
|
227
|
-
# Check
|
|
228
|
-
grep
|
|
256
|
+
# Check PostgreSQL is running
|
|
257
|
+
brew services list | grep postgresql # macOS
|
|
258
|
+
systemctl status postgresql # Linux
|
|
229
259
|
```
|
|
230
260
|
|
|
231
261
|
### Extension Issues
|
|
@@ -233,31 +263,32 @@ grep "bashrc__tiger" ~/.bashrc
|
|
|
233
263
|
If extensions aren't available:
|
|
234
264
|
|
|
235
265
|
```bash
|
|
266
|
+
# Check if pgvector is installed
|
|
267
|
+
psql htm_development -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
|
|
268
|
+
|
|
236
269
|
# Re-run extension setup
|
|
237
270
|
ruby enable_extensions.rb
|
|
238
271
|
|
|
239
|
-
# Check extension status
|
|
240
|
-
psql
|
|
272
|
+
# Check extension status
|
|
273
|
+
psql htm_development -c "SELECT extname, extversion FROM pg_extension ORDER BY extname"
|
|
241
274
|
```
|
|
242
275
|
|
|
243
|
-
###
|
|
276
|
+
### Test Database
|
|
244
277
|
|
|
245
|
-
|
|
278
|
+
For running tests, create a separate test database:
|
|
246
279
|
|
|
247
280
|
```bash
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
# Should show: sslmode=require
|
|
281
|
+
createdb htm_development_test
|
|
282
|
+
psql htm_development_test -c "CREATE EXTENSION IF NOT EXISTS vector; CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
|
251
283
|
```
|
|
252
284
|
|
|
253
285
|
## Resources
|
|
254
286
|
|
|
255
287
|
- **Ollama**: https://ollama.ai/
|
|
256
|
-
- **RubyLLM**: https://github.com/
|
|
257
|
-
- **TimescaleDB Docs**: https://docs.timescale.com/
|
|
288
|
+
- **RubyLLM**: https://github.com/crmne/ruby_llm
|
|
258
289
|
- **pgvector Docs**: https://github.com/pgvector/pgvector
|
|
259
|
-
- **Planning Document**: `htm_teamwork.md`
|
|
260
290
|
- **PostgreSQL Docs**: https://www.postgresql.org/docs/
|
|
291
|
+
- **Planning Document**: `htm_teamwork.md`
|
|
261
292
|
|
|
262
293
|
## Support
|
|
263
294
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddContentHashToNodes < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
unless column_exists?(:nodes, :content_hash)
|
|
6
|
+
# Add content_hash column for SHA-256 hash of content (64 hex characters)
|
|
7
|
+
add_column :nodes, :content_hash, :string, limit: 64,
|
|
8
|
+
comment: 'SHA-256 hash of content for deduplication'
|
|
9
|
+
|
|
10
|
+
# Unique index to prevent duplicate content
|
|
11
|
+
add_index :nodes, :content_hash, unique: true, name: 'idx_nodes_content_hash_unique'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateRobotNodes < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
unless table_exists?(:robot_nodes)
|
|
6
|
+
create_table :robot_nodes, comment: 'Join table connecting robots to nodes (many-to-many)' do |t|
|
|
7
|
+
t.bigint :robot_id, null: false, comment: 'ID of the robot that remembered this node'
|
|
8
|
+
t.bigint :node_id, null: false, comment: 'ID of the node being remembered'
|
|
9
|
+
t.timestamptz :first_remembered_at, default: -> { 'CURRENT_TIMESTAMP' },
|
|
10
|
+
comment: 'When this robot first remembered this content'
|
|
11
|
+
t.timestamptz :last_remembered_at, default: -> { 'CURRENT_TIMESTAMP' },
|
|
12
|
+
comment: 'When this robot last tried to remember this content'
|
|
13
|
+
t.integer :remember_count, default: 1, null: false,
|
|
14
|
+
comment: 'Number of times this robot has tried to remember this content'
|
|
15
|
+
t.timestamptz :created_at, default: -> { 'CURRENT_TIMESTAMP' }
|
|
16
|
+
t.timestamptz :updated_at, default: -> { 'CURRENT_TIMESTAMP' }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Unique constraint: each robot can only link to a node once
|
|
20
|
+
add_index :robot_nodes, [:robot_id, :node_id], unique: true, name: 'idx_robot_nodes_unique'
|
|
21
|
+
add_index :robot_nodes, :robot_id, name: 'idx_robot_nodes_robot_id'
|
|
22
|
+
add_index :robot_nodes, :node_id, name: 'idx_robot_nodes_node_id'
|
|
23
|
+
add_index :robot_nodes, :last_remembered_at, name: 'idx_robot_nodes_last_remembered_at'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Add foreign keys
|
|
27
|
+
unless foreign_key_exists?(:robot_nodes, :robots, column: :robot_id)
|
|
28
|
+
add_foreign_key :robot_nodes, :robots, column: :robot_id, primary_key: :id, on_delete: :cascade
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
unless foreign_key_exists?(:robot_nodes, :nodes, column: :node_id)
|
|
32
|
+
add_foreign_key :robot_nodes, :nodes, column: :node_id, primary_key: :id, on_delete: :cascade
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RemoveSourceAndRobotIdFromNodes < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
# Remove foreign key constraint first
|
|
6
|
+
if foreign_key_exists?(:nodes, :robots, column: :robot_id)
|
|
7
|
+
remove_foreign_key :nodes, :robots, column: :robot_id
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Remove indexes
|
|
11
|
+
if index_exists?(:nodes, :robot_id, name: 'idx_nodes_robot_id')
|
|
12
|
+
remove_index :nodes, name: 'idx_nodes_robot_id'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
if index_exists?(:nodes, :source, name: 'idx_nodes_source')
|
|
16
|
+
remove_index :nodes, name: 'idx_nodes_source'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Remove columns
|
|
20
|
+
if column_exists?(:nodes, :robot_id)
|
|
21
|
+
remove_column :nodes, :robot_id
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if column_exists?(:nodes, :source)
|
|
25
|
+
remove_column :nodes, :source
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateWorkingMemories < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
create_table :working_memories, comment: 'Per-robot working memory state (optional persistence)' do |t|
|
|
6
|
+
t.bigint :robot_id, null: false, comment: 'Robot whose working memory this belongs to'
|
|
7
|
+
t.bigint :node_id, null: false, comment: 'Node currently in working memory'
|
|
8
|
+
t.timestamptz :added_at, default: -> { 'CURRENT_TIMESTAMP' }, comment: 'When node was added to working memory'
|
|
9
|
+
t.integer :token_count, comment: 'Cached token count for budget tracking'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
add_index :working_memories, :robot_id, name: 'idx_working_memories_robot_id'
|
|
13
|
+
add_index :working_memories, :node_id, name: 'idx_working_memories_node_id'
|
|
14
|
+
add_index :working_memories, [:robot_id, :node_id], unique: true, name: 'idx_working_memories_unique'
|
|
15
|
+
|
|
16
|
+
add_foreign_key :working_memories, :robots, on_delete: :cascade
|
|
17
|
+
add_foreign_key :working_memories, :nodes, on_delete: :cascade
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RemoveUnusedColumns < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
# Remove in_working_memory from nodes - now tracked per-robot in working_memories table
|
|
6
|
+
remove_index :nodes, name: 'idx_nodes_in_working_memory', if_exists: true
|
|
7
|
+
remove_column :nodes, :in_working_memory, :boolean, default: false
|
|
8
|
+
|
|
9
|
+
# Remove unused metadata column from robots
|
|
10
|
+
remove_column :robots, :metadata, :jsonb
|
|
11
|
+
end
|
|
12
|
+
end
|