Alterna · learning material

18.3 What did the model really see

Let's get the question and the selected pieces in a limited context, check the actual current numbers, not just the beautifully drafted text.

What this material covers

Content and key concepts

On the previous page: Comparison and selection of fragments.
Let's get the question and the selected pieces in a limited context, check the actual current numbers, not just the beautifully drafted text.
The search selects fragments; the beilder adds them to the question. The memory, history and tool results have different sources. The right of action checks the program, and the cycle has to have a reason for stopping.
Для изменения рисунка включитеJavaScript; расчёт и теория доступны далее.
Retriever offers experience, generator shapes response
Retrieval-augmented energy connects parametric model to external non-paramétric memory. Model pipeline: convert query, get candidates, rerank, choose fragments to cotext budget, generate answer, and save numbers. F12. The found text is not recorded in the webs and does not automatically become reliable.
Let it passage
i
is score
s_i
and token cost
c_i
The educational policy goes down score and adds passage if it's placed. It's deterministic greedy rule, not the optimal knapsack solution:
C
=
{
i
1
,
…
}
:
∑
i
∈
C
c
i
≤
B
.
C=\{i_1,\ldots\}:\quad \sum_{i\in C}c_i\le B.
C
=
{
i
1
​
,
…
}
:
i
∈
C
∑
​
c
i
​
≤
B
.
That's what the model shows.
The Context billder shows the dudgets selected by spans and the mapping of the situation \source/version. Prompt is required to separate the retrieved data from system instruments: the document is considered to be untrustworthy, not a team. The answer without evidence can only be resolved by an explicit policy, for example an honest "source is not found".
Scope of applicability.
RAG does not guarantee the truth: document may not be correct; retriever – miss the right; general – distort the content. Prompt inject within a document requires sandbox/privilege reorganization. The location next to the proposal does not prove that the source actually supports the claim; a separate groupness test is needed.
passages_18c=[(.9,3,'d1'),(.8,2,'d2'),(.7,4,'d3')]; budget_18c=5; selected_18c=[]
for score_18c,cost_18c,source_18c in sorted(passages_18c,key=lambda row_18c:-row_18c[0]):
if cost_18c<=budget_18c:
selected_18c.append(source_18c); budget_18c-=cost_18c
assert selected_18c==['d1','d2'] and budget_18c==0
The code repeats the operations just taken care of.
Completely checked Python-example Chapter
Available with a separate file; the short piece shown does not replace its implementation.
Runtime limits the actual model tokens and clearly shows truncation.
The external program can do the job. How does this question continue?
Python examples of Chapter 18
Academic base

Textbook contents map