Design Bulk Document Question Answering into a Results Table
Answer one user question separately for every document in a selection of up to 100,000 documents with a language model, and fill a table with one answer row per document while many customers share one model provider's limits.
Problem statement
Design the backend behind a feature that puts the same question to every document in a big collection using a language model, up to roughly 100,000 model requests for one job, and gives back a table with a row for each document holding its name and its answer.
For this exercise, assume a document review product where customers keep large collections of documents in workspaces. The documents are already stored and their text has already been extracted; uploading and text extraction are out of scope.
A user selects up to 100,000 documents and types one question, for example which party may end the agreement early and with how much notice. The system answers that question separately for each selected document and shows the results as that table.
Assume one model call can read at most 30,000 tokens of input, so a few long documents do not fit in a single call. Assume all customers' jobs share one model provider account with fixed limits on tokens and requests per minute, and the provider sometimes rejects calls for going over those limits or times out.
Assume users watch the table fill in, may cancel a job, may retry rows that failed, and may export the table at any time, with unfinished rows marked as unfinished.
Every selected document must end with exactly one row in one final state, and its answer must come from the document version that was selected when the job started. Choosing or training the model, page-level citations, and the user interface layout are out of scope.
What to build
- A user selects up to 100,000 documents and enters one question; the system starts a job and shows a table that lists every selected document by name with its status.
- Each row ends with exactly one result for its whole document as selected at the start: an answer, a statement that the document does not address the question, a failure with a reason, or cancelled. Rows appear as they finish, not only when the whole job is done.
- The user can see progress, cancel a job, retry failed rows, and export the table at any time, with unfinished rows marked.
- Jobs from many customers share one model provider account; small jobs keep finishing quickly while large jobs run, and no job pushes the account over the provider's limits.
At scale
- For this exercise, assume most jobs cover a few hundred to a few thousand documents, the largest cover about 100,000 documents, and at peak dozens of jobs from different customers run at the same time.
- For this exercise, assume a typical document is about 4,000 tokens of text, the question and instructions add about 500 tokens to each call, and an answer is at most about 200 tokens. About 2 percent of documents are longer than the 30,000-token call limit, up to about 300,000 tokens.
- For this exercise, assume the shared provider account allows 10 million input tokens and 5,000 requests per minute, a call takes about 10 seconds at the median and up to 30 seconds, and about 1 percent of calls fail with a rate-limit error or a timeout.
- For this exercise, assume these targets under normal load: the first answers of any job appear within 30 seconds, a 1,000-document job finishes within 10 minutes even while large jobs are running, and a 100,000-document job finishes within about 3 hours.