Team Ai
Apppublic

Goodguygregory93/ai-agents-certification-code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
retriever.cpython-313.pyc47 linesDownload Raw Back to __pycache__
1�

2��h<��L�SSKJr SSKrSSKJr SSKJr SSKr"SS5rg)�)�DocumentN)�FunctionTool)�
BM25Retrieverc�f�\rSrSrSSjrS\\S\\4SjrSS\\	4Sjjr3S\S\4SjrS	rg4)�	Retriever�c���XlURU5Ul[R"URS9Ul[R"UR5Ulg)aq5Ingests the similar questions for the GAIA agent to leverage and supports 6the exporting of the FunctionalTool for an AgentWorkFlow to leverage7 8This class handles the detailed logic. of connecting the 9similar questions and answers for the agent to retrieve10 11Details:12    leverages the BM25Retriever due to it's ability to search without pre-embedding Documents13    14)�nodesN)	�confirm_load�load_similar_questions�
question_datar�
from_defaults�bm25_retrieverr�get_similar_question�similar_question_tool)�selfrs  �G/Users/gregwitt/Github/clones/ai-agents-certification-code/retriever.py�__init__�Retriever.__init__	sO��)��!�8�8��F���+�9�9��@R�@R�S���%1�%?�%?��@Y�@Y�%Z��"��	questions�returnc��/nUH5n[R"U5nUSS:XdM$URU5 M7 U$)a15filters the incoming questions determining which ones are "level-1" and are potentially 16associated with the challenge.17 18Args:19    questions (list[dict]): question objects to filter20Returns:21    filtered_questions (list[dict]): level 1 questions for similarity22�Level�)�json�loads�append)rr�filtered_questions�question�
question_dicts     r�filter_questions�Retriever.filter_questionssE�� ��!�H� �J�J�x�0�M��W�%��*�"�)�)�-�8�	"�"�!rc��[SS5nUR5nURU5n[[	U55Vs/sH5n[SR
SXES3SXES3/5SXES	0S239PM7 nnU(a<UH6n[[RRSUR3-5 M8 U$s snf)a;24loads the GAIA dataset for similar questions and returns them as a list of Documents 25for the BM25Retriever26 27Args:28    confirm_load (bool): boolean value that controls the printed output of each appended question29 30Returns:31    docs (list[Document]): returns the Document object for each question for the Retriever32z./data/metadata.jsonl�r�33z34question: �Questionzfinal_answer: zFinal answer�question_number�task_id)�text�metadatau✅ Added Question: )�open�	readlinesr"�range�lenr�join�print�colorama�Fore�GREENr+)rr�questions_file�incoming_questionsr�i�docsr s        rr� Retriever.load_similar_questions1s����5�s�;��+�5�5�7��!�2�2�3E�F���S�!3�4�5�35�6�!�

��Y�Y� �!3�!6�z�!B� C�D�$�%7�%:�>�%J�$K�L� ��,�-?�-B�9�-M�N�
�6�	
�36�� ���h�m�m�)�)�.B�8�CT�CT�BU�,V�V�W�!����#37s�<C�queryc��URRU5nU(a.SRUSSVs/sHo3RPM sn5$gs snf)a=38queries the `bm25_retriever` to determine if the question given in the query39exists in the potential_questions40 41Args:42    query (str): string of the potential question that might be supplied for the GAIA Agent43Returns:44    response (str): a string response that will indicate if the user(s) exist in the guest_book.45z/n/nN�z-No matching results in the questions database)r�retriever0r*)rr:�
found_results�docs    rr�Retriever.get_similar_questionUsO���+�+�4�4�U�;�
���;�;�M�"�1�4E�F�4E�S���4E�F�G�G�B�� Gs�A)rrr
rN)F)
�__name__�46__module__�__qualname__�__firstlineno__r�list�str�dictr"rrr�__static_attributes__�rrrrsJ��[�&"�$�s�)�"��T�47�"�*"�D��N�"�HC�#�C�#�Crr)	�llama_index.core.schemarr2�llama_index.core.toolsr�llama_index.retrievers.bm25rrrrIrr�<module>rMs"��,��/�5��\C�\Cr