Title: improvement(knowledge): rank inside the permitted set for organization search by waleedlatif1 · Pull Request #7996 · simstudioai/sim · GitHub
Open Graph Title: improvement(knowledge): rank inside the permitted set for organization search by waleedlatif1 · Pull Request #7996 · simstudioai/sim
X Title: improvement(knowledge): rank inside the permitted set for organization search by waleedlatif1 · Pull Request #7996 · simstudioai/sim
Description: Summary Organization search indexes grant most documents to one mailbox, channel, or file owner, so a typical member can read about 0.1% of the index. Both retrieval legs searched the whole index and checked access afterwards. The vector walk then post-filtered nearly every neighbour away, and common keyword terms ranked matches the member could never see. Resolve the permitted set once. retrieveKnowledgeSearch calls resolvePermittedDocuments before both legs for live user scopes (a user scope with an access provider and no explicit documentIds). It returns bounded (documents plus their connector) or unbounded. The set is resolved with the same candidate predicate both legs apply, so restricting a leg to it can only narrow. Vector. bounded ranks the permitted chunks exactly and skips the HNSW walk. unbounded runs the walk only, with no second tractability probe. Keyword. bounded reads the permitted chunks directly through embedding_keyword_search_document_idx, using an OFFSET 0 fenced subquery aliased as the table. Base, enabled, tsquery and tag checks are applied outside it. The existing visibility CTE still re-applies the candidate predicate. Probe SQL (user scopes). It counts the documents the caller's tokens reach inside the requested bases, up to the limit. It reads doc_acl_gin_idx (deleted_at IS NULL AND acl && tokens) inside an OFFSET 0 fence and applies the base check to the rows the index returns, so the planner cannot swap to a whole-base heap scan. The count is base-scoped because the baseline tokens (pub/ws/org) are shared by every tenant; a global count would saturate for nearly every caller. Only when the count is under the limit does it materialize those rows and apply the base, state and full candidate access conditions in memory. Over the limit, a saturated sentinel row reports unbounded. Resolved scopes keep the plain form. Members-mode access clause. The row-value IN (subquery) is now a correlated EXISTS, served by the observation PK (document_id, member_id). Semantics are identical: every compared column is NOT NULL, and the clause sits inside the connector EXISTS, so document.connector_id is non-null there. PostgreSQL no longer hashes every observation once per statement. Excluded sources and timeouts. Sources excluded by live authorization are dropped from the permitted set on refill; uploads with a null connector stay. An empty set short-circuits both legs. If the vector budget runs out during resolution, the result is unbounded and the vector leg is marked timed out; the keyword leg is not failed. Diagnostics. New stage permitted_documents and new metadata permittedDocuments / permittedDocumentCount. Evidence Server-side execution time on a restored copy of a large organization search index, measured with the same members and queries on main and on this branch: Typical member, keyword: common term: 1640 ms → 42 ms; rare term: 8 → 23 ms. Typical member, vector: Before: the HNSW walk found 0–16 of 1600 candidates after 0.7–3.4 s, then the tractability probe timed out at 600 ms. Now: permitted set 37 ms + exact ranking 17 ms + rerank 53 ms, with complete results. Replay recall went from 13–14 of 20 to 20 of 20. Member whose tokens reach several times the probe limit: hydration and rerank each 142–188 ms → ~1 ms, from the members-mode EXISTS; probe 2.0 s warm / 11.8 s cold → ~200 ms; rare keyword 319 → 2 ms. Unchanged: the unbounded common-term keyword path stays at ~2.3 s. A follow-up addresses it. Calibration: Exact vector ranking costs ~3 µs per permitted chunk: 7 ms at 1k documents, 513 ms at 100k. The HNSW walk only fills when a member can read roughly 20% or more of the index, so the bounded/unbounded split stays at the existing VECTOR_PROBE_DOCUMENT_LIMIT (100k documents). Keyword: the direct read and the text-index intersection cost about the same on common terms, but the planner misplanned the index form for real members (147–180 ms vs 23–42 ms). Bounded keyword therefore always uses the direct read. Type of Change Improvement (performance) Testing 11 new planner unit tests, plus a real-Postgres test: VECTOR_PROBE_DOCUMENT_LIMIT + 1 reachable documents in a sibling base must leave the target base bounded. The unit tests cover bounded exact ranking skips the walk; empty sets; no re-probe when unbounded; keyword confinement; excluded-source refill; saturation; budget exhaustion; resolved once before both legs. Each was confirmed to fail against a broken planner. 2965 knowledge unit tests pass; type-check, lint, check:api-validation and check:audits are clean. Real-Postgres knowledge ACL suite: 501/502. The one failure is a pre-existing organization-personal-tokens test that also fails on staging. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: Summary Organization search indexes grant most documents to one mailbox, channel, or file owner, so a typical member can read about 0.1% of the index. Both retrieval legs searched the whole index a...
X Description: Summary Organization search indexes grant most documents to one mailbox, channel, or file owner, so a typical member can read about 0.1% of the index. Both retrieval legs searched the whole index a...
Opengraph URL: https://github.com/simstudioai/sim/pull/7996
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,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-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5878f1a2-c4c1-1536-b3c6-2b4c8c4344b6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 95D8:73CE1:ED74AC:14535C0:6AFB5F14 |
| html-safe-nonce | e8b2fb5629e03eda4be64aec14f2d22ea5da948088bb75454b1fd2c53f0fc53a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUQ4OjczQ0UxOkVENzRBQzoxNDUzNUMwOjZBRkI1RjE0IiwidmlzaXRvcl9pZCI6IjM1MTQ2ODA2NTE4OTIzNTA3NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0917005c2d288a9a48cd28fccb53304e530403960f3c75643881291b765d1ecd |
| hovercard-subject-tag | pull_request:4574667001 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/7996/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary Organization search indexes grant most documents to one mailbox, channel, or file owner, so a typical member can read about 0.1% of the index. Both retrieval legs searched the whole index a... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 59ef97164c52cf59bd10558ddec9c4f482763988 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width