Add Context Chat Multi: process a batch of questions in one task - #351
Open
MichelleAntunes wants to merge 7 commits into
Open
Add Context Chat Multi: process a batch of questions in one task#351MichelleAntunes wants to merge 7 commits into
MichelleAntunes wants to merge 7 commits into
Conversation
MichelleAntunes
requested review from
kyteinsky and
marcelklehr
as code owners
September 7, 2026 08:21
Adds a new TaskType/TaskProcessingProvider registration in
enabled_handler(), alongside the existing context_chat and
context_chat_search ones.
This new task type ('context_chat:context_chat_multi') accepts the
same input as a regular question (prompt, scopeType, scopeList,
scopeListMeta), but is meant to receive several questions at once,
one per line.
Its output_shape is different from the single-question task type:
instead of a single 'output' text field, it declares 'questions'
and 'answers' as lists (LIST_OF_TEXTS), so the caller gets back one
answer per question, in order, plus a combined 'sources' list.
expected_runtime is set to 30 * MAX_MULTI_QUESTIONS, since answering
multiple questions sequentially takes proportionally longer than a
single question.
Also unregisters the new provider in the disabled branch, mirroring
the existing search/normal providers.
Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
MichelleAntunes
force-pushed
the
feat/context-chat-multi
branch
from
September 7, 2026 08:27
fa17434 to
3efcfe1
Compare
added 6 commits
September 7, 2026 10:34
Teaches the request processing loop to recognize the new 'context_chat:context_chat_multi' task type (added to the next_task() polling call) and route it to a new process_multi_task() function. process_multi_task(): - Splits the task's 'prompt' input into individual questions, one per non-empty line, via the new _split_questions() helper. - Caps the number of questions at MAX_MULTI_QUESTIONS (20) to avoid unbounded processing time on a single task. - Calls the existing process_context_query() once per question, reusing the same vector search + LLM logic used for single questions, instead of duplicating that logic. - Collects all answers in order, and deduplicates sources across answers (the same document may be relevant to more than one question) before returning them. - Raises ValueError if no valid question was found in the prompt, so the task fails clearly instead of silently returning nothing. The result (questions, answers, sources) is returned to Nextcloud via return_result_to_nextcloud(), matching the output_shape declared for this task type in controller.py. Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
…all answers Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
…tcher.py Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
MichelleAntunes
force-pushed
the
feat/context-chat-multi
branch
from
September 7, 2026 08:35
3efcfe1 to
4bbbd13
Compare
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backend implementation for nextcloud/assistant#637.
Problem
Context Chat currently answers one question per task. For workflows that need answers to a fixed batch of related questions against the same knowledge base, this means submitting each question as a separate task, waiting for each one, and manually reassembling the results afterwards.
Solution
Adds a new task type, "Context Chat Multi", that accepts a list of questions instead of a single prompt. Each question is processed through the existing
process_context_query()logic — the same code path already used for a single question, just looped, so no query/retrieval logic is duplicated. Sources are grouped per question rather than merged across the whole batch, since the same source can be relevant to more than one question.Changes
context_chat_backend/chain/types.py: newMultiOutputtype for the batch result shapecontext_chat_backend/controller.py: registers the new Multi task typecontext_chat_backend/task_fetcher.py: processes Multi tasks by looping the existing single-question logic, groups sources per question instead of merging them, and exposes the configured question cap (MAX_MULTI_QUESTIONS) to the frontend viainput_shape_defaultsso the UI can enforce the same limitTesting
Tested end-to-end on a real Nextcloud instance with the companion UI branch: submitted a batch of questions against real indexed documents and confirmed the Assistant UI returns correctly answered, source-attributed results for each question.
Companion PR
This is the backend half of the feature. UI branch: nextcloud/assistant#646
🤖 AI (if applicable)