Skip to content

Memory

Two independent memory systems, often confused. This page distinguishes them.

1. Core memory — manage_core_memory tool

Section titled “1. Core memory — manage_core_memory tool”

The tool the LLM calls when you say “remember that…” or when it proactively wants to record a fact. Simple by design.

Storage: two plain JSON files.

ScopePathSurvives
user~/.codebuddy/user-memory.jsonAll workspaces, all conversations
project<workspace>/.codebuddy/memory.jsonConversations in this workspace

Entry shape:

interface MemoryEntry {
id: string; // Random 7-char UUID
category: "Knowledge" | "Rule" | "Experience";
content: string;
title: string;
keywords: string; // Pipe-separated
scope: "user" | "project";
timestamp: number; // ms
}

Categories:

CategoryPurpose
KnowledgeFacts, conventions, architecture decisions
RuleAlways/never coding standards
ExperienceLessons learned from past debugging or refactoring

Actions:

ActionRequiredBehavior
addcontent, category, title, scopeCreate; random ID assigned
updateid + any changed fieldsFinds the entry across both scopes; updates in place
deleteidRemoves wherever it lives
searchquery?Case-insensitive substring match on title, content, keywords. Returns all if no query.

Write safety: per-file FileMutex serializes concurrent writes. Atomic write-temp-rename to prevent corrupt JSON on crash.

Injection into the prompt: MemoryTool.getFormattedMemories() runs once at agent construction. All entries land in the system prompt from the first message onward. Not re-read per turn — restart the extension to pick up new entries added outside the agent (rare).

When the agent saves proactively: its system prompt instructs it to remember your name, role, coding preferences, project conventions, and anything explicitly flagged with “remember this.”

No ranking, no vector search, no MMR. Core memory is deliberately simple — a JSON store the LLM reads whole. Fancy retrieval lives in system 2 below.

2. Workspace-content search — search_vector_db tool

Section titled “2. Workspace-content search — search_vector_db tool”

Separate system. Indexes your code, not your memories.

  • HNSW vector index via hnsw-index.ts — semantic search over file chunks.
  • BM25 keyword index (SQLite FTS4) — exact-term matching.
  • Score fusion — weighted merge: 0.7 × vector + 0.3 × BM25.
  • Temporal decay — recent code weighted higher (temporal-decay.ts).
  • MMR re-rankingmmr.ts — reduces redundant results.
  • Rerankerreranker.ts — final quality pass.

Storage: SQLite at <workspace>/.codebuddy/vector_store.db. Populated by AstIndexingService walking the workspace on activation.

The agent calls this via search_vector_db when it needs “find code semantically similar to X.” Not the same as manage_core_memory — you can’t save_memory into the vector store, and the LLM’s remembered facts don’t go there.

There’s also an in-process key/value cache (src/memory/base.ts) with a 30-min TTL, used for chat-history snapshots and other per-session state. Not user-facing — mentioned here so nobody reading the source is confused when they see three things called “memory.”

FileWhat
src/tools/memory.tsmanage_core_memory tool — the JSON store
src/memory/base.tsIn-process session cache (30-min TTL)
src/memory/hybrid-search.service.tsWorkspace-content search orchestrator
src/memory/hnsw-index.tsVector index
src/memory/mmr.tsMMR diversity re-ranking
src/memory/reranker.tsPost-fusion quality pass
src/memory/temporal-decay.tsRecency bias for workspace search
src/memory/chat-history-cache.tsChat-history persistence