到官網首頁 https://supabase.com/

點選 Start your project 綠色按鈕

點選最下方的 Sign Up Now 使用信箱進行註冊

Supabase註冊頁面

輸入信箱跟密碼進行註冊,然後到註冊信箱收信,完成信箱認證。

Supabase註冊資訊填寫

點選 New Organization

Supabase建立新組織

輸入名稱,這邊先用 n8nTest,其他選項不變,然後按右下角 Create Organization。

Supabase組織設定

Project name 先輸入 n8nProject

資料庫密碼要記好

Region 選地理位置最靠近你的

最後點選右下角 Create new project

Supabase專案設定

完成後畫面

Supabase專案建立完成


接著要建立資料表,先將滑鼠移到左邊邊界,展開左邊選單,點選 SQL Editor

Supabase左側選單SQL Editor

點選 Create a new snippet

Supabase建立新SQL片段

貼上這段語法

drop table if exists nhi_drug_768;

-- Drop the match_{{tablename}} function if it exists -- Note: It's good practice to specify argument types when dropping
drop function if exists match_nhi_drug_768(vector, integer, jsonb);

-- Enable the pgvector extension to work with embedding vectors
create extension if not exists vector;

-- Create a table to store your {{tablename}}
create table nhi_drug_768 (
  id bigserial primary key,
  content text, -- corresponds to Document.pageContent
  metadata jsonb, -- corresponds to Document.metadata
  embedding vector(768) -- 確保這個維度匹配你的 Embedding 模型
);

-- Create a function to search for documents_nhi_drug
create function match_nhi_drug_768 (
  query_embedding vector(768), -- 確保這個維度匹配你的 Embedding 模型
  match_count int default null, -- Using integer alias
  filter jsonb DEFAULT '{}'
) returns table (
  id bigint,
  content text,
  metadata jsonb,
  similarity float
)

language plpgsql
as $$
#variable_conflict use_column
begin
  return query
  select
    d.id,                -- Using alias for clarity
    d.content,
    d.metadata,
    1 - (d.embedding <=> query_embedding) as similarity -- Using alias
  from nhi_drug_768 d   -- Defining alias d
  where d.metadata @> filter
  order by d.embedding <=> query_embedding
  limit match_count;
end;
$$;

點選畫面中間最右側的綠色按鈕 Run

Supabase執行SQL查詢

點選 Run this query,等待數秒。

Supabase確認執行查詢

在下方視窗 Results 可以看到成功訊息

Supabase查詢結果成功訊息

打開左側欄選單,點選 Table Editor

Supabase左側選單Table Editor

看到我們創建的向量資料表已經完成。

接著點選畫面上方的咖啡色按鈕 RLS disabled

Supabase資料表RLS disabled狀態

點選下方的 Enable RLS for this table

Supabase啟用RLS選項

點選綠色的 Enable RLS

Supabase確認啟用RLS

至此資料表設置完畢。


再次打開左邊選單,點選 Project Settings

Supabase左側選單Project Settings

點選 Data API

Supabase專案設定Data API

找到 Project API Keys

點選 service_role 最右側的 Reveal 按鈕

Supabase專案API金鑰

點選後會產生 token,右側的按鈕會變成 Copy,點一下

Supabase API金鑰顯示與複製

把這個 API token 保存在安全的地方,勿外洩。

至此 Supabase 的向量資料庫設置完畢。

回上一頁