Tweak chroma memory retrieval so one big memory doesn't shut out smaller memories that might fit.

Fixed some log lines.
This commit is contained in:
50h100a
2023-07-09 04:31:34 -04:00
parent dae48e66d1
commit 497ca714a9

View File

@@ -615,7 +615,6 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => {
const lastMessage = chat[chat.length - 1];
let queriedMessages;
console.debug(recallStrategy)
if (lastMessage) {
let queryBlob = "";
if (chromaQueryLastOnly) {
@@ -626,7 +625,7 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => {
queryBlob += `${msg.mes}\n`
}
}
console.log("CHROMADB: Query text:", queryBlob);
console.debug("CHROMADB: Query text:", queryBlob);
if (recallStrategy === 'multichat') {
console.log("Utilizing multichat")
@@ -688,17 +687,17 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => {
memoryMsg += " {{message}}";
}
// Reversed because we want the most important messages at the bottom.
// Reversed because we want the most 'important' messages at the bottom.
let recalledMemories = queriedMessages.map(m => m.meta).filter(onlyUnique).map(JSON.parse).reverse();
let tokenApprox = 0;
let allMemoryBlob = "";
for (let msg of recalledMemories) {
let memoryBlob = memoryMsg.replace('{{name}}', msg.name).replace('{{message}}', msg.mes);
tokenApprox += (memoryBlob.length / CHARACTERS_PER_TOKEN_RATIO);
if (tokenApprox > chromaTokenLimit) {
break;
for (const msg of recalledMemories) {
const memoryBlob = memoryMsg.replace('{{name}}', msg.name).replace('{{message}}', msg.mes);
const memoryTokens = (memoryBlob.length / CHARACTERS_PER_TOKEN_RATIO);
if (tokenApprox + memoryTokens <= chromaTokenLimit) {
allMemoryBlob += memoryBlob;
tokenApprox += memoryTokens;
}
allMemoryBlob += memoryBlob;
}
const promptBlob = wrapperMsg.replace('{{memories}}', allMemoryBlob);