fix: improve error handling in HypaV3 (#808)

# PR Checklist
- [ ] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
- [ ] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
- [ ] Have you added type definitions?

# Description
This PR introduces following:
- fix: check empty summarization result in HypaV3
- fix: handle similarity search error in HypaV3
This commit is contained in:
kwaroran
2025-04-14 14:07:25 +09:00
committed by GitHub

View File

@@ -445,7 +445,11 @@ export async function hypaMemoryV3(
if (toSummarize.length > 0) {
const summarizeResult = await retryableSummarize(toSummarize);
if (!summarizeResult.success) {
if (
!summarizeResult.success ||
!summarizeResult.data ||
summarizeResult.data.trim().length === 0
) {
return {
currentTokens,
chats,
@@ -642,7 +646,16 @@ export async function hypaMemoryV3(
processor.oaikey = db.supaMemoryKey;
// Add summaryChunks to processor for similarity search
try {
await processor.addSummaryChunks(summaryChunks);
} catch (error) {
return {
currentTokens,
chats,
error: `[HypaV3] Similarity search failed: ${error}`,
memory: toSerializableHypaV3Data(data),
};
}
const scoredSummaries = new Map<Summary, number>();
@@ -652,6 +665,7 @@ export async function hypaMemoryV3(
if (!pop) break;
try {
const searched = await processor.similaritySearchScoredEx(pop.content);
for (const [chunk, similarity] of searched) {
@@ -662,6 +676,14 @@ export async function hypaMemoryV3(
(scoredSummaries.get(summary) || 0) + similarity
);
}
} catch (error) {
return {
currentTokens,
chats,
error: `[HypaV3] Similarity search failed: ${error}`,
memory: toSerializableHypaV3Data(data),
};
}
}
// (2) Summarized recent chat search
@@ -670,7 +692,11 @@ export async function hypaMemoryV3(
const recentChats = chats.slice(-minChatsForSimilarity);
const summarizeResult = await retryableSummarize(recentChats);
if (!summarizeResult.success) {
if (
!summarizeResult.success ||
!summarizeResult.data ||
summarizeResult.data.trim().length === 0
) {
return {
currentTokens,
chats,
@@ -679,6 +705,7 @@ export async function hypaMemoryV3(
};
}
try {
const searched = await processor.similaritySearchScoredEx(
summarizeResult.data
);
@@ -691,6 +718,14 @@ export async function hypaMemoryV3(
(scoredSummaries.get(summary) || 0) + similarity
);
}
} catch (error) {
return {
currentTokens,
chats,
error: `[HypaV3] Similarity search failed: ${error}`,
memory: toSerializableHypaV3Data(data),
};
}
console.log("[HypaV3] Similarity corrected.");
}