To migrate your database from SQLite to pgembed, follow these steps:
uv run migrate_opencode.pyThis will migrate your SQLite database from ~/.local/share/opencode/opencode.db to the pgdata directory.
Found unescaped \u0000 (null bytes, the literal string \u0000) and \ which should be escaped as \\
uv run check_json.py
uv run check_json.py --fixThe --fix flag will also convert the message.data column to JSONB.
Create pgvector HNSW indexes on session titles and message summaries:
uv run index_pgdata.pyThis will:
- Load the
BAAI/bge-small-en-v1.5embedding model - Generate 384-dimensional vectors for session titles
- Generate vectors for message
summary.titlefields - Create HNSW indexes for fast similarity search
Note: This step can take several minutes depending on your data size. Progress bars will show indexing status.
uv run start_db.pyIn another shell, you can run psql commands.
# Search similar sessions
uv run python query_pgvector.py "database migration" --sessions
# Search messages by model
uv run python query_pgvector.py "debug error" --model minimax-m2.1-free
# Search by agent type
uv run python query_pgvector.py "fix bug" --agent build
# Search with date range
uv run python query_pgvector.py "vcpkg setup" --start-time "2025-01-01 00:00:00"
# With similarity threshold
uv run python query_pgvector.py "graph creation" --min-similarity 0.8--sessions: Search session titles instead of messages--model <modelID>: Filter by model (e.g.,minimax-m2.1-free)--agent <agent>: Filter by agent type (build,explore,general,plan)--start-time/--end-time: Filter by date range--min-similarity <0-1>: Minimum similarity threshold--limit <n>: Number of results (default: 5)