René's URL Explorer Experiment


Title: feat(knowledge): read a PDF's text layer before paying for OCR by waleedlatif1 · Pull Request #6850 · simstudioai/sim · GitHub

Open Graph Title: feat(knowledge): read a PDF's text layer before paying for OCR by waleedlatif1 · Pull Request #6850 · simstudioai/sim

X Title: feat(knowledge): read a PDF's text layer before paying for OCR by waleedlatif1 · Pull Request #6850 · simstudioai/sim

Description: Every PDF is sent to OCR — an external, per-document call — even though most carry an embedded text layer that costs nothing to read. This reads the text layer first and reserves OCR for the documents that actually need it. The evidence Across a real corpus of 2,693 PDFs that exist both ways (locally extracted and OCR'd): Local extraction produced nothing 0 Local within 70% of OCR's character volume 2,515 (93%) Local materially under-extracted 178 (7%) Separately, of ~1,480 PDFs in that library only ~9% genuinely lacked a text layer. So the large majority of OCR calls were buying nothing. One caveat stated plainly: local extraction returned more characters than OCR on average (116K vs 14K), which is not local winning — pdfjs emits positioning noise where OCR returns clean markdown. Character volume demonstrates coverage, not fidelity. That is why the threshold is tunable and the routing is logged. How a text layer is judged Three independent failure modes, none of which catches the others. Taken from prior art rather than invented — pdfmux documents a text-density check, and docling#2963 describes the corrupted-layer cases: No text — a scan. Sparse text — present but too thin to be the document, e.g. a header or stamp on a scanned page. Measured per page, since a total-character floor cannot tell a short memo from a long scan. Text that is not language — a broken encoding, or the raw character ids a CID-keyed font emits when it has no ToUnicode map (/31 /8 /18 /12). This one matters here: it produces plenty of characters, so a length check reads it as healthy, and it is common in documents from older generators and subset fonts — much of the contract and procurement material that reaches a knowledge base. KB_PDF_MIN_CHARS_PER_PAGE (default 100) moves the balance toward cost or fidelity without a deploy. A typeset page carries roughly 1,500–3,000 characters and a scan carries none, so the gap is wide and the threshold does not need to be precise. Beyond cost This narrows an availability dependency. Previously an OCR outage failed every PDF; now it only reaches the minority that cannot be read locally. That materially reduces the blast radius of the one failure mode this design deliberately does not paper over with a silent fallback. Known limitation The judgement is per document, so a file mixing typeset pages with scanned inserts can average above the threshold and keep its partial text. Per-page routing would catch it and needs per-page extraction we do not currently have. Called out rather than hidden — it is the natural next refinement. One behavioural change worth review attention assertKnowledgeOpaqueModelInputSafe now runs after the local read rather than before it, because the local read is what decides whether OCR is needed at all. The guarantee is unchanged: bytes never reach an external model when the projection is refused. The refusal simply fires at the outbound request instead of the storage read, and its test now asserts against fetch accordingly. This is consistent with the case directly above it in that file, which establishes that local parsing is not model egress. It is also the better ordering — a secret-bearing PDF with a usable text layer is now indexed locally instead of being refused for an external call that never happens. Testing vitest run lib/knowledge/ lib/uploads/ lib/file-parsers/ connectors/ app/api/knowledge/ — 2,020 passed (131 files) pdf-text-layer.test.ts — 9 cases: typeset document, scan, sparse text, CID escapes, replacement characters, prose containing slashes and digits, accented and non-Latin text, unknown page count, and threshold scaling with length pdf-ocr-triage.test.ts — 4 routing cases: text layer used with no OCR call, and fallthrough on scan, CID escapes, and an unparseable PDF. Verified the first fails when the triage is disabled bun run check:audits — 29/29 tsgo --noEmit — no errors in changed files Checklist Self-reviewed No secrets or customer data introduced

Open Graph Description: Every PDF is sent to OCR — an external, per-document call — even though most carry an embedded text layer that costs nothing to read. This reads the text layer first and reserves OCR for the docume...

X Description: Every PDF is sent to OCR — an external, per-document call — even though most carry an embedded text layer that costs nothing to read. This reads the text layer first and reserves OCR for the docume...

Opengraph URL: https://github.com/simstudioai/sim/pull/6850

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:0eedf6ea-84ce-69e9-d8d6-2361c460fd4d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE6A8:858A:BB5C85:1092951:6AFB5E20
html-safe-noncebac9db084296431993bdf4adca59b5cd8cfee44046514e9528645c664c2645c9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkE4Ojg1OEE6QkI1Qzg1OjEwOTI5NTE6NkFGQjVFMjAiLCJ2aXNpdG9yX2lkIjoiMjM4MzIwOTM4MTE2NjY4OTYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac33986cfa3fce9481cb2343bf7f6fabacb7888065e2df95c911483f3b0e024eb7
hovercard-subject-tagpull_request:4316144574
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6850/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altEvery PDF is sent to OCR — an external, per-document call — even though most carry an embedded text layer that costs nothing to read. This reads the text layer first and reserves OCR for the docume...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release59ef97164c52cf59bd10558ddec9c4f482763988
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/6850/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6850%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6850%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/6850/files
Reloadhttps://github.com/simstudioai/sim/pull/6850/files
Reloadhttps://github.com/simstudioai/sim/pull/6850/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests197 (197)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
staginghttps://github.com/simstudioai/sim/tree/staging
feat/pdf-ocr-triagehttps://github.com/simstudioai/sim/tree/feat/pdf-ocr-triage
Conversation 28 https://github.com/simstudioai/sim/pull/6850
Commits 6 https://github.com/simstudioai/sim/pull/6850/commits
Checks 30 https://github.com/simstudioai/sim/pull/6850/checks
Files changed https://github.com/simstudioai/sim/pull/6850/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
feat(knowledge): read a PDF's text layer before paying for OCR https://github.com/simstudioai/sim/pull/6850/files#top
Show all changes 6 commits https://github.com/simstudioai/sim/pull/6850/files
78bb3d6 feat(knowledge): read a PDF's text layer before paying for OCR waleedlatif1 Aug 19, 2026 https://github.com/simstudioai/sim/pull/6850/commits/78bb3d6072f5e126a2ad4de81bd53612eb86db6a
fbfe406 fix(knowledge): route a truncated PDF extraction to OCR, and drop the… waleedlatif1 Aug 19, 2026 https://github.com/simstudioai/sim/pull/6850/commits/fbfe4062fe56acd1bfb2790062b244dab4b968f9
47cd6e1 fix(knowledge): take the page count from the parse that produced the … waleedlatif1 Aug 19, 2026 https://github.com/simstudioai/sim/pull/6850/commits/47cd6e10002a684651fea3d13128c2e8e12d81aa
58aa669 fix(knowledge): chunk a long PDF for Azure OCR instead of refusing it waleedlatif1 Aug 19, 2026 https://github.com/simstudioai/sim/pull/6850/commits/58aa669eae9d24661c96a945b133b3d4401a8b55
fc8af91 fix(knowledge): keep an unsplittable PDF and an empty OCR response ho… waleedlatif1 Aug 19, 2026 https://github.com/simstudioai/sim/pull/6850/commits/fc8af91164e4fe3261cbe0bfd7ae3fd3db2b65ec
0dabda6 fix(knowledge): fail a PDF whose OCR only partly came back waleedlatif1 Aug 19, 2026 https://github.com/simstudioai/sim/pull/6850/commits/0dabda6cdf4af0d0234619bcf34e46e2cbcc05ed
Clear filters https://github.com/simstudioai/sim/pull/6850/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
document-processor-secret-provenance.test.ts https://github.com/simstudioai/sim/pull/6850/files#diff-0c29ef408fce32f11d0455ec151b9dc1646f04cbe2351a3863fbf52def2b40d9
document-processor.ts https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
pdf-ocr-triage.test.ts https://github.com/simstudioai/sim/pull/6850/files#diff-d93c6c0c2f53dbf88d4a592072609bfbef74f8b0c7a5189ac6818b2d5e1eee7e
pdf-text-layer.test.ts https://github.com/simstudioai/sim/pull/6850/files#diff-9e22ff6548540b1bff54a67e84f99cd846da6b700ddf1a18faa968af751189e2
pdf-text-layer.ts https://github.com/simstudioai/sim/pull/6850/files#diff-69114eecbd756e5111a83cdd6cb4e8aebb68200244b93e82efdd5ae9d7a106c8
apps/sim/lib/knowledge/documents/document-processor-secret-provenance.test.tshttps://github.com/simstudioai/sim/pull/6850/files#diff-0c29ef408fce32f11d0455ec151b9dc1646f04cbe2351a3863fbf52def2b40d9
View file https://github.com/simstudioai/sim/blob/0dabda6cdf4af0d0234619bcf34e46e2cbcc05ed/apps/sim/lib/knowledge/documents/document-processor-secret-provenance.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6850/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6850/files#diff-0c29ef408fce32f11d0455ec151b9dc1646f04cbe2351a3863fbf52def2b40d9
https://github.com/simstudioai/sim/pull/6850/files#diff-0c29ef408fce32f11d0455ec151b9dc1646f04cbe2351a3863fbf52def2b40d9
https://github.com/simstudioai/sim/pull/6850/files#diff-0c29ef408fce32f11d0455ec151b9dc1646f04cbe2351a3863fbf52def2b40d9
apps/sim/lib/knowledge/documents/document-processor.tshttps://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
View file https://github.com/simstudioai/sim/blob/0dabda6cdf4af0d0234619bcf34e46e2cbcc05ed/apps/sim/lib/knowledge/documents/document-processor.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6850/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
https://github.com/simstudioai/sim/pull/6850/files#diff-caef18c7f5680f8ad0ec1e40b90e7635fe8f182b55d4fd20ef78fbe881f11205
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6850/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.