fastrag.query.prompts.templates#
The PromptTemplate: retrieved documents plus a question to messages.
Functions
|
Group retrieved chunks into the sources a prompt cites as |
|
The link to the page |
Classes
|
Renders retrieved documents and a question into messages for a |
- class fastrag.query.prompts.templates.PromptTemplate(template, system=None)[source]#
Bases:
objectRenders retrieved documents and a question into messages for a
ChatModel.- Parameters:
- render(*, context, question)[source]#
Render
contextandquestioninto the messages to send.contextis numbered by source, asgroup_sources()groups it —[n]is every chunk of the page ingroups[n - 1]— so a “cite as [n]” system instruction cites each page by one number.
- fastrag.query.prompts.templates.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.