Skip to content

fix(knowledge): optimize search and trace pipeline latency - #7782

Merged
waleedlatif1 merged 3 commits into
stagingfrom
codex/fix-document-search-latency
Sep 11, 2026
Merged

fix(knowledge): optimize search and trace pipeline latency#7782
waleedlatif1 merged 3 commits into
stagingfrom
codex/fix-document-search-latency

Conversation

@icecrasher321

@icecrasher321 icecrasher321 commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Keep broad permission-filtered vector searches on HNSW in the shared query layer. Probe visible IDs without reading vectors, rank small scopes by those bounded IDs, and restart exact fallback from its own cursor for underfilled approximate pages. Deduplicate previously considered candidates and preserve distance ranking across refills. Live source authorization still gates content.
  • Add correlated pipeline timings for Assistant and Search, including active-stage reports for stalled calls, provenance, billing, provider authorization, SQL, and result presentation. Record UTF-8 output/passage byte counts without content, and correct the final tool trace to measure bytes rather than characters.
  • Add an opt-in PostgreSQL/pgvector harness that calls the real Assistant tool and compares identical Search-tab requests across a 30,000-chunk synthetic corpus, selective permissions, revocation, concurrent calls, and organization scope. Correct the ACL-transition test to cover pending and completed rewrites for candidate and final-read predicates.

Type of Change

  • Bug fix

Testing

  • Synthetic paired SQL benchmark: median vector time including the new probe fell from 81.5 ms to 3.8 ms; buffer accesses fell from 123,278 to 2,403. All 50 returned candidates matched exact ranking in this corpus. These are local SQL measurements, not end-to-end or deployment latency claims.
  • 8 real PostgreSQL/pgvector harness scenarios passed again after review fixes, including saved pipeline diagnostics, passage-size assertions, and matching Search-tab/Assistant SQL. The synthetic 15-passage response was about 54 KB (45 KB of text); local presentation and measurement took 0.4–1.7 ms. No model latency claim is made from this provider-controlled harness.
  • 198 search, tool-execution, and diagnostic tests passed for the review fixes, including exact-cursor restarts, deduplication, cross-page ranking, and UTF-8 size reporting.
  • 224 search/application/diagnostic unit tests, 20 database mock tests, and 66 broader access integration tests passed; one existing integration test was skipped.
  • Full lint, all 26 workspace type checks, all 46 repository audits (including API validation), block-registry validation, generated artifacts, and docs-manifest checks passed.

Run the harness from the repository root with Docker running:

KNOWLEDGE_SEARCH_PERFORMANCE_REPORT_FILE=/tmp/search-performance.json bun run test:search-performance

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)

@icecrasher321
icecrasher321 requested a review from a team as a code owner September 11, 2026 19:42
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Sep 11, 2026 8:06pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable new correctness, security, or repository-rule violation remains.

Summary

  • Keeps broad searches on HNSW while ranking bounded permission scopes exactly.
  • Gives approximate and exact ranking strategies independent cursors, deduplicates considered candidates, and preserves distance ordering across refills.
  • Adds stage timing and UTF-8 byte-count telemetry without logging queries or passage content.
  • Adds an opt-in PostgreSQL/pgvector performance and authorization harness plus targeted regression coverage.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Search request] --> B[Scope and authorization]
  B --> C[Embedding]
  C --> D[Permission-filtered candidate probe]
  D -->|Broad scope| E[HNSW ranking]
  D -->|Bounded scope| F[Exact ranking by candidate IDs]
  E --> G[Live source authorization and hydration]
  F --> G
  G -->|Underfilled ANN page| H[Exact fallback with independent cursor]
  H --> G
  G --> I[Deduplicate and distance-rank]
  I --> J[Present results]
  J --> K[Content-free timing and byte diagnostics]
Loading

Reviews (2) · Last reviewed commit: "fix(knowledge): preserve fallback rankin..."

Comment thread apps/sim/lib/knowledge/search/queries.ts Outdated
@icecrasher321
icecrasher321 force-pushed the codex/fix-document-search-latency branch from 35d1d85 to 617ce71 Compare September 11, 2026 20:04
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@waleedlatif1
waleedlatif1 merged commit c4f0815 into staging Sep 11, 2026
42 checks passed
@waleedlatif1
waleedlatif1 deleted the codex/fix-document-search-latency branch September 11, 2026 20:23
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.

2 participants