rag.format

Format search hits into a numbered, human-readable text string.

Format search hits into a numbered, human-readable text string.

format_hits(hits, max_chars=None, include_parent=True)[source]

Format search hits into a numbered, human-readable text string.

Each hit is rendered with its index, source, relevance score, content, and optionally a snippet of its parent context.

Parameters:
  • hits (list[SearchHit]) – List of SearchHit objects to format.

  • max_chars (int | None) – Optional character budget; hits beyond the budget are omitted.

  • include_parent (bool) – Whether to include parent-context snippets.

Returns:

A formatted string, or an empty string if hits is empty.

Return type:

str

Functions

format_hits(hits, max_chars=None, include_parent=True)[source]

Format search hits into a numbered, human-readable text string.

Each hit is rendered with its index, source, relevance score, content, and optionally a snippet of its parent context.

Parameters:
  • hits (list[SearchHit]) – List of SearchHit objects to format.

  • max_chars (int | None) – Optional character budget; hits beyond the budget are omitted.

  • include_parent (bool) – Whether to include parent-context snippets.

Returns:

A formatted string, or an empty string if hits is empty.

Return type:

str