用於 AI 代理檢索的 Supabase 向量存儲

說明問題/錯誤/問題

嗨,所以我在嘗試將 Supabase 向量儲存庫與 AI 代理工具連接並實際為我建立的文件進行測試時,再次遇到錯誤。
錯誤是 (PGRST202),它只是無法取回資料訊息,我不知道為什麼。我找到了一個舊主題詢問相同的錯誤:

再次,SQL 編輯器程式碼與此有關,所以我複製貼上了提供的解決方案程式碼,不幸的是,我得到了完全相同的錯誤 :frowning:

錯誤訊息是什麼(如果有的話)?

Error searching for documents: PGRST202 Could not find the function public.match_documents(filter, match_count, query_embedding) in the schema cache Searched for the function public.match_documents with parameters filter, match_count, query_embedding or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.

請分享你的工作流程

關於你的 n8n 設定資訊

  • n8n 版本: 2.35.7
  • 資料庫(預設:SQLite):
  • n8n EXECUTIONS_PROCESS 設定(預設:own, main):
  • n8n 運行方式(Docker、npm、n8n cloud、桌面應用程式): 瀏覽器
  • 作業系統: Windows 11 Home

嗨 @Mazen_Hassan
n8n 的 Supabase 檢索呼叫使用具名引數 filter、match_count 和 query_embedding 來匹配 match_documents,但你昨天執行緒中的設定 SQL 函式聲明使用的是 match_threshold 而不是 filter,所以 PostgREST 找不到具有該簽章的函式,這正是 PGRST202 報告的內容。貼上舊主題中的程式區塊無法修正:該區塊以 create extension vector 開頭,沒有 if not exists,SQL 編輯器將整個貼上內容作為一個批次執行,第一個陳述式在你的專案上出現錯誤,所以底部的 create function 從未執行。
在新的 SQL 編輯器查詢中僅執行以下內容,它會移除舊簽章並建立 n8n 針對你的表格所期望的簽章:

drop function if exists match_documents(vector, float, int);

create or replace function match_documents (
  query_embedding vector(1536),
  match_count int default null,
  filter jsonb default '{}'
) returns table (
  id bigint,
  content text,
  metadata jsonb,
  similarity float
)
language plpgsql
as $$
#variable_conflict use_column
begin
  return query
  select
    id,
    content,
    metadata,
    1 - (knowledge_chunks.embedding <=> query_embedding) as similarity
  from knowledge_chunks
  where metadata @> filter
  order by knowledge_chunks.embedding <=> query_embedding
  limit match_count;
end;
$$;

notify pgrst, 'reload schema';

整個 n8n 中的向量存儲和 RAG 設定涵蓋範圍如下:
https://axshul.site/n8n/guide/vector-stores-and-rag/

嗨 @Anshul_Namdev,我讀了你的回覆,對所要求的內容有了更好的理解,但我在 SQL 編輯器中測試了你的程式碼,並再次嘗試了我的工作流程。仍然得到相同的錯誤 :frowning:

PGRST202 在建立後仍然存在,表示你的工作流程所連接的資料庫仍然沒有具有那三個具名參數的 match_documents,因此該陳述式沒有到達節點查找的位置。在 SQL 編輯器中執行以下命令並查看輸出:

select n.nspname as schema, p.proname, pg_get_function_identity_arguments(p.oid) as arguments
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where p.proname = 'match_documents';

沒有任何列:該程式區塊從未執行。再單獨執行一次,並查看結果面板中的紅色錯誤文字,然後比較 SQL 編輯器 URL 中的專案參考與你的 n8n Supabase 認證中的主機,在編輯一個專案的同時讓工作流程呼叫另一個專案會產生完全相同的問題。
如果 schema 不是 public,或者參數的名稱不是 query_embedding、match_count 和 filter:請按照我上一個回覆中發佈的內容再次執行該程式區塊。
如果有一列的 schema 是 public,且具有那三個名稱:執行 notify pgrst, 'reload schema';(單獨執行),等待一分鐘,然後再次測試工作流程。
如果在那之後仍然失敗,請將該查詢的輸出貼上到這裡。

(貼文已被作者刪除)

「Success. No rows returned」是該區塊在運作。drop,啊我想你已經搞定了。:smiley:

看起來是這樣,非常感謝你 @Anshul_Namdev :smile: — 我只是希望它不會自己再出問題,你說我給它時間重新整理,情況確實是這樣 : )