Repository navigation
fix: size AI summary chunks in tokens so local OpenAI-compatible models get the instructions - #2771
kovashikawa wants to merge 2 commits into
Conversation
…ls get the instructions - Chunk transcripts by estimated tokens instead of 24,000 characters, counting the per-segment timestamp prefix and non-ASCII scripts - Use a 1,800-token budget when openai-compatible is in the generation chain, so each request fits Ollama's default 4k context - Document the Ollama context limit and OLLAMA_CONTEXT_LENGTH in the self-hosting guide
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
@kovashikawa thanks for tracking this down, the Ollama truncation write-up is really helpful. One concern before we can merge: the new estimate also changes chunking for hosted providers. In |
…get only for openai-compatible - Restore the 24,000-character chunker unchanged for chains without openai-compatible - Use the 1,800-token chunker when openai-compatible is anywhere in the generation chain, including as a fallback - Pin the hosted split points in tests (585 vs 586 cues, 24,000 vs 24,001 characters, oversized cue, non-ASCII length) - Make the token test count the per-segment timestamp allowance - Docs: note that the final combining step can still pass 4k tokens on very long recordings
|
Thanks @richiemcilroy, good catch. Hosted chains now go through the original 24,000-character chunker, unchanged from main, and only chains that include The new tests use your numbers: 585 forty-character cues stay in one chunk, 586 split, and exactly 24,000 joined characters stay together. I also replayed 14 transcripts through main and this branch, and hosted chains send byte-identical prompts. One small docs tweak: the note now says the final step that combines sections can still pass 4k tokens on very long recordings. |
Summary
AI summaries fail on self-hosted instances that use
AI_PROVIDER=openai-compatiblewith Ollama. Every recording longer than a few minutes ends inAiUnavailableError: All AI providers failed for the "generation" role, with each attempt loggingAI response did not contain a JSON object.Root cause: transcripts are chunked at a fixed 24,000 characters, and the single-chunk prompt prefixes every segment with
[m:ss]. Ollama serves a 4k-token context by default on machines under 24 GB of VRAM (docs), and its/v1endpoint ignoresnum_ctx(ollama#5356, ollama#16825). A longer prompt is cut from the front with no error, which removes the JSON instructions, so the model answers in prose. Ollama reports exactlyprompt_tokens: 4096when this happens.Found while testing #2397 (closed in favour of this PR). The STT side worked, but the AI summary for the same recording never completed.
Changes
openai-compatiblekeep the existing 24,000-character chunker, unchanged from main.openai-compatibleis anywhere in the generation chain, including as a fallback, transcripts are chunked by estimated tokens with a 1,800-token budget, which leaves room for the instructions and the JSON reply inside a 4k window. Every provider in the chain receives the same chunks, so a local fallback means sizing for its context.OLLAMA_CONTEXT_LENGTH.Testing
generate-ai-fallback.test.tspin the hosted split points: 585 forty-character cues stay in one chunk and 586 split, exactly 24,000 joined characters stay together and 24,001 split, an oversized cue stays whole, and non-ASCII text is still measured by string length. Further tests coveropenai-compatibleas primary and as fallback, including the timestamp allowance. The AI provider, start, title and fallback suites pass (105 tests), Biome is clean, andbun run typecheckpasses.gemma3:12bat the default 4,096 context, main failed a 33-minute recording on all four attempts: the prompt was cut from 6,503 to 4,096 tokens and the reply ignored the instructions. This branch completed it in 4 calls with no truncation, and completed the 66, 100 and 133-minute transcripts that main failed or summarized from only part of the recording.