contextForMatches method

KnowledgeSearchResponse contextForMatches(
  1. Iterable<SearchResult> ranked, {
  2. KnowledgeSearchPolicy? policy,
  3. int limit = 5,
  4. int? contextLimit,
})

Applies the same eligibility and context policy to externally ranked hits. Unknown or excluded chunk IDs are ignored. Scores do not establish authority.

Implementation

KnowledgeSearchResponse contextForMatches(
  Iterable<SearchResult> ranked, {
  KnowledgeSearchPolicy? policy,
  int limit = 5,
  int? contextLimit,
}) {
  final snapshot = _snapshot;
  if (snapshot == null || _synchronizing) {
    throw StateError('Synchronize the index before assembling context.');
  }
  final budget = contextLimit ?? limit;
  if (limit <= 0 || budget <= 0) {
    return KnowledgeSearchResponse(matches: [], context: [], notices: []);
  }
  final effective = policy ?? KnowledgeSearchPolicy();
  return _contextForEligible(
    snapshot,
    _eligibleChunks(snapshot, effective),
    ranked,
    policy: effective,
    limit: limit,
    budget: budget,
  );
}