searchHybridWithContext method
Future<RagSearchResult>
searchHybridWithContext(
- String query, {
- int topK = 10,
- int tokenBudget = 2000,
- ContextStrategy strategy = ContextStrategy.relevanceFirst,
- double vectorWeight = kDefaultVectorWeight,
- double bm25Weight = kDefaultBm25Weight,
- List<
int> ? sourceIds, - int adjacentChunks = 0,
- bool singleSourceMode = false,
- SearchHydrationMode hydrationMode = SearchHydrationMode.full,
- int previewMaxBytes = 512,
- 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.
hydrationMode - Controls whether high-level chunk payloads are returned
as full content, lightweight previews, or omitted entirely.
previewMaxBytes - Maximum UTF-8 bytes per chunk preview when
hydrationMode is SearchHydrationMode.preview.
Implementation
Future<RagSearchResult> searchHybridWithContext(
String query, {
int topK = 10,
int tokenBudget = 2000,
ContextStrategy strategy = ContextStrategy.relevanceFirst,
double vectorWeight = kDefaultVectorWeight,
double bm25Weight = kDefaultBm25Weight,
List<int>? sourceIds,
int adjacentChunks = 0,
bool singleSourceMode = false,
SearchHydrationMode hydrationMode = SearchHydrationMode.full,
int previewMaxBytes = 512,
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,
hydrationMode: hydrationMode,
previewMaxBytes: previewMaxBytes,
);
}