consolidation and aging
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const {getDB} = require('../db');
|
||||
const { EPISODIC, getEnv, SERVICES, parseRow, formatEpisodeText, SUMMARIES, logger, isTrivialTurn } = require('@nexusai/shared');
|
||||
const { EPISODIC, getEnv, SERVICES, parseRow, formatEpisodeText, SUMMARIES, logger, isTrivialTurn, CONSOLIDATION } = require('@nexusai/shared');
|
||||
const semantic = require('../semantic');
|
||||
const { extractAndStoreEntities } = require('../entities/extraction')
|
||||
|
||||
@@ -311,6 +311,22 @@ function getEpisodesByProject(projectId, limit = SUMMARIES.MAX_PROJECT_EPISODE_L
|
||||
`).all(projectId, limit).map(parseRow);
|
||||
}
|
||||
|
||||
function getConsolidationCandidates(sessionId, limit = CONSOLIDATION.CANDIDATE_LIMIT) {
|
||||
const db = getDB();
|
||||
const now = Date.now();
|
||||
const cutoff = Math.floor(now / 1000) - CONSOLIDATION.MIN_AGE_DAYS *86400 // seconds, so it matches created_at
|
||||
|
||||
return db.prepare(`
|
||||
SELECT id, access_count, created_at, last_accessed_at,
|
||||
SUBSTR(user_message, 1, 80) AS preview,
|
||||
CAST( access_count AS REAL) / (1+(?-COALESCE(last_accessed_at, created_at * 1000)) / 86400000.0) AS aging_score
|
||||
FROM episodes
|
||||
WHERE session_id = ? AND created_at < ?
|
||||
ORDER BY aging_score ASC
|
||||
LIMIT ?
|
||||
`).all(now, sessionId, cutoff, limit);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createSession,
|
||||
getSession,
|
||||
@@ -331,4 +347,5 @@ module.exports = {
|
||||
touchEpisodes,
|
||||
getEpisodesByProject,
|
||||
buildFtsQuery,
|
||||
getConsolidationCandidates,
|
||||
};
|
||||
Reference in New Issue
Block a user