Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions examples/basic-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Demonstrates how to add memories, search them, and list results
* using the LocalMemoryClient API.
*/

import { memoryClient } from "../src/services/client.js";
import { log } from "../src/services/logger.js";

Expand All @@ -29,9 +28,9 @@ async function main() {
);

if (addResult.success) {
console.log(`Memory added with ID: ${addResult.id}`);
log(`Memory added with ID: ${addResult.id}`);
} else {
console.error("Failed to add memory:", addResult.error);
log("Failed to add memory", { error: addResult.error });
return;
}

Expand Down Expand Up @@ -59,30 +58,30 @@ async function main() {
);

if (searchResult.success) {
console.log(`\nSearch returned ${searchResult.total} results:`);
log(`\nSearch returned ${searchResult.total} results:`);
for (const result of searchResult.results) {
console.log(` - ${result.memory} (score: ${result.similarity?.toFixed(3)})`);
log(` - ${result.memory} (score: ${result.similarity?.toFixed(3)})`);
}
} else {
console.error("Search failed:", searchResult.error);
log("Search failed", { error: searchResult.error });
}

// --- List all memories ---
const listResult = await memoryClient.listMemories(containerTag, 20, "project");

if (listResult.success) {
console.log(`\nListed ${listResult.memories.length} memories:`);
log(`\nListed ${listResult.memories.length} memories:`);
for (const memory of listResult.memories) {
console.log(` [${memory.id}] ${memory.summary}`);
console.log(
log(` [${memory.id}] ${memory.summary}`);
log(
` Strength: ${memory.strength?.toFixed(3)} | Store: ${memory.storeType || "stm"}`
);
}
}

// --- Clean up ---
memoryClient.close();
console.log("\nDone!");
log("\nDone!");
}

main().catch((error) => {
Expand Down
26 changes: 8 additions & 18 deletions examples/custom-scoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ function main() {
const confidence = calculateConfidence("manual", "refactor");
const interference = calculateInterference(content, conflictingMemories);

console.log("=== Individual Scores ===");
console.log(`Recency: ${recency.toFixed(3)}`);
console.log(`Frequency: ${frequency.toFixed(3)}`);
console.log(`Importance: ${importance.toFixed(3)}`);
console.log(`Utility: ${utility.toFixed(3)}`);
console.log(`Novelty: ${novelty.toFixed(3)}`);
console.log(`Confidence: ${confidence.toFixed(3)}`);
console.log(`Interference: ${interference.toFixed(3)}`);

// --- Compute overall strength ---
const scores: ScoreComponents = {
recency,
Expand All @@ -64,7 +55,6 @@ function main() {
};

const strength = computeStrength(scores);
console.log(`\n=== Overall Strength: ${strength.toFixed(3)} ===`);

// --- Calculate all scores in one call ---
const allScores = calculateAllScores({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'allScores' is assigned a value but never used


Unused variables are generally considered a code smell and should be avoided.

Expand All @@ -80,21 +70,21 @@ function main() {
utilityHalfLifeDays: 3,
});

console.log("\n=== Batch Calculation ===");
console.log(JSON.stringify(allScores, null, 2));

// --- Score interpretation ---
console.log("\n=== Interpretation ===");
if (strength > 0.8) {
console.log("High-strength memory → eligible for automatic LTM promotion.");
// High-strength memory → eligible for automatic LTM promotion.
// You may trigger a UI update here.
} else if (strength > 0.5) {
console.log("Medium-strength memory → remains in STM with standard decay.");
// Medium-strength memory → remains in STM with standard decay.
// You may trigger a UI update here.
} else {
console.log("Low-strength memory → may be archived after prolonged inactivity.");
// Low-strength memory → may be archived after prolonged inactivity.
// You may trigger a UI update here.
}

if (interference > 0.3) {
console.log("⚠️ High interference detected — consider conflict resolution.");
// ⚠️ High interference detected — consider conflict resolution.
// You may trigger a UI warning here.
}
}

Expand Down
Loading