Skip to content

Commit

Permalink
Fix memory indices
Browse files Browse the repository at this point in the history
  • Loading branch information
josephrocca authored Nov 26, 2023
1 parent b8dfc24 commit 027549c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,7 @@ <h2 style="text-align:center;margin-bottom: 0.5rem;">Your Characters</h2>
}

let memoryIdsToSetToCurrent = [];
let highestMemoryIndexInCurrentMemories = -1;
// let memories = await db.memories.where({threadId});
// memories.sort((a,b) => a.index - b.index);
// if(aiCharacter.autoGenerateMemories === "v1") {
Expand Down Expand Up @@ -3778,16 +3779,18 @@ <h2 style="text-align:center;margin-bottom: 0.5rem;">Your Characters</h2>

let embeddings = await embedTexts({textArr:memories, modelName:embeddingModelName, shouldCache:true});

let existingThreadMemories = await db.memories.where({threadId, status:"current"}).toArray();
existingThreadMemories.sort((a,b) => a.index - b.index);
let previousMemory = existingThreadMemories.at(-1);
let previousMemoryIndex = previousMemory ? previousMemory.index : -1;
let i = 0;
let memoryObjsToAdd = [];
// let existingThreadMemories = await db.memories.where({threadId, status:"current"}).toArray();
// existingThreadMemories.sort((a,b) => a.index - b.index);
// let previousMemory = existingThreadMemories.at(-1);
// let previousMemoryIndex = previousMemory ? previousMemory.index : -1;
// let i = 0;
// let memoryObjsToAdd = [];
let previousMemoryIndex = highestMemoryIndexInCurrentMemories;
for(let memory of memories) {
let embedding = embeddings[i];
memoryObjsToAdd.push({summaryHash:hash, threadId, text:memory, characterId, embeddings:{[embeddingModelName]:embedding}, status:"current", index:previousMemoryIndex+1, triggers:[]});
previousMemoryIndex++;
highestMemoryIndexInCurrentMemories = previousMemoryIndex;
addToDebugLog(`<b>added memory:</b> ${memory}`);
console.log("added memory:", memory);
i++;
Expand Down Expand Up @@ -3820,6 +3823,11 @@ <h2 style="text-align:center;margin-bottom: 0.5rem;">Your Characters</h2>
// There's already an existing summary that matches this instruction hash.
// mark the existing memories that match this summary has as current/valid:
let memories = await db.memories.where({summaryHash:hash, threadId}).toArray();
for(let m of memories) {
if(m.index > highestMemoryIndexInCurrentMemories) {
highestMemoryIndexInCurrentMemories = m.index;
}
}
memoryIdsToSetToCurrent.push(...memories.map(m => m.id));
}

Expand Down

0 comments on commit 027549c

Please sign in to comment.