A Next.js application that leverages Supabase and OpenAI embeddings to provide semantic search capabilities for travel recommendations sourced from Reddit.
- Semantic Search: Uses OpenAI embeddings to find relevant travel recommendations based on user queries.
- Hybrid Search: Combines vector similarity search with traditional text search for optimal results.
- User Feedback System: Collects and stores user feedback on search results to improve future search quality.
- Voice Input: Supports voice input for natural query entry.
- Secure API Layer: Server-side API routes protect sensitive credentials and provide rate limiting.
- Frontend: Next.js with TypeScript and TailwindCSS
- Backend: Supabase database and Edge Functions
- API Layer: Next.js API Routes for secure server-side operations
- Search: Hybrid search using PostgreSQL's vector extension and
ts_ranktext search - Embeddings: OpenAI for generating vector embeddings
- Security: Middleware for rate limiting and security headers
First, set up your environment variables:
# Create .env.local file
cp .env.example .env.local
# Fill in the required valuesThen, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
The application provides the following API routes:
/api/search: Main search endpoint that orchestrates the entire search process/api/query-analysis: Analyzes user queries to extract intent, entities, and topics/api/embeddings: Generates vector embeddings for search queries/api/feedback: Collects user feedback on search results
All API routes are protected by rate limiting and include proper error handling.
This project requires a Supabase project with the following components:
-
Database Tables:
reddit_posts: Stores posts with embeddingsreddit_comments: Stores comments with embeddingscontent_chunks: Stores chunked content for long posts/commentsembedding_metrics: Tracks embedding processing metricssearch_feedback: Stores user feedback on search results
-
Edge Functions:
query-analysis: Analyzes user queries for intent and entitiesquery-embeddings: Generates embeddings for search queriesfeedback: Records user feedback on search resultsembed: Processes content for embedding generationprocess-queue: Processes the embedding queue
-
Vector Extension:
- The project uses pgvector for similarity search
The following environment variables are required:
# Supabase Configuration (Server-side)
SUPABASE_URL=your-supabase-url
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
SUPABASE_ANON_KEY=your-anon-key
# Supabase Configuration (Client-side)
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
# Security Configuration
API_RATE_LIMIT=60 # Requests per minute allowed for API routes
# OpenAI
OPENAI_API_KEY=your-openai-key
# Optional: Direct PostgreSQL connection
DATABASE_URL=your-postgres-connection-string
# Optional: Reddit API (for data collection)
REDDIT_CLIENT_ID=your-reddit-client-id
REDDIT_CLIENT_SECRET=your-reddit-client-secret
REDDIT_USERNAME=your-reddit-username
REDDIT_PASSWORD=your-reddit-password
# Optional: Logging Configuration
LOG_LEVEL=info # debug, info, warn, error
The application includes several security features:
- Rate Limiting: Prevents abuse of API endpoints
- Security Headers: Protects against common web vulnerabilities
- Server-side API Keys: Keeps sensitive credentials secure
- Error Handling: Prevents leaking sensitive information in error messages
To deploy the Edge Functions to Supabase, you can use the Supabase dashboard:
- Navigate to your Supabase project
- Go to Edge Functions
- Create a new function with the name matching your function directory
- Copy the code from the corresponding function in
supabase/functions/ - Set the required environment variables
- Deploy the function
To learn more about the technologies used:
This repository contains the implementation of an enhanced intent detection system for LocalGuru, a platform that helps users find relevant local information. The system uses advanced natural language processing techniques to detect user intents and provide more relevant search results.
- Intent Detection: Automatically detects user intent from search queries
- Topic Extraction: Identifies key topics and locations in user queries
- Boosted Search Results: Applies different boosting strategies based on detected intent
- Multi-Strategy Search: Combines multiple search strategies for optimal results
-
supabase/migrations/: Contains all database migrations for the project20250313000000_enhanced_intent_search.sql: The latest migration that implements the enhanced intent detection system- Other migrations that set up the database schema and functions
-
tests/: Contains essential test scripts and documentation- Test scripts for verifying the intent detection system
- Deployment scripts for applying migrations
- Documentation of test results
The system currently supports the following intent types:
- recommendation: Queries seeking recommendations for places, activities, etc.
- information: Queries seeking factual information
- comparison: Queries comparing multiple options
- experience: Queries about personal experiences
- local_events: Queries about events in a specific location
- how_to: Queries seeking instructions or guidance
- discovery: Queries about discovering new things
Different boosting strategies are applied based on the detected intent:
- Location Boosting: Applied to recommendation and local_events intents
- Context Enhancement: Applied to how_to and experience intents
- Topic Boosting: Applied to information and discovery intents
- Comparison Boosting: Applied to comparison intents
- Supabase account and project
- PostgreSQL client (psql)
- jq for JSON processing
To deploy the enhanced intent detection system:
- Navigate to the
testsdirectory - Run the deployment script:
./deploy_enhanced_intent_search.sh
To test the enhanced intent detection system:
- Navigate to the
testsdirectory - Run the test scripts:
./test_autodetect_only.sh ./test_meetup_query_autodetect.sh
For detailed test results and analysis, see tests/intent_detection_summary.md.
This project is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.
The Supabase Edge Function 'query-analysis' was failing because it was trying to call a non-existent database function:
Error: Could not find the function public.search_opt.store_query_analysis(p_enhanced_queries, p_entities, p_intent, p_locations, p_query, p_topics, p_user_id) in the schema cache
I've updated the Edge Function to call the correct database function:
// Changed from
'search_opt.store_query_analysis'
// To
'query_analysis'To deploy the fixed edge function:
- Make sure Docker Desktop is running (required for Supabase CLI)
- Run:
npx supabase functions deploy query-analysisIf Docker issues persist, you can manually update the Edge Function through the Supabase Dashboard:
- Go to your Supabase project dashboard
- Navigate to Edge Functions
- Edit the 'query-analysis' function
- Replace 'search_opt.store_query_analysis' with 'query_analysis'
- Save and deploy
If you continue to experience issues:
- Check the Edge Function logs in the Supabase Dashboard
- Verify that your OpenAI API key is valid
- Make sure all required environment variables are set correctly