ó
    ³ü¡jø  ã                  óú   • S r SSKJr  SSKrSSKJr  SSKJrJr  SSK	J
r
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  \(       a  SSKJr  SrSr " S S\
5      r\" SS9SS j5       rSS jrSS jrSS jrg)uö  Candidate selection agent for the playground's retrieval path.

Given a question and a wide, source-diverse pool of retrieved chunks, an agent
decides which chunks contain the information the question needs. Rank order
alone cannot do this: on the evaluation corpus, the answering chunk sat as
deep as fused rank 63 while near-duplicates and on-vocabulary neighbors filled
the top slots. The agent reads the pool and selects; it does not answer.

Candidates are sent in full â€” no truncation. The 90-candidate pool measured
about 32k tokens on the evaluation corpus, well inside the model context, and
any cut risks hiding the one row of a large table that answers the question.
Labels are local indices that carry no information about any expected answer.
é    )ÚannotationsN)Ú	lru_cache)ÚTYPE_CHECKINGÚList)Ú	BaseModelÚField)ÚAgent)ÚModelSettings)Úusage_metadata_from)Úanthropic_model)Úrun_metadataÚtracer)ÚRetrievedChunkzclaude-haiku-4-5a0  You are a retrieval triage step for financial-document question answering.
You are given a QUESTION and a numbered list of CANDIDATE context chunks
retrieved from one document. Your ONLY job is to decide which candidates
contain the specific information needed to answer the question.

Do NOT answer the question. Do NOT compute or state any figure. Select
candidates.

Rules:
- Return the labels (e.g. C0, C7) of every candidate that contains information
  needed to answer the question, ordered MOST relevant first.
- A candidate is relevant if it holds the exact line, row, or statement the
  question asks about (matching the entity, period, metric, and units). Prefer
  the candidate that states the asked-for value most directly and specifically.
- If several near-duplicate candidates exist, include the one(s) that most
  precisely match the question's entity and period; you may include a few close
  alternates but keep the best first.
- Only return labels that appear in the candidate list. Never invent a label.
- If nothing is relevant, return an empty list.
c                  ó.   • \ rS rSr% \" \SS9rS\S'   Srg)Ú	Selectioné9   zKCandidate labels (e.g. 'C3') that answer the question, most relevant first.)Údefault_factoryÚdescriptionz	List[str]Úlabels© N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   Úlistr   Ú__annotations__Ú__static_attributes__r   ó    Ú8/home/mande/repo/quber/src/quber/playground/selection.pyr   r   9   s   ‡ ÙØØañ€FˆIö r   r   é   )Úmaxsizec            	     óR   • [        [        [        5      [        [        [        SS9S9$ )Ng        )Útemperature)Úoutput_typeÚsystem_promptÚmodel_settings)r	   r   ÚMODELr   ÚSYSTEM_PROMPTr
   r   r   r   Ú_agentr)   @   s'   € ô ÜœÓÜÜ#Ü$°Ñ5ñ	ð r   c                óô   • [        U5       VVs/ s H4  u  p#SU SUR                   SUR                  S-    SUR                   3PM6     nnnSU  S[	        U5       S3S	R                  U5      -   S
-   $ s  snnf )Nz[label=Cz | type z | page r    z]
z
QUESTION: z

CANDIDATES (z):

z

zv

Return the labels of the candidates that contain the information needed to answer the question, most relevant first.)Ú	enumerateÚ
chunk_typeÚpageÚcontentÚlenÚjoin)ÚquestionÚcandsÚiÚcÚblockss        r   Ú_promptr6   N   s—   € ä[dÐejÔ[kôÚ[kÑSWÐSTˆ(�1�#�X˜aŸl™l˜^¨8°A·F±F¸Q±J°<¸sÀ1Ç9Á9À+ÓNÑ[kð ñ ð �X�Jð Ü˜5“z�l &ð	*Ø,2¯K©K¸Ó,?ñ	@ðC7ñ	7ðùós   �;A4c              ƒ  ó   #   • [        X5      nS[        S.SUS./U Vs/ s H  o3R                  PM     snS.n[        5       R	                  SU[
        [        5       S9 ISh  v•N n[        5       R                  U5      I Sh  v•N nSUR                  R                  5       S./[        UR                  5      S	.Ul        SSS5      ISh  v•N   / nWR                  R                   Hx  nUR                  5       R!                  S
5      nUR#                  5       (       d  M9  [%        U5      n	SU	s=::  a  ['        U5      :  d  M\  O  M`  X—;  d  Mg  UR)                  U	5        Mz     U$ s  snf  GN
 Në N¤! , ISh  v•N  (       d  f       N¹= f7f)zÂIndices into `cands` the agent judged relevant, most relevant first.

Labels outside the candidate range and duplicates are discarded, so the
result is always a valid, de-duplicated index list.
Úsystem)Úroler.   Úuser)ÚmessagesÚ	chunk_idsÚselect_chunks)ÚmodelÚextra_metadataNÚ	assistant)r;   Úusage_metadataÚCcr   )r6   r(   Úchunk_idr   Úllm_runr'   r   r)   ÚrunÚoutputÚmodel_dump_jsonr   ÚusageÚoutputsr   ÚstripÚlstripÚisdigitÚintr/   Úappend)
r1   r2   Úpromptr4   ÚinputsrE   ÚresultÚidxsÚlabÚjs
             r   ÚselectrU   Z   s<  é € ô �XÓ%€Fð ¬-Ñ8Ø¨Ñ/ð
ñ +0Ó0ª% Q—j”j©%Ñ0ñ€Fô ‹x×Ñ °¼uÔUaÓUcÐ×dÑdÐhkÜ“x—|‘| FÓ+×+ˆà"-¸&¿-¹-×:WÑ:WÓ:YÑZÐ[Ü1°&·,±,Ó?ñ
ˆŒ÷ e×dð €DØ�}‰}×#Ô#ˆØ�i‰i‹k× Ñ  Ó&ˆØ�;‰;�=‹=Ü�C“ˆAØ�AÕ"œ˜E›
×"Ñ" q¥}Ø—‘˜A–ñ $ð €Kùò 1âdÙ+÷ e×d×dÐdüsv   ‚FŸE(´/FÁ#E-Á$FÁ'E4ÂE0Â=E4ÃFÃE2ÃAFÄ#FÅFÅFÅ0E4Å2FÅ4FÅ:E=Å;FÆFc                ó@   • [         R                  " [        X5      5      $ )N)ÚasynciorE   rU   )r1   r2   s     r   Úselect_syncrX   x   s   € Ü�;Š;”v˜hÓ.Ó/Ð/r   )ÚreturnzAgent[None, Selection])r1   Ústrr2   úList['RetrievedChunk']rY   rZ   )r1   rZ   r2   r[   rY   z	List[int]) Ú__doc__Ú
__future__r   rW   Ú	functoolsr   Útypingr   r   Úpydanticr   r   Úpydantic_air	   Úpydantic_ai.settingsr
   Úquber.agents.langsmith_tracerr   Úquber.playground.agentr   Úquber.playground.tracingr   r   Úquber.playground.retrievalr   r'   r(   r   r)   r6   rU   rX   r   r   r   Ú<module>rg      sp   ðñõ #ã Ý ß &ç %Ý Ý .å =Ý 2ß 9æÝ9à€ð€ô.�	ô ñ �1Ñó
ó ð
ô	ôõ<0r   