All articles

Local AI

How to process long transcripts with a local LLM

A 113-minute recording overflowed our prompt. Here’s how to index a transcript in layers, budget every request, and verify edits against the source.

A strip of motion-picture film threaded through stacked blue glass plates
In this article

Split a long transcript into timecoded segments, index the original speech, and give your local model the excerpts it needs for one decision at a time. Build short chapter summaries for browsing. Keep the transcript available so the model can reopen a passage before it answers a question or proposes a cut.

The failed run

In one ClipMill development run, a 113-minute conversation produced 305 events across its first pass. Each window fit. The next pass, which tried to connect events across the recording, put all 305 into one request. It exceeded the editorial worker’s configured input limit of 12,000 tokens.

Recording
113 min
Extracted events
305
Input token cap
12,000

The error was recorded as a malformed model reply, so the run continued without chapters or links. The editor lost the option to join a question to an answer later in the recording or build a montage around a recurring theme. The transcript was still there.

A larger context window would have helped that request fit. Finding the right detail inside that request is a separate problem. In Lost in the Middle, retrieval and question answering often got worse when the relevant information moved into the middle of a long input. Liu et al., TACL 2024.

The first change is to classify the failure where it happens. A request rejected for size needs splitting. A request that fits and returns broken JSON needs an output validation error. In the run log, put the stage, source range, rendered token count, and budget alongside the failure. The outer workflow can then retry the right amount of work and tell an editor which parts of the result are usable.

A layered transcript index

Our next design gives the recording three useful levels. The transcript stays intact at the bottom. A segment holds one local topic and a brief summary. A chapter groups neighboring segments into a larger part of the conversation.

Chapters
Locate the part of the conversation.
Segments
Find a topic and follow its source IDs.
Source sentences
Read the exact words, speaker, and timestamps.
Browse in broad strokes and reopen the source at full detail.

Give each sentence an ID within a transcript revision and preserve its start, end, and speaker. Put segment boundaries at complete sentences, preferring speaker turns or noticeable pauses when there’s a choice. Split any overlong turn to stay within the model’s budget. If windows overlap, attach the same IDs to repeated lines so the merge can deduplicate them.

Write a short gist for each segment and store the source IDs with it. Build chapter summaries upward in groups that fit the budget. Record unfinished threads, such as a question whose answer hasn’t appeared yet, so you can search later passages and inspect the closest matches. Short summaries make browsing cheaper. Source IDs make it possible to check what the summary compressed or omitted.

Give windows enough context to finish a thought

Build the first set of windows in time order. Where a hard split would leave a question at the end of one window and its answer at the start of the next, try moving the boundary to the end of the answer while the request still fits. If it can’t fit, carry a small overlap of complete sentences. For more than one speaker, record the speaker with each sentence so a later step can tell who is answering.

A window can own its central IDs and read its overlap as context. During merging, keep the facts written by the owner. When two windows propose the same event, use source IDs and event type to reconcile it. Two answers with similar wording can belong to different parts of the recording. The ID anchors the result to a particular utterance.

Decide what each layer should answer

A chapter entry can answer where a topic is discussed. A segment can report the local topic and surface an unresolved question. The source lines answer what somebody said and when. For example, a segment can record that the host asks about a subscription at 05:10. Retrieval can then search later passages for evidence, even if the answer falls outside the chapter that contains the question. Store the accepted link with both source ranges.

This combines ideas from two different retrieval studies. ReadAgent used gists with the option to reopen original pages, including on a meeting-transcript task. RAPTOR grouped chunks and wrote summaries from the bottom up for retrieval at several levels of detail. We borrow those patterns for an editing task where a result needs to resolve to the recording. ReadAgent · RAPTOR.

Enforce the token budget

Read the effective context limit from the backend configuration. Reserve tokens for generation, including any reasoning the runtime counts as generated output. Then count the rendered request with the backend’s tokenizer. System instructions, role markers, tool schemas, identifiers, and the answer template all take space.

Try a prompt budget

Enter token counts for a sample request. Count the prompt after applying the chat template.

464 tokens over budgetInput limit after reserve: 14,336 tokens

Each backend can also impose a stricter input cap, as the run above did. Use the smaller limit. Have the caller split an overlong batch, or shrink the set of retrieved passages and count again. If the fixed instructions or one indivisible item still exceeds the cap, record that failure against its stage and source span.

Python sketch · Check a request before dispatch
def check_request(request, backend):
    available = backend.context_window - request.max_new_tokens
    limit = min(backend.input_cap, available)
    used = backend.count_rendered(request)

    if used > limit:
        return SplitRequired(used=used, limit=limit)
    return Ready(request)

For example, llama.cpp’s server exposes chat templating and tokenization. Keep the count close to the actual inference call so a template or model change can’t quietly invalidate the estimate. llama.cpp server reference.

A backend that can count the request directly avoids differences between your test tokenizer and the inference server. For a local tokenizer, apply the same chat template and generation markers as your runtime. The Transformers chat template interface can tokenize the rendered request in one step. Transformers chat template reference.

Python · Measure the entire chat request
tokens = tokenizer.apply_chat_template(
    messages,
    tokenize=True,
    add_generation_prompt=True,
    return_dict=False,
)
input_tokens = len(tokens)

Pack a recording in practice

We ran a separate packing exercise with 305 fictional event records and the local Qwen3.5 tokenizer. The fixture uses the event count from the earlier development run. Its text is independent of that recording. The exercise measures input size and packing, with no model generation.

One flat request
21,027
Input cap
12,000
Requests after packing
2

The script walks the events in time order. It tries to add one whole record to the current batch and counts the chat request again. Once the next record would exceed the cap, it saves the current batch and starts another. The two requests include all records and stay within the 12,000-token limit.

Request 1
174 events, 11,987 input tokens
Request 2
131 events, 9,073 input tokens
Counts include the instructions and chat template.

The requests total 21,060 input tokens. Repeating the fixed text adds 33 tokens in this fixture. The benefit is that each request fits. Build the next chapter level out of the smaller outputs and check its budget again. If the model generates a long list in place of a compact gist, cap that output and preserve its source IDs.

To try it, run the script with a local model directory containing the tokenizer and chat template. It uses Transformers to read those files. Change the window, reserve, or input cap to see how the batches change. Download the token packing example.

For a high-throughput implementation, estimate a starting batch from per-record sizes and count the whole request before dispatch. This reduces tokenizer work while accounting for separators and template overhead. An oversized single record still needs action. Split it on a sentence boundary if possible. If the instructions cause the overflow, shorten them and retry the size check before calling the model.

Verify against the recording

Imagine the gist says, “The guest explains why costs rose.” That’s enough to find the segment. Before using it as the answer to “Why did the subscription get more expensive?”, reopen the lines, including the previous turn. The guest may be talking about shipping costs for an entirely different product.

Return candidate moments as a set of sentence or span IDs. Code can verify those IDs, the matching transcript revision, source order, and timestamp boundaries. For a question joined to an answer, give the model both original spans and the surrounding turns. Ask it the narrower question of whether the second span answers the first. Review the resulting edit with the actual audio and frames.

Store the verdict beside the evidence so a rejected edit can be inspected later. When a link can’t be verified, keep the original passage available as a continuous clip. A summary’s fidelity is an independent thing to check. FABLES found that evaluated automated raters struggled to detect unfaithful claims in long book summaries, even when those claims could be checked against the source. Kim et al., FABLES.

When a search returns several plausible answers, include a strong negative candidate in your test set. In the subscription example, a sentence that says when the price changed can rank highly while missing the reason. A candidate about another product can share the same keywords. The verifier should be able to leave the question open when the passages don’t supply the answer.

What to measure

The 113-minute run gives us a regression case for the proposed memory design. We’d start by replaying that run and checking three outcomes.

  • Coverage. Every completed segment has source IDs. A failed window has a visible reason and time range.
  • Retrieval. For questions chosen by a human editor, measure whether the correct answer span appears in the retrieved candidates. Include questions answered much later and questions with no answer.
  • Edit quality. Check the resulting cut against its source and a continuous version of the same moment. Count improvements, unclear joins, and changes in meaning.

Compare keyword retrieval, a flat embedding index, and the layered version with the same model, call budget, and questions. Also record input tokens, runtime, and the number of model calls. If a flat index finds the right evidence at comparable cost, it may be sufficient for that workload.

Separate finding the evidence from using it

For each annotated question, check the retrieved spans before opening the model’s answer. If the evidence never enters the request, improve retrieval or the windowing. If the right span is present and the answer points somewhere else, inspect the verifier and its instructions. Keep the two counts separate so a retrieval improvement can’t hide a worse edit decision.

QMSum offers an example of separating the location of relevant meeting spans from query-focused summarization. For clipping, add boundary and context checks to that idea. Test whether a model chooses a complete thought from the source and keeps the context that makes it understandable. Zhong et al., QMSum.

Try an interrupted run as well. Stop after indexing a few windows, restart from the saved state, and confirm that completed windows retain their IDs and pending ones still run. If the transcript changes, invalidate the old entries or partition them by revision. Log the largest prompt, skipped windows, and unanswered questions alongside wall time and the number of proposed clips.

The transcript search walkthrough shows how to retrieve exact and paraphrased lines by timestamp.

References