@mounaji_npm/learning-core
v0.1.2
Published
The neural weighting engine as a reusable, root-parameterized library — Hebbian/gradient learning over intents, collections and skills with recency decay, co-occurrence and feedback, plus injectable onEvent and export/import state. Extracted from mcp-moun
Maintainers
Readme
@mounaji_npm/learning-core
The neural weighting engine as a reusable, root-parameterized library,
extracted from mcp-mounaji-rag. It learns which intents, collections and
skills matter — from search frequency, feedback, recency decay and
co-occurrence — and turns those weights into boost multipliers via a sigmoid.
Zero runtime dependencies (Node built-ins only).
What changed vs. the MCP's internal copy
- Root is a constructor argument (not
process.env.YOAGENT_ROOT), so many agents can each own an isolated engine — e.g. an@mounaji_npm/agentfslearning/layer. onEventis injected instead of a hard-wireddispatchEvent.- Adds
exportState/importStatefor durability (Supabase mirror) and portability (Tier S export).
File names and formats are unchanged, so it reads/writes the same
intent_weights.json, collection_weights.json, etc. the MCP already uses.
Usage
import { createLearningEngine } from '@mounaji_npm/learning-core';
const engine = createLearningEngine({
root: '/data/agents/yoagent-abc/learning',
onEvent: (type, payload) => bus.emit(`learning.${type}`, payload), // optional
scopeContext: { agentId: 'abc' }, // optional
config: { learningRate: 0.15 }, // optional overrides
});
engine.processSearchEvent({
query: 'how does billing work',
intent: 'find_convention',
collections: ['mcp_conventions'],
skillsHit: ['billing-service'],
topScore: 0.82,
resultCount: 5,
feedback: 'positive', // optional: 'positive' | 'negative' | null
});
engine.getIntentBoost('find_convention', 1.2); // learned + base, clamped
engine.getWeightSnapshot(); // all weights + boosts for a UICompose with agentfs
import { createAgentFs } from '@mounaji_npm/agentfs';
import { createLearningEngine } from '@mounaji_npm/learning-core';
const fs = createAgentFs({ root, agentId });
const engine = createLearningEngine({ root: fs.layerPath('learning') });
// engine state now lives inside the agent's portable bundle.Durability
const state = engine.exportState(); // plain object → persist to Supabase
engine.importState(state); // rehydrate a fresh/ephemeral engineAPI
createLearningEngine(opts)/new LearningEngine(opts)—{ root, config?, onEvent?, scopeContext? }.processSearchEvent(params)— main entry point; updates all weights, records the pattern, tracks co-occurrence, emits asearchevent.updateIntentWeight / updateCollectionWeight / updateSkillWeight.getIntentBoost / getCollectionBoost / getSkillBoost / getLearnedKeywords.detectIntentWithLearning(query, rules)— base + learned + stem matching.learnKeywords / trackCoOccurrence / recordSearchPattern.getWeightSnapshot / getSearchPatternData.appendFeedback / readFeedbackLog.loadConfig / saveConfig,getDefaultLearningConfig().exportState() / importState(state).
Test
npm test # node --test