Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add langchain quickstart template.

thorwebdev4e4363f01872
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts b/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts
index 77ebefd4d13..b9e54497146 100644
--- a/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts
+++ b/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts
@@ -1169,7 +1169,7 @@ $$;
`.trim(),
},
{
- id: 21,
+ id: 22,
type: 'template',
title: 'Replication status report',
description: 'See the status of your replication slots and replication lag.',
@@ -1185,6 +1185,52 @@ FROM pg_control_checkpoint(), pg_replication_slots s
LEFT JOIN pg_stat_replication r ON (r.pid = s.active_pid);
`,
},
+ {
+ id: 23,
+ type: 'quickstart',
+ title: 'LangChain',
+ description: 'LangChain is a popular framework for working with AI, Vectors, and embeddings.',
+ sql: `
+-- Enable the pgvector extension to work with embedding vectors
+create extension vector;
+
+-- Create a table to store your documents
+create table documents (
+ id bigserial primary key,
+ content text, -- corresponds to Document.pageContent
+ metadata jsonb, -- corresponds to Document.metadata
+ embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
+);
+
+-- Create a function to search for documents
+create 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 - (documents.embedding <=> query_embedding) as similarity
+ from documents
+ where metadata @> filter
+ order by documents.embedding <=> query_embedding
+ limit match_count;
+end;
+$$;
+`.trim(),
+ },
]
export const SQL_SNIPPET_SCHEMA_VERSION = '1.0'