Skip to content

fix(retriever): cap per-document content so small local models can finish a report#27

Merged
Mrbaeksang merged 1 commit into
mainfrom
feat/retriever-content-cap
Jun 5, 2026
Merged

fix(retriever): cap per-document content so small local models can finish a report#27
Mrbaeksang merged 1 commit into
mainfrom
feat/retriever-content-cap

Conversation

@Mrbaeksang

Copy link
Copy Markdown
Owner

What & why

The StealthRetriever returned each Bypassed page's full text as the LangChain Document.page_content. The research loop then stuffed all of them into the synthesis prompt, so a small-context local model overflowed before it could write anything:

Error 400: request (56262 tokens) exceeds the available context size (16384 tokens)

The result: only the 🛡️ Bypassed N badge was written, no report body, no citations. This silently broke the README's "local-first, no API key required" + "cited report" promise for anyone running a typical small local model.

The fix

Cap each document to max_chars (default 2000) before it reaches the loop. New pure helper _cap_content (langchain-free → unit-testable in CI, which installs --no-deps).

Verified live (not mocked)

Same machine, local 16k-context llama-server (Qwen3.6-35B) + SearXNG, identical query:

before after
synthesis prompt 56k–68k tokens → overflow well under 16k → OK
report body ❌ empty (error line + badge) ✅ substantive, cited [1]…[28]
Bot Walls Bypassed (bypass always worked) 20 (turnstile ×11, cloudflare ×9)

The bypass/Evidence layer was always real; this makes the report step actually complete on small local models.

Tests

  • tests/test_retriever.py — 3 cases for _cap_content (long capped, short untouched, 0/None disables).
  • Full suite: 70 passed, ruff clean.

🤖 Generated with Claude Code

…nish a report

The StealthRetriever fed full Bypassed pages into the synthesis prompt, so a
16k-context local model overflowed (~56k–68k tokens) and the report step never
ran — only the 🛡️ badge was written. This broke the README's "local-first, no
API key" promise on a typical small local model.

Cap each document to `max_chars` (default 2000) before it reaches the research
loop. Verified live against a local 16k llama-server (Qwen) + SearXNG: the same
run that previously errored now Bypasses 20 Cloudflare/Turnstile walls AND writes
a substantive cited report (prompt dropped 68k -> well under 16k).

Pure `_cap_content` helper is unit-tested (langchain-free, CI-safe).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
deepcloak Ready Ready Preview, Comment Jun 5, 2026 12:19am

Request Review

@Mrbaeksang Mrbaeksang merged commit e1196a2 into main Jun 5, 2026
4 checks passed
@Mrbaeksang Mrbaeksang deleted the feat/retriever-content-cap branch June 5, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant