fastrag.query.prompts#

Prompt templates: retrieved documents plus a question to chat messages.

fastrag.query.prompts.group_sources(context)[source]#

Group retrieved chunks into the sources a prompt cites as [n].

Chunks sharing a page_url() (one page, and each page of a PDF apart) form one group, placed where the page’s best-ranked chunk was retrieved and holding its chunks in page order (chunk_index). A chunk with no URL is a group of its own. groups[n - 1] is what [n] cites: the serving layer maps an answer’s citations back to pages through this same function.

Parameters:

context (Sequence[Document])

Return type:

list[list[Document]]

Modules

templates

The PromptTemplate: retrieved documents plus a question to messages.