mr-memory 2.18.4 ā 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +74 -0
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -872,6 +872,80 @@ const memoryRouterPlugin = {
|
|
|
872
872
|
await runUpload({ memoryKey, endpoint, targetPath, stateDir, workspacePath, hasWorkspaceFlag: !!opts.workspace, hasBrainFlag: !!opts.brain, embeddings });
|
|
873
873
|
});
|
|
874
874
|
|
|
875
|
+
mr.command("search")
|
|
876
|
+
.description("Search memories in vault")
|
|
877
|
+
.argument("<query>", "Search query")
|
|
878
|
+
.option("-n, --limit <number>", "Number of results", "5")
|
|
879
|
+
.option("--json", "Output raw JSON response")
|
|
880
|
+
.action(async (query: string, opts: { limit: string; json?: boolean }) => {
|
|
881
|
+
if (!memoryKey) { console.error("Not configured. Run: openclaw mr <key>"); return; }
|
|
882
|
+
const limit = parseInt(opts.limit, 10) || 5;
|
|
883
|
+
try {
|
|
884
|
+
const res = await fetch(`${endpoint}/v1/memory/search`, {
|
|
885
|
+
method: "POST",
|
|
886
|
+
headers: {
|
|
887
|
+
Authorization: `Bearer ${memoryKey}`,
|
|
888
|
+
"Content-Type": "application/json",
|
|
889
|
+
},
|
|
890
|
+
body: JSON.stringify({ query, limit }),
|
|
891
|
+
});
|
|
892
|
+
if (!res.ok) {
|
|
893
|
+
const err = await res.json() as { error?: string };
|
|
894
|
+
console.error(`Search failed: ${err.error || `HTTP ${res.status}`}`);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
const data = await res.json() as {
|
|
898
|
+
query: string;
|
|
899
|
+
sessionId: string | null;
|
|
900
|
+
memoryKey: string;
|
|
901
|
+
totalMemories: number;
|
|
902
|
+
tokenCount: number;
|
|
903
|
+
windowBreakdown: Record<string, number>;
|
|
904
|
+
metrics: Record<string, number>;
|
|
905
|
+
memories: Array<{
|
|
906
|
+
id: number;
|
|
907
|
+
content: string;
|
|
908
|
+
score: number;
|
|
909
|
+
window: string;
|
|
910
|
+
timestampHuman: string;
|
|
911
|
+
timestamp: number;
|
|
912
|
+
role: string;
|
|
913
|
+
source: string;
|
|
914
|
+
}>;
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
// Raw JSON output
|
|
918
|
+
if (opts.json) {
|
|
919
|
+
console.log(JSON.stringify(data, null, 2));
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (data.totalMemories === 0) {
|
|
924
|
+
console.log("No results found.");
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const modelLabel = embeddings ? ` (${embeddings})` : " (bge)";
|
|
928
|
+
console.log(`\nš ${data.totalMemories} results for "${query}"${modelLabel}\n`);
|
|
929
|
+
for (let i = 0; i < data.memories.length; i++) {
|
|
930
|
+
const m = data.memories[i];
|
|
931
|
+
const score = (m.score * 100).toFixed(1);
|
|
932
|
+
const date = new Date(m.timestampHuman).toLocaleDateString("en-US", {
|
|
933
|
+
month: "short", day: "numeric", year: "numeric",
|
|
934
|
+
});
|
|
935
|
+
const windowIcon = m.window === "immediate" ? "ā”" : m.window === "short" ? "š„" : m.window === "long" ? "š§ " : "š";
|
|
936
|
+
console.log(` ${i + 1}. ${windowIcon} ${score}% | ${m.role} | ${date} | id:${m.id}`);
|
|
937
|
+
console.log(` ${m.content}\n`);
|
|
938
|
+
}
|
|
939
|
+
console.log(` Tokens: ${data.tokenCount} | Windows: ${JSON.stringify(data.windowBreakdown)}`);
|
|
940
|
+
if (data.metrics) {
|
|
941
|
+
const ms = data.metrics;
|
|
942
|
+
console.log(` Latency: ${ms.raceMs ?? ms.totalMs ?? '-'}ms`);
|
|
943
|
+
}
|
|
944
|
+
} catch (err) {
|
|
945
|
+
console.error(`Failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
|
|
875
949
|
mr.command("delete")
|
|
876
950
|
.description("Clear all memories from vault")
|
|
877
951
|
.action(async () => {
|