Memory: fix MMR tie-break and temporal timestamp dedupe

This commit is contained in:
Rodrigo Uroz
2026-02-11 20:56:56 +00:00
committed by Peter Steinberger
parent 33cf27a52a
commit 65ad9a4262
2 changed files with 7 additions and 6 deletions

View File

@@ -163,7 +163,7 @@ export function mmrRerank<T extends MMRItem>(items: T[], config: Partial<MMRConf
// Use original score as tiebreaker (higher is better)
if (
mmrScore > bestMMRScore ||
(mmrScore === bestMMRScore && (bestItem === null || candidate.score > bestItem.score))
(mmrScore === bestMMRScore && candidate.score > (bestItem?.score ?? -Infinity))
) {
bestMMRScore = mmrScore;
bestItem = candidate;

View File

@@ -132,21 +132,22 @@ export async function applyTemporalDecayToHybridResults<
}
const nowMs = params.nowMs ?? Date.now();
const timestampCache = new Map<string, Date | null>();
const timestampPromiseCache = new Map<string, Promise<Date | null>>();
return Promise.all(
params.results.map(async (entry) => {
const cacheKey = `${entry.source}:${entry.path}`;
if (!timestampCache.has(cacheKey)) {
const timestamp = await extractTimestamp({
let timestampPromise = timestampPromiseCache.get(cacheKey);
if (!timestampPromise) {
timestampPromise = extractTimestamp({
filePath: entry.path,
source: entry.source,
workspaceDir: params.workspaceDir,
});
timestampCache.set(cacheKey, timestamp);
timestampPromiseCache.set(cacheKey, timestampPromise);
}
const timestamp = timestampCache.get(cacheKey) ?? null;
const timestamp = await timestampPromise;
if (!timestamp) {
return entry;
}