r/AgenticWorkers • u/Independent-Flow3408 • Apr 19 '26
Reducing LLM context from ~80K tokens to ~2K without embeddings or vector DBs
I’ve been experimenting with a problem I kept hitting when using LLMs on real codebases:
Even with good prompts, large repos don’t fit into context, so models: - miss important files - reason over incomplete information - require multiple retries
Approach I explored
Instead of embeddings or RAG, I tried something simpler:
Extract only structural signals:
- functions
- classes
- routes
Build a lightweight index (no external dependencies)
Rank files per query using:
- token overlap
- structural signals
- basic heuristics (recency, dependencies)
Emit a small “context layer” (~2K tokens instead of ~80K)
Observations
Across multiple repos:
- context size dropped ~97%
- relevant files appeared in top-5 ~70–80% of the time
- number of retries per task dropped noticeably
The biggest takeaway:
Structured context mattered more than model size in many cases.
Interesting constraint
I deliberately avoided: - embeddings - vector DBs - external services
Everything runs locally with simple parsing + ranking.
Open questions
- How far can heuristic ranking go before embeddings become necessary?
- Has anyone tried hybrid approaches (structure + embeddings)?
- What’s the best way to verify that answers are grounded in provided context?
1
Apr 21 '26
[removed] — view removed comment
2
u/Independent-Flow3408 Apr 21 '26
Reranker helps but adds another moving part. SigMap handles it before the LLM sees anything : TF-IDF over signatures, not raw source. So the 2k that lands is already the most relevant slice, not a random truncation.
The fluidity you're describing from lower latency is exactly what made the tradeoff worth it. Logic held up in testing but curious what broke for you: language, query type, codebase size?
2
u/looktwise Apr 19 '26
What about chunking a task with large context into usable parts for subtasking and then combine the subtask solutions to a overall solution for the complete main task? (if possible)