← Back
00:00

RAG Citation Text Matching and Tagging

Harvey AI interview questions · Hard · Coding round · reported 19× · 6 tests

You are given an LLM answer string and a list of source phrases. Implement a function that does two things:

  1. Report, for every source phrase, the number of times it occurs in the text.
  2. Return the text with every matched region wrapped in <yellow>...</yellow>, followed by citation indices such as [0][2].

Function signature

function annotateCitations(
  text: string,
  sources: string[],
): { counts: number[]; taggedText: string }
Idle