ENG-1769 Optimize semantic search by removing LIMIT from function body#1141
ENG-1769 Optimize semantic search by removing LIMIT from function body#1141mdroidian wants to merge 3 commits into
Conversation
- Remove match_count parameter from match_content_embeddings function - Remove LIMIT clause from function body to improve query planner performance - Add space_id parameter for better filtering - Move LIMIT to caller side using Supabase .limit() method - Update TypeScript types to reflect new function signature Co-authored-by: Michael Gartner <mdroidian@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Updates to Preview Branch (cursor/optimize-semantic-search-eng-1769-cec2) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
Focus this PR only on the LIMIT optimization that's killing the planner. The space_id filtering will be addressed in a separate ticket. Co-authored-by: Michael Gartner <mdroidian@users.noreply.github.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68cd04e7be
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Problem
The semantic search functions (
match_content_embeddings) were taking much longer than the underlying queries. This performance degradation was caused by theLIMITbeing passed as a parameter to the function body, which prevented the PostgreSQL query planner from optimizing the query effectively.Solution
This PR implements the optimization suggested in ENG-1769:
match_countparameter frommatch_content_embeddingsfunctionLIMITclause from the function body to allow the query planner to optimize properly.limit()method on the client sideChanges
Database Changes
match_content_embeddingsfunction signature:match_count integerparameterLIMIT match_countclause from function bodyApplication Changes
findSimilarNodesVectorOnlyto use.limit()method.limit()methodPerformance Impact
By removing the
LIMITfrom the function body, the PostgreSQL query planner can now:The function should now have roughly the same performance as running the underlying query directly.
Testing
The changes maintain backward compatibility in terms of behavior:
Linear Issue: ENG-1769