§
    šŠtj  ã                   ól   — d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ  G d„ de	e¦  «        ZdS )	é    )ÚAnyÚListÚOptional)ÚCallbackManagerForRetrieverRun)ÚDocument)ÚBaseRetriever)Ú	BaseModelÚFieldc                   ó  — e Zd ZU dZdZee         ed<   	  edd¬¦  «        Z	ee
         ed<    edd¬¦  «        Zee
         ed	<    edd
¬¦  «        Zee         ed<   dd„Zde
dee         fd„Zde
dedee         fd„ZdS )ÚNeedleRetrieveraY  
    NeedleRetriever retrieves relevant documents or context from a Needle collection
    based on a search query.

    Setup:
        Install the `needle-python` library and set your Needle API key.

        .. code-block:: bash

            pip install needle-python
            export NEEDLE_API_KEY="your-api-key"

    Key init args:
        - `needle_api_key` (Optional[str]): The API key for authenticating with Needle.
        - `collection_id` (str): The ID of the Needle collection to search in.
        - `client` (Optional[NeedleClient]): An optional instance of the NeedleClient.
        - `top_k` (Optional[int]): Maximum number of results to return.

    Usage:
        .. code-block:: python

            from langchain_community.retrievers.needle import NeedleRetriever

            retriever = NeedleRetriever(
                needle_api_key="your-api-key",
                collection_id="your-collection-id",
                top_k=10  # optional
            )

            results = retriever.retrieve("example query")
            for doc in results:
                print(doc.page_content)
    NÚclientzNeedle API Key)ÚdescriptionÚneedle_api_key.z,The ID of the Needle collection to search inÚcollection_idz*Maximum number of search results to return)Údefaultr   Útop_kÚreturnc                 óŽ   — 	 ddl m} n# t          $ r t          d¦  «        ‚w xY w| j        s || j        ¬¦  «        | _        dS dS )z•
        Initialize the NeedleClient with the provided API key.

        If a client instance is already provided, this method does nothing.
        r   )ÚNeedleClientz0Please install with `pip install needle-python`.)Úapi_keyN)Ú	needle.v1r   ÚImportErrorr   r   )Úselfr   s     úc/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/retrievers/needle.pyÚ_initialize_clientz"NeedleRetriever._initialize_client6   s   € ð	RØ.Ð.Ð.Ð.Ð.Ð.Ð.øÝð 	Rð 	Rð 	RÝÐPÑQÔQÐQð	Røøøð Œ{ð 	DØ&˜,¨tÔ/BÐCÑCÔCˆDŒKˆKˆKð	Dð 	Ds   ‚	 ‰#Úqueryc                 óÊ   — |                       ¦   «          | j        €t          d¦  «        ‚| j        j                             | j        || j        ¬¦  «        }d„ |D ¦   «         }|S )zý
        Search the Needle collection for relevant documents.

        Args:
            query (str): The search query used to find relevant documents.

        Returns:
            List[Document]: A list of documents matching the search query.
        Nz4NeedleClient is not initialized. Provide an API key.)r   Útextr   c                 ó8   — g | ]}t          |j        ¬ ¦  «        ‘ŒS ))Úpage_content)r   Úcontent)Ú.0Úresults     r   ú
<listcomp>z6NeedleRetriever._search_collection.<locals>.<listcomp>U   s%   € ÐLÐLÐL¸&• f¤nÐ5Ñ5Ô5ÐLÐLÐLó    )r   r   Ú
ValueErrorÚcollectionsÚsearchr   r   )r   r   ÚresultsÚdocss       r   Ú_search_collectionz"NeedleRetriever._search_collectionD   ss   € ð 	×ÒÑ!Ô!Ð!ØŒ;ÐÝÐSÑTÔTÐTà”+Ô)×0Ò0ØÔ,°5ÀÄ
ð 1ñ 
ô 
ˆð MÐLÀGÐLÑLÔLˆØˆr%   Úrun_managerc                ó,   — |                       |¦  «        S )zñ
        Retrieve relevant documents based on the query.

        Args:
            query (str): The query string used to search the collection.
        Returns:
            List[Document]: A list of documents relevant to the query.
        )r+   )r   r   r,   s      r   Ú_get_relevant_documentsz'NeedleRetriever._get_relevant_documentsX   s   € ð ×&Ò& uÑ-Ô-Ð-r%   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__annotations__r
   r   Ústrr   r   Úintr   r   r   r+   r   r.   © r%   r   r   r   	   s0  € € € € € € ð ð  ðD !€FˆH�SŒMÐ Ð Ñ Ø,Ø$) E¨$Ð<LÐ$MÑ$MÔ$M€N�H˜S”MÐMÐMÑMØ#( 5ØÐGð$ñ $ô $€M�8˜C”=ð ð ñ ð !˜5ØÐ"Nðñ ô €Eˆ8�CŒ=ð ð ñ ðDð Dð Dð Dð¨ð °°X´ð ð ð ð ð(.Øð.Ø*Hð.à	ˆhŒð.ð .ð .ð .ð .ð .r%   r   N)Útypingr   r   r   Úlangchain_core.callbacksr   Úlangchain_core.documentsr   Úlangchain_core.retrieversr   Úpydanticr	   r
   r   r6   r%   r   ú<module>r<      s±   ðØ &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à CÐ CÐ CÐ CÐ CÐ CØ -Ð -Ð -Ð -Ð -Ð -Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %ð\.ð \.ð \.ð \.ð \.�m Yñ \.ô \.ð \.ð \.ð \.r%   