Hybrid Search
Hybrid search runs both full-text and semantic search in parallel, then merges the results. This gives you exact keyword matches alongside conceptually related content, producing the most comprehensive results.How it works
- Your query is sent to both search engines simultaneously.
- Full-text search matches against
sessions.searchableTextusing Convex’s search indexes. - Semantic search converts the query to an embedding and matches against
sessionEmbeddingsusing cosine similarity. - Results from both are merged using a weighted scoring formula.
- Sessions that appear in both result sets receive a boost.
Scoring formula
| Weight | Value | Description |
|---|---|---|
weight_fulltext | 0.5 | Weight for keyword match score |
weight_semantic | 0.5 | Weight for embedding similarity score |
overlap_boost | 0.1 | Bonus for sessions appearing in both result sets |
When to use hybrid search
| Scenario | Recommended search |
|---|---|
| You know the exact function name | Full-text |
| You want to describe a concept | Semantic |
| You want comprehensive results | Hybrid |
| Building a RAG pipeline | Hybrid |
| Debugging a specific error message | Full-text |
| Finding similar past solutions | Semantic |
Using in the dashboard
The Context tab in the dashboard supports a hybrid mode:- Open the Context tab.
- Select Hybrid as the search type.
- Enter your query.
- Results show combined rankings with scores from both engines.
Using via API
matchedIn field indicates which search engine(s) found the result.
Use case: RAG pipeline
Hybrid search is ideal for Retrieval-Augmented Generation because it retrieves both precise matches (from full-text) and conceptually related context (from semantic):/api/context endpoint uses hybrid search internally and returns results formatted for LLM prompt injection.
Example RAG flow
- User asks a question in your application.
- Your backend queries
/api/contextwith the user’s question. - The top results are injected into the system prompt.
- The LLM responds with knowledge from your past sessions.
Comparison
| Feature | Full-text | Semantic | Hybrid |
|---|---|---|---|
| Exact keyword matches | Excellent | Poor | Good |
| Conceptual similarity | Poor | Excellent | Excellent |
| Speed | Fast | Moderate | Moderate |
| Cost | Free | OpenAI API | OpenAI API |
| Best for | Specific terms | Natural language | Comprehensive retrieval |
Requirements
Hybrid search requires:- OpenAI API key (for the semantic component)
- Embeddings generated for your sessions