Add Context Chat Multi: process a batch of questions in one task - #351
MichelleAntunes wants to merge 7 commits into
Conversation
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>
fa17434 to
3efcfe1
Compare
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>
3efcfe1 to
4bbbd13
Compare
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
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)