Skip to content

improvement(knowledge): score the page on the original vectors, resolve a search's context once, and read identities off the walk - #8100

Merged
waleedlatif1 merged 6 commits into
stagingfrom
fix/search-page-full-rerank-and-pdf-chunk-test
Sep 21, 2026
Merged

waleedlatif1 merged 6 commits into
stagingfrom
fix/search-page-full-rerank-and-pdf-chunk-test

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Page scored on the original vectors, page-sized. Hydration reads one out-of-line vector per hydrated row (the page, 60 rows for the dashboard) and both legs report that distance, so one response carries one distance scale. On a production-shaped copy, 20 queries, recall@20 against the exact full-vector ranking of a 2,000-candidate pool: projection order alone 0.908, page rescored 0.995, 200-row rescore 0.998. The walk and the candidate threshold stay on the projection, so the novel-query cost removed earlier stays removed.
  • A search's context is resolved once. The workspace, organization and scoped search use cases resolved and authorized their owner, then invoked the inner search use case, which read the organization, the membership and the knowledge base again. The index lookup now returns the reference the search runs over, and the scoped use cases run the shared search body (runKnowledgeSearch) under their own context, with the same after-success hook. Three round trips and one nested application stage gone per search; the reference shape lives in one module both lookups read.
  • Candidate identities come off the walk. Every walk selects the projection row's document and source, so once the projection is filled the page needs no further read before hydration; while the fill runs, the page is still read off the documents (a row the fill has not reached carries no source). The projection-fill probe is the search's own read under its budget, cached for a minute, so one search's deadline never fails another's; a bounded permitted set that is empty reads nothing.
  • Less serial work ahead of retrieval. The embedding is requested the moment admission passes, beside the access-scope, defaults, tag-definition and reranker-credential reads instead of after all of them; the organization billing payer's two independent reads run together; an organization's access availability is memoized by organization alone, not per viewer; the keyword hydration no longer joins the projection it does not read. The three scoped search surfaces are one factory that differs only in how it names the owner and finds the index, with the index-less path shared.
  • pdf-ocr-chunking.test.ts flaked in CI (expected 2 to be 1): pdf-lib stamps the modification date into each save and deflates the object streams, so two builds of the same pages a second apart can differ by a byte, and the test derives a byte budget from one build and applies it to another. The test now pins the clock.

Type of Change

  • Improvement

Testing

  • Unit tests: the hydration test asserts the page is scored on the original vector while the threshold still reads the projection; the queries fixtures that model the page read run against an unfilled projection, and new cases cover the filled projection (no page read, identities off the walk, exclusion on the row); the scoped search tests assert the search runs under the context the use case resolved; the schema mock carries the projection's mirrored columns.
  • Staging profile on this branch (server critical path p50, common/medium/rare): 69/21/9 ms, every query complete, one retrieval statement fewer per search.
  • bun run lint, check:audits, type-check pass; 4,426 tests pass across knowledge, billing, navigation, the tool adapters and the search routes.

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)

@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 21, 2026 6:31am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previous findings are resolved and the latest test-isolation change introduces no actionable regression.

Summary

This PR improves knowledge-search accuracy and latency while consolidating authorization context resolution.

  • Rescores hydrated result pages with original vectors while retaining projection-based candidate traversal.
  • Reuses already-authorized search contexts across workspace, organization, and scoped search surfaces.
  • Reads candidate identities directly from a filled projection and memoizes projection-fill detection.
  • Parallelizes independent billing, access, credential, and search prerequisite reads.
  • Stabilizes the PDF OCR chunking test by pinning time-dependent PDF metadata.
  • Changes since the previous review isolate the projection-fill memo between integration-test iterations.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Scoped search request] --> B[Validate input]
  B --> C[Resolve and authorize owner context]
  C --> D[Build shared search context]
  D --> E[Run admission and prerequisite reads]
  E --> F[Generate query embedding]
  F --> G[Projection candidate walk]
  G --> H[Read candidate identities]
  H --> I[Hydrate page and score original vectors]
  I --> J[Optional reranking]
  J --> K[Record usage and search activity]
  K --> L[Return results]
Loading

Reviews (5) · Last reviewed commit: "improvement(knowledge): reset the projec..."

Comment thread apps/sim/lib/knowledge/search/queries.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/knowledge/search/queries.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Comment thread apps/sim/lib/knowledge/search/queries.ts
@waleedlatif1 waleedlatif1 changed the title improvement(knowledge): score the vector page on the original vectors and pin the clock in the PDF chunk test improvement(knowledge): score the page on the original vectors, resolve a search's context once, and read identities off the walk Sep 21, 2026
…ps, admission ahead of the embedding beside the scope reads
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 14 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/knowledge/application/search.ts Outdated
Comment thread apps/sim/lib/knowledge/application/workspace-search.ts
…fuse a contradicting owner, count the shared fill read
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 15 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 15 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit bc2f641 into staging Sep 21, 2026
25 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/search-page-full-rerank-and-pdf-chunk-test branch September 21, 2026 06:35

This branch was previously deployed

1 inactive deployment
Preview 28c0359c Deployed Sep 21, 2026 by vercel[bot]
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