skills/vectorize-context/SKILL.md
Manual vector DB for semantic search over .opencode/context/ — triggered via /harvest-context search
npx skillsauth add Thomashighbaugh/opencode vectorize-contextInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Indexes .opencode/context/ markdown files into a local sqlite-vec vector database for semantic search. Manual trigger only — invoked via /harvest-context search.
The system uses lazy freshness: every query automatically stats all context files, re-indexes only what changed, then searches. This covers every write path:
| Trigger | Behavior |
|---------|----------|
| Hub writes a new context/decision/pattern file | Next query picks it up automatically |
| /harvest-context saves research docs | Indexed on next query |
| /orchestrate completes and saves patterns | Indexed on next query |
| /ideation finalizes a plan to context | Indexed on next query |
| Direct .md file edit in .opencode/context/ | Indexed on next query |
| Full re-index needed | Delete .opencode/.vector/ — auto-rebuilds |
The ML model is only loaded when there's actual work to do (files changed). If everything is up to date, ensureIndexed() returns instantly with no model load.
| Script | Purpose |
|--------|---------|
| scripts/veclib.mjs | Shared library — exported programmatic API for all integrations |
| scripts/vectorize.mjs | CLI: manual re-index (for debugging/forced refresh) |
| scripts/query.mjs | CLI: semantic search over context |
Used by Hubs hub subcommands and agents:
// Lazy re-index: stats files, only loads model if something changed
import { ensureIndexed } from './veclib.mjs';
await ensureIndexed(); // current project
await ensureIndexed('/path/to/app'); // specific project
// Semantic search (auto-refreshes index first)
import { queryChunks } from './veclib.mjs';
const results = await queryChunks(undefined, 'auth patterns', 10);
// results: [{ source, heading, content, file_path, distance }]
// Index stats
import { getIndexStats } from './veclib.mjs';
const stats = await getIndexStats();
// { exists, totalChunks, totalFiles, files: [...] }
# Manual re-index (useful for debugging)
node {skill_dir}/scripts/vectorize.mjs
# Semantic search (auto-refreshes on every call)
node {skill_dir}/scripts/query.mjs "how does error handling work"
QUERY="auth patterns" node {skill_dir}/scripts/query.mjs
=== Search Results ===
1. patterns/error-handling.md — Error Patterns (score: 0.71)
Error handling follows a centralized approach with...
[file: .opencode/context/patterns/error-handling.md]
2. frameworks/architecture.md — System Design (score: 0.64)
The project follows a layered architecture...
[file: .opencode/context/frameworks/architecture.md]
npm install better-sqlite3 sqlite-vec @xenova/transformers
Requires Node.js 18+ and ~200MB RAM for the embedding model (loaded lazily only when indexing).
After any hub subcommand writes to .opencode/context/:
/harvest-context search to index and query — no automatic indexingAgents can use queryChunks() to retrieve relevant context during execution:
const ctx = await queryChunks(process.cwd() + '/.opencode', query, 5);
// Inject results into agent context as supporting evidence
rm -rf .opencode/.vector/ # Delete the DB
# Next query or ensureIndexed() call auto-rebuilds it
ensureIndexed() scans .opencode/context/ for *.md files##/### headersXenova/all-MiniLM-L6-v2The vec0 virtual table uses L2 distance. Since embeddings are normalized (unit vectors), L2 distance sorts equivalently to cosine similarity — nearest neighbors are the most semantically similar chunks.
tools
Create valid, type-safe TypeScript tools for OpenCode — generates correct boilerplate, typed interfaces, and handler stubs. Use when building new tools for global config or per-project .opencode/tools/.
testing
Explore multiple solution branches in parallel, evaluate each, and recommend the best path. Use when the user explicitly invokes /ideation tree-of-thoughts or asks for "tree of thought" / "branching exploration".
testing
Run multiple independent reasoning passes and find consensus. Use when the decision is critically important, the stakes are high, or the user explicitly requests "run it multiple times" / "check consistency" / "self-consistency".
testing
Optimization by PROmpting — generate candidate prompt variations, test each against a benchmark, and report the best performer. Use when the user invokes /ideation opro or asks for "prompt optimization" / "OPRO".