Skip to content
1 min read · 190 words

Function: selectRelevantTurns()

ts
function selectRelevantTurns<M, TC>(
  turns: readonly HistoryTurn<M, TC>[],
  queryText: string,
  options: SelectRelevantTurnsOptions,
): HistoryTurn<M, TC>[];

Defined in: src/batteries/context/thrift/relevance.ts:295

Select which turns to replay by RELEVANCE to the current query: always keep the most recent keepRecent turns, and among the OLDER turns keep any whose relevanceToQuery score against the query's content words clears a floor that scales with how much of the older-history budget is already spoken for (see scaledRelevanceFloor). Walks the ENTIRE history — there is no turn-count cap — so a turn from far in the past survives if it is genuinely relevant, which a recency-only policy (see selectNaiveTurns) can never do.

Type Parameters

Type ParameterDefault type
M extends RelevanceMessageRelevanceMessage
TC extends RelevanceToolCallRelevanceToolCall

Parameters

ParameterTypeDescription
turnsreadonly HistoryTurn<M, TC>[]The full grouped history, chronological, from groupHistoryIntoTurns.
queryTextstringThe current user query (or turn text) to score every older turn against.
optionsSelectRelevantTurnsOptionsSee SelectRelevantTurnsOptions.

Returns

HistoryTurn<M, TC>[]

The surviving turns, in their original chronological order.