-- Create the table createtable notes ( id serial primary key, title text );
-- Insert some sample data insertinto notes (title) values ('Today I created a Supabase project.'), ('I added some data and queried it from Next.js.'), ('It was awesome!');
exportconstupdateSession = async (request: NextRequest) => { // This `try/catch` block is only here for the interactive tutorial. // Feel free to remove once you have Supabase connected. try { // Create an unmodified response let response = NextResponse.next({ request: { headers: request.headers, }, });
const supabase = createServerClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, { cookies: { get(name: string) { return request.cookies.get(name)?.value; }, set(name: string, value: string, options: CookieOptions) { // If the cookie is updated, update the cookies for the request and response request.cookies.set({ name, value, ...options, }); response = NextResponse.next({ request: { headers: request.headers, }, }); response.cookies.set({ name, value, ...options, }); }, remove(name: string, options: CookieOptions) { // If the cookie is removed, update the cookies for the request and response request.cookies.set({ name, value: "", ...options, }); response = NextResponse.next({ request: { headers: request.headers, }, }); response.cookies.set({ name, value: "", ...options, }); }, }, }, );
// This will refresh session if expired - required for Server Components // https://supabase.com/docs/guides/auth/server-side/nextjs await supabase.auth.getUser();
return response; } catch (e) { // If you are here, a Supabase client could not be created! // This is likely because you have not set up environment variables. // Check out http://localhost:3000 for Next Steps. returnNextResponse.next({ request: { headers: request.headers, }, }); } };
returncreateServerClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, { cookies: { get(name: string) { return cookieStore.get(name)?.value; }, set(name: string, value: string, options: CookieOptions) { try { cookieStore.set({ name, value, ...options }); } catch (error) { // The `set` method was called from a Server Component. // This can be ignored if you have middleware refreshing // user sessions. } }, remove(name: string, options: CookieOptions) { try { cookieStore.set({ name, value: "", ...options }); } catch (error) { // The `delete` method was called from a Server Component. // This can be ignored if you have middleware refreshing // user sessions. } }, }, }, ); };
Vector 插件
运行以下 sql 可以引入 vector 插件
1 2 3
create extension vector with schema extensions;
然后使用如下 sql 即可创建一个表:
1 2 3 4 5
createtable documents ( id serial primary key, content text notnull, embedding vector(384) );
使用如下 sql 建立一个语义检索函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
createor replace function match_documents ( query_embedding vector(384), match_threshold float, match_count int ) returns setof documents languagesql as $$ select* from documents where documents.embedding <#> query_embedding <-match_threshold orderby documents.embedding <#> query_embedding asc limit least(match_count, 200); $$;