learn_context
Store preferences, rules, or context to reuse later, reducing token cost and enriching future prompts.
Instructions
Memorizes important information (preference, technical rule, context) for future use.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| information | Yes | The information to be remembered. | |
| category | No | Information category (e.g., 'preference', 'architecture', 'style'). |
Implementation Reference
- src/index.ts:89-108 (registration)Tool registration for 'learn_context' with description and inputSchema (information: string, category: optional string)
{ name: "learn_context", description: "Memorizes important information (preference, technical rule, context) for future use.", inputSchema: { type: "object", properties: { information: { type: "string", description: "The information to be remembered.", }, category: { type: "string", description: "Information category (e.g., 'preference', 'architecture', 'style').", }, }, required: ["information"], }, }, ], }; - src/index.ts:114-136 (handler)Handler for 'learn_context' tool: extracts 'information' and optional 'category' args, generates an embedding via Ollama, stores the vector + text + category + timestamp into a LanceDB table, and returns a confirmation message.
if (name === "learn_context") { const info = args?.information as string; const category = (args?.category as string) || "general"; const vector = await getEmbedding(info); const data = [{ vector, text: info, category, timestamp: new Date().toISOString() }]; if (!table) { table = await db.createTable(TABLE_NAME, data); } else { await table.add(data); } return { content: [{ type: "text", text: `Learned and stored in semantic memory: "${info}"` }], }; } - src/index.ts:52-58 (helper)getEmbedding helper function that calls Ollama's embed API with 'nomic-embed-text' model to convert text to a vector.
async function getEmbedding(text: string): Promise<number[]> { const response = await ollama.embed({ model: EMBEDDING_MODEL, input: text, }); return response.embeddings[0]!; }