Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
feat: complete the supabase adapter method
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcodercrane committed Oct 31, 2023
1 parent 8b3ed23 commit e431c79
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
32 changes: 29 additions & 3 deletions src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,33 @@ export const _approveLabelChange = async (changeId: number) => {
* @param issue - The issue number
* @param embeddings - The vector of floating point numbers
*/
export const upsertEmbeddings = async (org: string, repo: string, issue: number, embeddings: Array<number>) => {
// TODO: Insert or Update embeddings data
return;
export const upsertEmbeddings = async (org: string, repo: string, issue: number, embedding: number[]) => {
const { supabase } = getAdapters();
const logger = getLogger();
const { data } = await supabase.from("embeddings").select("*").eq("org", org).eq("repo", repo).eq("issue", issue).single();
if (data) {
// Update the existing record with the new embedding for a given set.
const id = data["id"] as number;
const { error } = await supabase.from("embeddings").upsert({
id: id,
embedding,
updated_at: new Date().toISOString(),
});
if (error) {
logger.info(`Updating embedding table failed. id: ${id}, org: ${org}, repo: ${repo}, issue: ${issue}, embedding: ${embedding.join(", ")}`);
}
} else {
// Insert a new record to the `embeddings` table.
const { error } = await supabase.from("embeddings").upsert({
org,
repo,
issue,
embedding,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
});
if (error) {
logger.info(`Inserting to embedding table failed. org: ${org}, repo: ${repo}, issue: ${issue}, embedding: ${embedding.join(", ")}`);
}
}
};
4 changes: 2 additions & 2 deletions supabase/migrations/20231030085814_create_embedding_table.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Creates the `embeddings` table to store embeddings for every issue
-- Creates the `embeddings` table to store an embedding for every issue
-- We've decided to use the `text-embedding-ada-002` model in the beginning which has 1536 output dimensions
CREATE TABLE IF NOT EXISTS embeddings (
id serial PRIMARY KEY,
org character varying(255) NOT NULL,
repo character varying(255) NOT NULL,
issue integer NOT NULL,
embeddings vector(1536) NOT NULL,
embedding vector(1536) NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
);

0 comments on commit e431c79

Please sign in to comment.