Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sql functions not updated #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions supabase/migrations/20241002004403_issue_comments.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DROP FUNCTION IF EXISTS find_similar_issues;

CREATE OR REPLACE FUNCTION find_similar_issues(current_id VARCHAR, query_embedding vector(1024), threshold float8, top_k INT)
RETURNS TABLE(issue_id VARCHAR, issue_plaintext TEXT, similarity float8) AS $$
DECLARE
Expand Down
33 changes: 33 additions & 0 deletions supabase/migrations/20241016000744_function_issue.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
DROP FUNCTION IF EXISTS find_similar_issues;

CREATE OR REPLACE FUNCTION find_similar_issues(current_id VARCHAR, query_embedding vector(1024), threshold float8, top_k INT)
RETURNS TABLE(issue_id VARCHAR, issue_plaintext TEXT, similarity float8) AS $$
DECLARE
current_quantized vector(1024);
current_repo TEXT;
current_org TEXT;
BEGIN
-- Ensure the query_embedding is in the correct format
current_quantized := query_embedding;

-- Extract the current issue's repo and org from the payload
SELECT
payload->'repository'->>'name'::text,
payload->'repository'->'owner'->>'login'::text
INTO current_repo, current_org
FROM issues
WHERE id = current_id;

RETURN QUERY
SELECT id AS issue_id,
plaintext AS issue_plaintext,
((0.5 * inner_product(current_quantized, embedding)) + 0.5 * (1 / (1 + l2_distance(current_quantized, embedding)))) as similarity
FROM issues
WHERE id <> current_id
AND COALESCE(payload->'repository'->>'name', '') = COALESCE(current_repo, '') -- To handle Private Issues
AND COALESCE(payload->'repository'->'owner'->>'login', '') = COALESCE(current_org, '') -- To handle Private Issues
AND ((0.5 * inner_product(current_quantized, embedding)) + 0.5 * (1 / (1 + l2_distance(current_quantized, embedding)))) > threshold
ORDER BY similarity DESC
LIMIT top_k;
END;
$$ LANGUAGE plpgsql;