Menu

How Many Log Lines Should You Send to Gemini? The Context Window Problem.
🖼️

How Many Log Lines Should You Send to Gemini? The Context Window Problem.

DEV Community·hiyoyo·6 months ago
#EAxKZGU3
#ai#gemini#programming#lines#diagnosis
Reading 0:00
15s threshold

All tests run on an 8-year-old MacBook Air.

When you send logcat lines to Gemini for diagnosis, how many lines should you include?

Too few: the model lacks context, gives a generic answer.

Too many: you hit token limits, slow down the response, and bury the relevant signal in noise.

Here's what I found after testing different window sizes in HiyokoLogcat.

The naive approach: send everything

First attempt: grab the last 500 lines and send them all.

Problems:

Gemini 1.5 Flash has a large context window, but 500 verbose logcat lines is a lot of tokens

Response latency increases noticeably

The model sometimes focuses on unrelated noise rather than the actual error

What actually works: 50 lines before, 50 after

After testing, ±50 lines around the target error hits the sweet spot:

pub fn get_diagnosis_context ( buffer : & LogRingBuffer , error_idx : usize , ) -> String { let window = 50 ; let lines = buffer .context_around ( error_idx , window );

lines .iter () .map (| l | format!…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.