+
    mҘj                    j    ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
HtHt R R ltR	 R
 ltR# )    )annotations)get_settings)get_connection)embed_query)synthesize_answer)SearchResponseSourceChunkc               $    V ^8  d   QhRRRRRR/# )   query_embeddingzlist[float]kintreturnzlist[SourceChunk] )formats   "
app/rag.py__annotate__r   
   s"      [ S =N     c                   R p\        4       ;_uu_ 4       pVP                  4       ;_uu_ 4       pVP                  W W34       VP                  4       pRRR4       RRR4       X Uu. uF?  p\	        VR,          VR,          \        VR,          4      VR,          VR,          R7      NKA  	  up#   + '       g   i     Ld; i  + '       g   i     Lo; iu upi )z
        SELECT
            id,
            text_chunk,
            source_file,
            chunk_index,
            1 - (embedding <=> %s::vector) AS similarity
        FROM document_chunks
        ORDER BY embedding <=> %s::vector
        LIMIT %s
    Nid
text_chunk
similaritychunk_indexsource_file)r   r   r   r   r   )r   cursorexecutefetchallr	   float)r   r   sqlconncurrowsrows   &&     r   retrieve_chunksr$   
   s    
C 
		T[[]]cKKBC<<>D  
 	 C 	4y<(S./M*M*	
 	 	 ] 
		s)   C$B.	C&AC.B>9CC	c                    V ^8  d   QhRRRR/# )r   questionstrr   r   r   )r   s   "r   r   r   &   s     
: 
:c 
:n 
:r   c                    \        4       p\        V 4      p\        W!P                  4      pV'       g   \	        R . R7      # \        Y Uu. uF  qDP                  NK  	  up4      p\	        WSR7      # u upi )z-This is not covered in the provided document.)answersources)r   r   r$   retrieval_kr   r   r   )r&   settings	embeddingr*   sr)   s   &     r   answer_questionr/   &   si    ~HH%Ii)=)=>GB
 	
 x)H1,,)HIF99 *Is   	A0
N)
__future__r   
app.configr   app.dbr   app.embeddingsr   app.llmr   
app.modelsr   r	   r$   r/   r   r   r   <module>r6      s!    " # ! & % 28
:r   