Semantic search with embeddings
Explore semantic search using embeddings and PostgreSQL pgvector extension.
Foundation for RAG systems using Supabase as the vector store.
// Vector Database Search Implementation
val openAI = OpenAI(apiKey = "your-openai-api-key")
val supabase = Supabase(url = "your-supabase-url", key = "your-key")
// Step 1: Convert query to embedding vector
val queryEmbedding = openAI.createEmbedding("action packed thriller")
// Step 2: Search for similar documents using pgvector
val matches = supabase.matchDocuments(queryEmbedding, maxMatches = 5)
// Results contain similarity scores and document content
matches.forEach { match ->
println("Similarity: ${match.similarity}")
println("Content: ${match.content}")
}
openAI.close()
supabase.close()