smarter context assembly implementation

This commit is contained in:
Storme-bit
2026-04-27 21:41:32 -07:00
parent b58a4e4692
commit e4908193bd
7 changed files with 156 additions and 22 deletions

View File

@@ -64,4 +64,14 @@ function getEntityNeighbors(entityIds) {
return { nodes, edges };
}
module.exports = { getNeighborhood, getEntityNeighbors };
// Returns episode IDs linked to any of the given entity IDs via entity_episodes
function getEpisodeIdsByEntities(entityIds) {
if (!entityIds.length) return [];
const db = getDB();
const ph = entityIds.map(() => '?').join(',');
return db.prepare(
`SELECT DISTINCT episode_id FROM entity_episodes WHERE entity_id IN (${ph})`
).all(...entityIds).map(r => r.episode_id);
}
module.exports = { getNeighborhood, getEntityNeighbors, getEpisodeIdsByEntities };

View File

@@ -251,6 +251,14 @@ app.post('/graph/neighbors', (req, res) => {
res.json(graph.getEntityNeighbors(entityIds.map(Number)));
});
app.post('/episodes/by-entities', (req, res) => {
const { entityIds } = req.body;
if (!Array.isArray(entityIds) || entityIds.length === 0) {
return res.status(400).json({ error: 'entityIds array is required' });
}
res.json({ episodeIds: graph.getEpisodeIdsByEntities(entityIds.map(Number)) });
});
/*********************************** */
/********** Project Routes ********** */
/*********************************** */