Provides a vector/similarity search for any documentation site. It's headless, so that you can integrate it into your existing website.
- This repo initializes a new
docs
schema inside your database. - The accompanying GitHub Action ingests your markdown docs into your database as embeddings.
- This repo provides an Edge Function that handles user queries, converting them into ChatGPT-like responses.
- Supabase: Database & Edge Functions.
- OpenAI: Embeddings and completions.
- GitHub Actions: for ingesting your markdown docs.
Start by creating a new Supabase Project: database.new.
- Clone this repo
- Link the repo to your remote project:
supabase link --project-ref XXX
- Apply the database migrations:
supabase db push
- Set your OpenAI key as a secret:
supabase secrets set OPENAI_API_KEY=sk-xxx
- Deploy the Edge Functions:
supabase functions deploy --no-verify-jwt
- Expose
docs
schema via API in Supabase Dashboard settings >API Settings
>Exposed schemas
- Setup
supabase-vector-embeddings
GitHub action in your Knowledge Base repo. You will see the embeddings populated in your database after the GitHub Action has run.
- Find the URL for the
vector-search
Edge Function in the Functions section of the Dashboard. - Inside your appliction, you can send the user queries to this endpoint to receive a streamed response from OpenAI.
See cURL example
curl -i --location --request GET 'https://your-project-ref.functions.supabase.co/vector-search?query=What%27s+Supabase%3F'
See EventSource example
const onSubmit = (e: Event) => {
e.preventDefault()
answer.value = ""
isLoading.value = true
const query = new URLSearchParams({ query: inputRef.current!.value })
const projectUrl = `https://your-project-ref.functions.supabase.co`
const queryURL = `${projectURL}/${query}`
const eventSource = new EventSource(queryURL)
eventSource.addEventListener("error", (err) => {
isLoading.value = false
console.error(err)
})
eventSource.addEventListener("message", (e: MessageEvent) => {
isLoading.value = false
if (e.data === "[DONE]") {
eventSource.close()
return
}
const completionResponse: CreateCompletionResponse = JSON.parse(e.data)
const text = completionResponse.choices[0].text
answer.value += text
});
isLoading.value = true
}
- docs.supabase.com - Use cmd+k to access.
MIT