AI Chat with database #52075
Unanswered
tarunpahade18
asked this question in
Feature Requests
Replies: 1 comment
|
The safe way to build this is to not let the model talk to the database directly. Give it a few tools you write yourself. Each tool runs as the signed-in user, so your RLS policies decide what it can see. In an Edge Function or a Next.js route, create the client with the caller's JWT, not the service_role key: const supabase = createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, {
global: { headers: { Authorization: req.headers.get('Authorization')! } },
})
// a "tool" the model can call
async function searchDocuments(q: string) {
const { data, error } = await supabase
.from('documents')
.select('id, title, content')
.ilike('title', `%${q}%`)
.limit(5)
if (error) throw error
return data
}A few rules that save trouble later:
Supabase also just shipped a template for exactly this, an MCP server for your app where each request runs as the signed-in user: https://github.com/orgs/supabase/discussions/52171 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
AI to interact with database where people user ai chat that can query database answer documents retrive data make api calls
All reactions