$ show tickernelz/opencode-mem
OpenCode-Mem is a plugin for OpenCode, an AI coding assistant, that provides persistent memory using vector embeddings and Turso/libSQL. It stores project-level technical memories (decisions, code facts, patterns) and learns user preferences/configs across sessions. The system uses local ONNX embeddings (or remote API) and supports multiple LLM providers (Anthropic, OpenAI, Google Gemini, MiniMax). It features auto-capture of session content, user profile learning with confidence decay, deduplication, and migration services. A full React web UI allows browsing, editing, and managing memories and user profiles. The architecture is modular: plugin entry, AI provider abstraction, Turso shard management, embedding service, web server, and shared API schemas. While primarily an application, it includes robust data pipeline patterns for vector search, ETL (migration), and user modeling.
The LLM identified 5 files worth highlighting for reuse:
Defines an abstract BaseAIProvider class with a generic tool-call execution loop, safe extra parameter filtering, and timeout handling. It standardizes the interface for all LLM providers (Anthropic, OpenAI, etc.), enabling easy addition of new backends. The pattern is reusable for any multi-provider AI integration.
Implements TursoVectorSearch with a hybrid scoring approach combining content vector (60%), tags vector (40%) and exact-match boosting. It uses libSQL's vector_top_k for ANN with fallback to exact scan. Over-fetches results and applies post-filter. This pattern is reusable for any vector-search system requiring multi-field scoring.
Provides memory export/import with a versioned JSON schema (schemaVersion: 1). Export includes all memories with embeddings; import is atomic via transactional insert and handles ID conflicts. The service validates schema versions and supports rollback. This pattern is reusable for any plugin needing portable data backups.
Uses an LLM to analyze user profile items (preferences, patterns, workflows) and produce a merge/delete mapping via JSON schema. Applies changes to the stored profile by merging duplicate entries and removing stale ones. The pattern is reusable for any system requiring AI-assisted data deduplication.
Defines Zod schemas for all API types (memory, user prompt, profile, migration, portability). These are used both server-side for request validation and client-side for type inference. The schemas are the single source of truth for the API contract, enabling safe cross-boundary data handling. The pattern is reusable for any TypeScript API with shared types.