Skip to content

Use full-text index for semantic document filtering. Improve Doc Queries for Perf#253

Merged
vswamidass-sfdc merged 6 commits into
mainfrom
fix/document-search-vector-query
Jul 4, 2026
Merged

Use full-text index for semantic document filtering. Improve Doc Queries for Perf#253
vswamidass-sfdc merged 6 commits into
mainfrom
fix/document-search-vector-query

Conversation

@vswamidass-sfdc

Copy link
Copy Markdown
Collaborator

Summary

  • replace semantic retrieval text filter from document ILIKE to search_vector @@ plainto_tsquery via a new Document.full_text_match scope
  • keep query behavior unchanged while allowing PostgreSQL to use the existing GIN full-text index
  • remove redundant .not_deleted from default documents index scope to avoid duplicated soft-delete predicates

Test plan

  • Run lint diagnostics for edited files
  • Run a semantic retrieval query with library_search_text present and confirm results still return
  • Compare query plan before/after and verify full-text predicate uses index_documents_on_search_vector

Made with Cursor

vswamidass-sfdc and others added 6 commits July 3, 2026 09:14
Replace ILIKE-based library search text filtering in semantic retrieval with a search_vector full-text scope so PostgreSQL can use the existing GIN index, and remove a redundant deleted filter from document listing.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add concurrent partial indexes on library plus created_at and updated_at for non-deleted documents to speed high-volume library-scoped list and cleanup queries.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Change schema version to 2026_07_03_183252.
- Replace existing partial indexes on documents with new indexes for active documents based on created_at and updated_at, improving query performance for non-deleted documents.
- Reintroduce the `doc_lookback_days` column in the questions table to enhance question-answer retrieval capabilities.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Changed the method for selecting document columns from `select` to `reselect` in the BaseDocumentsController to enhance query performance.
- Updated the embedding status display in the document view to provide clearer information on availability, replacing the raw embedding output with a user-friendly message.
- Added a new script for loading test documents, allowing for bulk creation of documents with customizable parameters for testing purposes.
Drop the ad hoc document seeding script so this PR only contains the intended application and index changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Switch document listing back to select to avoid changing relation select semantics while we continue performance validation.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vswamidass-sfdc vswamidass-sfdc changed the title Use full-text index for semantic document filtering Use full-text index for semantic document filtering. Improve Doc Queries for Perf Jul 3, 2026
@vswamidass-sfdc vswamidass-sfdc merged commit 29bb3a2 into main Jul 4, 2026
4 checks passed
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