Hybrid vector search for Clawdie's long-term memory
All 5 phases finished. TypeScript + Bash pipelines ready.
8 commits pushed to Codeberg on 10.03.2026
+346 lines โ Bash scripts for memory operations
| File | Purpose |
|---|---|
scripts/memory/common.sh |
DB connection, dependency checks, config |
scripts/memory/embed.sh |
Generate 1536d embeddings via OpenRouter |
scripts/memory/chunk.sh |
Split text on sentence boundaries (~500 chars) |
scripts/memory/memory-pg.sh |
Full CLI: store/search/recent/important/count |
Pipeline: text โ chunk โ embed โ insert (fully automated)
+659 lines โ TypeScript integration
| File | Purpose |
|---|---|
src/memory-pg.ts |
PostgreSQL memory client (275 lines) |
src/memory-lifecycle.ts |
Memory lifecycle management |
src/memory-pg.test.ts |
Unit tests |
scripts/memory/memory-hydrate-pg.sh |
Populate MEMORY.md from PostgreSQL |
+189 lines โ Ansible automation
infra/ansible/playbooks/jail-create.yaml โ Automated jail creation (184 lines)host_vars/clawdie_host.yaml โ Host-specific variablessrc/config.ts+425 lines โ Step-by-step bootstrap guide
| Commit | Changes |
|---|---|
| 5d2e605 | Jail state tracking, European date format standard, ZFS naming convention |
| a502bd2 | RCTL prerequisites for jail memory limits |
| dcb3545 | bhyve/VMM prerequisites for future VM support |
| 050c93c | Core FreeBSD config docs (loader.conf, rc.conf) |
| Component | Status |
|---|---|
| PostgreSQL 17 | โ
Running in db jail with pgvector 0.8.1 |
| ai_brain Database | โ Created with extensions |
| Schema | โ memories, memory_chunks, memory_embeddings |
| Hybrid Search | โ
search_memories() function |
| Embedding API | โ OpenRouter text-embedding-3-large @ 1536d |
| Bash Scripts | โ memory-pg.sh, embed.sh, chunk.sh, common.sh |
| TypeScript Module | โ memory-pg.ts (275 lines) |
| Unit Tests | โ memory-pg.test.ts |
| Deployment Plan | โ test-deployment-plan.md (425 lines) |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Clawdie-AI Memory System โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ TypeScript โ โ Bash โ โ PostgreSQL โ โ
โ โ memory-pg.tsโ โ memory-pg.shโ โ ai_brain โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโดโโโโโโโโโ โ
โ โ Pipeline Flow โ โ
โ โโโโโโโโโโฌโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ โ
โ โผ โผ โผ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ chunk.sh โโโโโโบโ embed.sh โโโโโโบโ INSERT โ โ
โ โ Split 500c โ โ OpenRouter โ โ PostgreSQL โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ
โ Search: Hybrid RRF (full-text tsvector + vector cosine) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
docs/sql/ai-brain-base.sql โ Base memories tabledocs/sql/clawdie-brain-hybrid-upgrade.sql โ Chunks + embeddings| Property | Value |
|---|---|
| Provider | OpenRouter |
| Model | openai/text-embedding-3-large |
| Dimensions | 1536 |
| Cost | ~$0.13 / 1M tokens |
# Store (auto-chunks + embeds)
./scripts/memory/memory-pg.sh store "Summary text" "topic1,topic2" 3
# Hybrid search
./scripts/memory/memory-pg.sh search "query text" 10
# Recent memories
./scripts/memory/memory-pg.sh recent 5
# Important memories
./scripts/memory/memory-pg.sh important
-- search_memories() function
SELECT * FROM search_memories(
'query text',
'<embedding>'::vector,
10
);
-- Returns: memory_id, chunk_text, summary, importance, topics, combined_score
src/memory-pg.ts โ Connection pooling, chunking, embedding, searchsrc/memory-lifecycle.ts โ Lifecycle managementsrc/memory-pg.test.ts โ Unit tests# Store a memory
./scripts/memory/memory-pg.sh store \
"Discussed PGVector implementation with Sam" \
"postgres,vector,memory" \
3
# Search (hybrid: full-text + semantic)
./scripts/memory/memory-pg.sh search "database setup" 10
# Get recent memories
./scripts/memory/memory-pg.sh recent 5
# Get high-importance memories
./scripts/memory/memory-pg.sh important
# Count total memories
./scripts/memory/memory-pg.sh count
import { storeMemory, searchMemories, getRecentMemories } from './memory-pg.js';
// Store a memory (auto-chunks + embeds)
const memoryId = await storeMemory({
summary: 'Session about deploying PostgreSQL with pgvector',
topics: ['postgres', 'vector', 'deployment'],
importance: 3,
});
// Hybrid search
const results = await searchMemories('how did we set up the database', 10);
// Recent memories
const recent = await getRecentMemories(5);
| Phase | Task | Status |
|---|---|---|
| 1 | Database Schema | โ Done |
| 2 | Embedding Generation | โ Done |
| 3 | Memory Scripts (Bash) | โ Done |
| 4 | Hybrid Search Function | โ Done |
| 5 | TypeScript Integration | โ Done |
| Total | 5/5 Complete ๐ | |
docs/test-deployment-plan.md)ai_brain| Category | Files | Lines |
|---|---|---|
| Memory Scripts | 5 files in scripts/memory/ |
+480 |
| TypeScript | memory-pg.ts, memory-lifecycle.ts, memory-pg.test.ts | +410 |
| Ansible | jail-create.yaml, host-preflight.yaml, db-memory-bootstrap.yaml | +229 |
| Documentation | test-deployment-plan.md, loader-conf.md, rc-conf.md, etc. | +1,108 |
| Total | 27 files | +2,227 |