Project Files
src / memory / constants.ts
/**
* @file constants.ts
* Single source of truth for every tunable parameter.
* Grouped by subsystem for easy discovery.
*/
export const DB_FILENAME = "memory.db";
export const MAX_MEMORIES_TOTAL = 10_000;
export const MAX_MEMORY_CONTENT_LENGTH = 4_000;
export const MAX_TAGS_PER_MEMORY = 10;
export const MAX_TAG_LENGTH = 50;
export const MAX_CATEGORY_LENGTH = 30;
/** Default number of memories injected into prompt context. */
export const DEFAULT_CONTEXT_MEMORIES = 5;
/** Maximum memories that can be injected per prompt. */
export const MAX_CONTEXT_MEMORIES = 15;
/** Default number returned by explicit Recall/Search tools. */
export const DEFAULT_SEARCH_RESULTS = 8;
/** Maximum results from a single search/recall. */
export const MAX_SEARCH_RESULTS = 25;
/** Minimum TF-IDF similarity score to surface a memory (0–1). */
export const MIN_RELEVANCE_THRESHOLD = 0.05;
/** Minimum query length (chars) for semantic search. */
export const MIN_QUERY_LENGTH = 2;
/** Stop words excluded from TF-IDF indexing (English + Portuguese). */
export const STOP_WORDS = new Set([
// English
"the", "a", "an", "is", "in", "of", "and", "or", "for", "to",
"how", "what", "why", "when", "does", "with", "from", "its",
"that", "this", "are", "was", "were", "be", "been", "being",
"have", "has", "had", "do", "did", "will", "would", "could",
"should", "may", "might", "shall", "can", "it", "he", "she",
"they", "we", "you", "i", "me", "my", "your", "our", "his",
"her", "their", "not", "no", "but", "if", "so", "at", "by",
"on", "up", "out", "about", "into", "over", "after", "before",
"between", "under", "again", "then", "here", "there", "all",
"each", "every", "both", "few", "more", "most", "other", "some",
"such", "than", "too", "very", "just", "also", "now",
// Portuguese
"que", "de", "do", "da", "dos", "das", "um", "uma", "uns", "umas",
"para", "com", "como", "por", "mais", "mas", "se", "na", "no",
"nos", "nas", "ao", "aos", "esse", "essa", "esses", "essas",
"este", "esta", "estes", "estas", "isso", "isto", "aquilo",
"ele", "ela", "eles", "elas", "eu", "tu", "nós", "vós",
"meu", "minha", "meus", "minhas", "seu", "sua", "seus", "suas",
"nosso", "nossa", "nossos", "nossas", "tem", "ter", "tinha",
"foi", "ser", "está", "estar", "são", "era", "eram", "será",
"seria", "pode", "poder", "vai", "vou", "vamos", "foram",
"quando", "onde", "quem", "qual", "quais", "porque", "porquê",
"muito", "muita", "muitos", "muitas", "bem", "mal", "sim",
"não", "já", "ainda", "aqui", "ali", "lá", "entre", "sobre",
"até", "sem", "depois", "antes", "então", "nem", "ou", "pois",
"assim", "mesmo", "só", "também", "cada", "todo", "toda",
"todos", "todas", "outro", "outra", "outros", "outras",
"voce", "você", "vocês", "gente", "coisa", "coisas",
]);
/** Minimum term length for TF-IDF indexing. */
export const MIN_TERM_LENGTH = 2;
/** Maximum vocabulary size for the TF-IDF index. */
export const MAX_VOCAB_SIZE = 50_000;
/** How many top terms per document to keep for scoring. */
export const MAX_TERMS_PER_DOC = 200;
/** Half-life of memory relevance decay in days. */
export const DECAY_HALF_LIFE_DAYS = 45;
/** Weight of recency in the composite retrieval score (0–1). */
export const DECAY_WEIGHT = 0.2;
/** Weight of access frequency in the composite retrieval score (0–1). */
export const FREQUENCY_WEIGHT = 0.1;
/** Weight of TF-IDF similarity in the composite retrieval score (0–1). */
export const SIMILARITY_WEIGHT = 0.55;
/** Weight of stored confidence score in the composite retrieval score (0–1). */
export const CONFIDENCE_WEIGHT = 0.10;
/** Weight of keyword overlap boost in the composite retrieval score (0–1). */
export const KEYWORD_BOOST_WEIGHT = 0.05;
/** Max tokens for L0 identity layer (always injected). */
export const L0_MAX_CHARS = 400;
/** Max tokens for L1 essential memories layer (always injected). */
export const L1_MAX_CHARS = 1600;
/** Number of top essential memories for L1 layer. */
export const L1_ESSENTIAL_COUNT = 5;
/** Max tokens for AI fact extraction calls. */
export const AI_EXTRACT_MAX_TOKENS = 800;
/** Temperature for AI fact extraction (low = factual). */
export const AI_EXTRACT_TEMPERATURE = 0.1;
/** Timeout for AI calls in ms. */
export const AI_CALL_TIMEOUT_MS = 12_000;
/** Max tokens for AI conflict detection. */
export const AI_CONFLICT_MAX_TOKENS = 400;
/** Temperature for conflict detection. */
export const AI_CONFLICT_TEMPERATURE = 0.1;
export const VALID_SCOPES = ["global", "project", "session"] as const;
export type MemoryScope = (typeof VALID_SCOPES)[number];
/** Max project name length. */
export const MAX_PROJECT_NAME_LENGTH = 60;
/** Max session memories (in-memory only, never persisted). */
export const MAX_SESSION_MEMORIES = 200;
export const VALID_CATEGORIES = [
"fact",
"preference",
"project",
"note",
"instruction",
"relationship",
"context",
"correction",
"reference",
"identity",
] as const;
export type MemoryCategory = (typeof VALID_CATEGORIES)[number];
/** Max chars of injected memory context (to avoid blowing up prompts). */
export const MAX_INJECTED_CONTEXT_CHARS = 5_000;
/** Separator between injected memories. */
export const MEMORY_SEPARATOR = "\n• ";