searchHybridWithContext method

Future<RagSearchResult> searchHybridWithContext(
  1. String query, {
  2. int topK = 10,
  3. int tokenBudget = 2000,
  4. ContextStrategy strategy = ContextStrategy.relevanceFirst,
  5. double vectorWeight = 0.2,
  6. double bm25Weight = 0.8,
  7. List<int>? sourceIds,
  8. int adjacentChunks = 0,
  9. bool singleSourceMode = false,
  10. String? collectionId,
})

Hybrid search with context assembly for LLM.

adjacentChunks - Include N chunks before/after matches (default: 0). singleSourceMode - Only include chunks from most relevant source.

Implementation

Future<RagSearchResult> searchHybridWithContext(
  String query, {
  int topK = 10,
  int tokenBudget = 2000,
  ContextStrategy strategy = ContextStrategy.relevanceFirst,
  double vectorWeight = 0.2,
  double bm25Weight = 0.8,
  List<int>? sourceIds,
  int adjacentChunks = 0,
  bool singleSourceMode = false,
  String? collectionId,
}) async {
  final service = await _serviceForCollection(collectionId);
  await _flushIndex(
    collectionId: collectionId,
  ); // Ensure index is up-to-date before searching
  return service.searchHybridWithContext(
    query,
    topK: topK,
    tokenBudget: tokenBudget,
    strategy: strategy,
    vectorWeight: vectorWeight,
    bm25Weight: bm25Weight,
    sourceIds: sourceIds,
    adjacentChunks: adjacentChunks,
    singleSourceMode: singleSourceMode,
  );
}