GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Rex-yer/opencode-mem-local: OpenCode plugin that gives coding agents persistent memory using local vector database

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

5 Commits
5 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
scripts
scripts
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
AGENTS.md
AGENTS.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bun.lock
bun.lock
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

OpenCode Memory

GitHub license

OpenCode Memory Banner

A persistent memory system for AI coding agents that enables long-term context retention across sessions using local vector database technology.

Visual Overview

Project Memory Timeline:

Project Memory Timeline

Core Features

  • Local vector database with SQLite + USearch-first vector indexing and ExactScan fallback
  • Project memory and global memory: project memories are tied to a directory and carry a display path; global memories are personal and shared across all projects
  • Full-featured web UI (project / global views) for browsing and managing memories
  • Auto-injects recent project memories into chat context (chatMessage hook)
  • Multi-keyword search with tag-aware scoring
  • memory tool: add / search / list / get / forget / help
  • Automatic schema migrations (idempotent, run at startup)

Prerequisites

This plugin uses USearch for preferred in-memory vector indexing with automatic ExactScan fallback. No custom SQLite build or browser runtime shim is required.

Recommended runtime:

  • Bun
  • Standard OpenCode plugin environment
  • Internet access on first use if you use the default local embedding model, because the model is downloaded by @huggingface/transformers
  • For source/development installs, run bun install before building. The published plugin package installs its runtime dependencies automatically through OpenCode.

Notes:

  • If USearch is unavailable or fails at runtime, the plugin automatically falls back to exact vector scanning.
  • SQLite remains the source of truth; search indexes are rebuilt from SQLite data when needed.

Getting Started

Add to your OpenCode configuration at ~/.config/opencode/opencode.json:

{
  "plugin": ["opencode-mem"],
}

The plugin downloads automatically on next startup.

Usage Examples

memory({ mode: "add", content: "Project uses microservices architecture" }); // saves to the current project (default)
memory({ mode: "add", content: "I prefer Vim keybindings", scope: "global" }); // saves to global (personal) memory
memory({ mode: "search", query: "architecture decisions" });
memory({ mode: "list", limit: 10 });
memory({ mode: "get", memoryId: "mem_..." }); // fetch one memory by id
memory({ mode: "forget", memoryId: "mem_..." }); // delete a memory by id

Access the web interface at http://127.0.0.1:4747 for visual memory browsing and management.

Configuration Essentials

Configure at ~/.config/opencode/opencode-mem.jsonc:

The plugin creates a full commented template at this path on first startup. This trimmed example shows the most common settings:

{
  "storagePath": "~/.opencode-mem/data",
  "userEmailOverride": "[email protected]",
  "userNameOverride": "John Doe",
  "embeddingModel": "Xenova/nomic-embed-text-v1",
  // Optional OpenAI-compatible embedding endpoint:
  // "embeddingApiUrl": "https://api.openai.com/v1",
  // "embeddingApiKey": "env://OPENAI_API_KEY",
  // "embeddingModel": "text-embedding-3-small",

  "webServerEnabled": true,
  "webServerPort": 4747,

  "showErrorToasts": true,
  "logLevel": "info",

  "maxMemories": 10,
  "perTokenLimit": 3,
  "similarityThreshold": 60,

  "chatMessage": {
    "enabled": true,
    "maxMemories": 3,
    "injectOn": "first",
    "maxAgeDays": undefined,
  },
}

Memory Scope

  • scope: "project" (default): save to the current project's memory.
  • scope: "global": save to global (personal) memory.
  • Queries (search / list) always merge global memory with the current project memory — there is no scope filter for queries.

Search Scoring

Memory search uses a multi-keyword approach with the following scoring formula:

最终分数 = contentSim × 0.5 + finalTagsSim × 0.5
  • contentSim: Semantic similarity between query and memory content (0-100)
  • tagsSim: Semantic similarity between query and memory tags (0-100)
  • exactMatchBoost: Exact/substring match of query words to tags (0-1)
  • finalTagsSim: max(tagsSim, exactMatchBoost) - takes the higher of semantic or exact match

Multi-keyword search: Queries are tokenized by spaces/commas. Each token runs a separate sub-query (limited by perTokenLimit), then results are merged and deduplicated.

Example:

  • Query "编程" → "编程基础" (exactMatchBoost=1.0) → score 77
  • Query "天气" → no tag match → score ≤13 (filtered by threshold)

Sharing One Project Memory Across Nested Repos

By default a project is identified by its enclosing git repository, so every physical git repo gets its own isolated memory store. That is wrong for multi-repo workspaces — trees managed by Google repo, monorepos, or any layout where several nested git repositories belong to one logical project — because each sub-repository would be siloed.

Drop an empty .opencode-mem-project marker file at the workspace root:

my-workspace/
├── .opencode-mem-project   ← workspace root
├── kernel/                 (own git repo)
├── userspace/              (own git repo)
└── tools/                  (own git repo)

Every session started anywhere underneath the marker then resolves onto that root and shares one memory store, regardless of which sub-repo the working directory lives in:

touch ~/my-workspace/.opencode-mem-project

The marker is looked up by walking up from the working directory that every code path already passes in (the plugin's working directory, the web API's process.cwd()), so identity is directory-driven and process-independent. It does not rely on environment variables or a global config value. The marker takes precedence over git detection. Without a marker, behavior is unchanged (git-based identity).

Public Subpath Exports

In addition to the main plugin entry, opencode-mem exposes one stable subpath that other opencode plugins can import directly:

opencode-mem/tags

Canonical scope helpers used by opencode-mem itself to resolve project/global memory identity from the working directory.

import {
  getScopes,
  getProjectScopeInfo,
  getGlobalScopeInfo,
  extractScopeTag,
} from "opencode-mem/tags";

// Resolve the current directory's project + global scope in one call.
const scopes = getScopes(process.cwd());
// scopes.project.scopeTag => "opencode_project_<hash>"
// scopes.global.scopeTag  => "opencode_global_<hash>"

// Project scope for an arbitrary directory.
const project = getProjectScopeInfo(process.cwd());

// Global (personal) scope, derived from git user name/email.
const global = getGlobalScopeInfo();

// Parse a scope tag back into its parts.
const { scope, hash } = extractScopeTag("opencode_project_6077b54e38c72a18");
// => { scope: "project", hash: "6077b54e38c72a18" }

Scope tags always look like opencode_project_<hash> or opencode_global_<hash>. Hand-rolled tags whose substring isn't _project_ or _global_ end up in shadow shards that /api/stats and /api/memories silently filter out — using these helpers avoids that pitfall.

Development & Contribution

Build and test locally:

bun install
bun run build
bun run typecheck
bun run format

If you hit a blocker or have improvement ideas, submit a pull request.

License & Links

MIT License - see LICENSE file

  • Repository: https://github.com/Rex-yer/opencode-mem-local
  • Issues: https://github.com/Rex-yer/opencode-mem-local/issues
  • OpenCode Platform: https://opencode.ai

Inspired by opencode-supermemory

About

OpenCode plugin that gives coding agents persistent memory using local vector database

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.