Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend/controllers/ragController.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export const askQuestionStream = catchAsync(async (req, res) => {
closed = true;
});

// Keep the SSE connection alive through nginx's proxy_read_timeout (default 60s).
// The embedding phase can take minutes on CPU-only ollama — without this, nginx
// kills the idle connection before the first event is ever flushed.
const heartbeat = setInterval(() => {
if (!closed && !res.writableEnded) res.write(': keepalive\n\n');
}, 20000);

try {
await executeRAG({
question,
Expand All @@ -104,6 +111,7 @@ export const askQuestionStream = catchAsync(async (req, res) => {
send('error', { message: 'Stream failed', code: 'STREAM_ERROR' });
}
} finally {
clearInterval(heartbeat);
if (!res.writableEnded) res.end();
}
});
Loading