searchHybrid method
Hybrid search combining vector and keyword (BM25) search.
This method uses Reciprocal Rank Fusion (RRF) to combine:
- Vector search: semantic similarity using embeddings
- BM25 search: keyword matching for exact terms
Use this for better results when searching for:
- Proper nouns (names, product models)
- Technical terms or code snippets
- Exact keyword matches
Parameters:
query: The search query texttopK: Number of results to return (default: 10)vectorWeight: Weight for vector search (0.0-1.0, default: 0.5)bm25Weight: Weight for BM25 search (0.0-1.0, default: 0.5)
Implementation
Future<List<hybrid.HybridSearchResult>> searchHybrid(
String query, {
int topK = 10,
double vectorWeight = 0.5,
double bm25Weight = 0.5,
}) async {
// 1. Generate query embedding
final queryEmbedding = await EmbeddingService.embed(query);
// 2. Perform hybrid search with RRF fusion
final results = await hybrid.searchHybridWeighted(
dbPath: dbPath,
queryText: query,
queryEmbedding: queryEmbedding,
topK: topK,
vectorWeight: vectorWeight,
bm25Weight: bm25Weight,
);
return results;
}