MCPcopy
hub / github.com/CaviraOSS/OpenMemory / update_memory

Function update_memory

backend/src/memory/hsg.ts:1155–1218  ·  view source on GitHub ↗
(
    id: string,
    content?: string,
    tags?: string[],
    metadata?: any,
)

Source from the content-addressed store, hash-verified

1153 if (new_sal > 0.8) await log_maint_op("consolidate", 1);
1154}
1155export async function update_memory(
1156 id: string,
1157 content?: string,
1158 tags?: string[],
1159 metadata?: any,
1160): Promise<{ id: string; updated: boolean }> {
1161 const mem = await q.get_mem.get(id);
1162 if (!mem) throw new Error(`Memory ${id} not found`);
1163 const new_content = content !== undefined ? content : mem.content;
1164 const new_tags = tags !== undefined ? j(tags) : mem.tags || "[]";
1165 const new_meta = metadata !== undefined ? j(metadata) : mem.meta || "{}";
1166 await transaction.begin();
1167 try {
1168 if (content !== undefined && content !== mem.content) {
1169 const chunks = chunk_text(new_content);
1170 const use_chunking = chunks.length > 1;
1171 const classification = classify_content(new_content, metadata);
1172 const all_sectors = [
1173 classification.primary,
1174 ...classification.additional,
1175 ];
1176 await vector_store.deleteVectors(id);
1177 const emb_res = await embedMultiSector(
1178 id,
1179 new_content,
1180 all_sectors,
1181 use_chunking ? chunks : undefined,
1182 );
1183 for (const result of emb_res) {
1184 await vector_store.storeVector(
1185 id,
1186 result.sector,
1187 result.vector,
1188 result.dim,
1189 mem.user_id || "anonymous",
1190 );
1191 }
1192 const mean_vec = calc_mean_vec(emb_res, all_sectors);
1193 const mean_vec_buf = vectorToBuffer(mean_vec);
1194 await q.upd_mean_vec.run(id, mean_vec.length, mean_vec_buf);
1195 await q.upd_mem_with_sector.run(
1196 new_content,
1197 classification.primary,
1198 new_tags,
1199 new_meta,
1200 Date.now(),
1201 id,
1202 );
1203 } else {
1204 await q.upd_mem.run(
1205 new_content,
1206 new_tags,
1207 new_meta,
1208 Date.now(),
1209 id,
1210 );
1211 }
1212 await transaction.commit();

Callers 1

memFunction · 0.90

Calls 9

chunk_textFunction · 0.90
embedMultiSectorFunction · 0.90
vectorToBufferFunction · 0.90
classify_contentFunction · 0.70
calc_mean_vecFunction · 0.70
deleteVectorsMethod · 0.65
storeVectorMethod · 0.65
getMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected