
    BTh                     ^    d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
  G d de
      Zy)	    )abstractmethod)TypeN)Document)BaseRetriever)BaseStandardTestsc                       e Zd ZdZeedee   fd              Zede	fd       Z
eedefd              Zej                  defd       ZddZd	eddfd
Zd	eddfdZd	eddfdZy)RetrieversIntegrationTestsz6
    Base class for retrievers integration tests.
    returnc                      y)z8
        A BaseRetriever subclass to be tested.
        N selfs    ~/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/langchain_tests/integration_tests/retrievers.pyretriever_constructorz0RetrieversIntegrationTests.retriever_constructor        	    c                     i S )zZ
        Returns a dictionary of parameters to pass to the retriever constructor.
        r   r   s    r   retriever_constructor_paramsz7RetrieversIntegrationTests.retriever_constructor_params   s	    
 	r   c                      y)zV
        Returns a str representing the "query" of an example retriever call.
        Nr   r   s    r   retriever_query_examplez2RetrieversIntegrationTests.retriever_query_example   r   r   c                 :     | j                   di | j                  S )z
        :private:
        r   )r   r   r   s    r   	retrieverz$RetrieversIntegrationTests.retriever'   s     
 *t))ND,M,MNNr   Nc                    | j                   j                         D ci c]  \  }}|dk7  s|| }}}i |ddi} | j                  di |}|j                  | j                        }t        |      dk(  sJ t        d |D              sJ i |ddi} | j                  di |}|j                  | j                        }	t        |	      dk(  sJ t        d |	D              sJ yc c}}w )aB  
        Test that the retriever constructor accepts a k parameter, representing
        the number of documents to return.

        .. dropdown:: Troubleshooting

            If this test fails, either the retriever constructor does not accept a k
            parameter, or the retriever does not return the correct number of documents
            (`k`) when it is set.

            For example, a retriever like

            .. code-block:: python

                    MyRetriever(k=3).invoke("query")

            should return 3 documents when invoked with a query.
        k   c              3   <   K   | ]  }t        |t                y wN
isinstancer   .0docs     r   	<genexpr>zFRetrieversIntegrationTests.test_k_constructor_param.<locals>.<genexpr>H        A:c8,A      c              3   <   K   | ]  }t        |t                y wr   r   r    s     r   r#   zFRetrieversIntegrationTests.test_k_constructor_param.<locals>.<genexpr>N   r$   r%   Nr   )r   itemsr   invoker   lenall)
r   r   vparamsparams_3retriever_3result_3params_1retriever_1result_1s
             r   test_k_constructor_paramz3RetrieversIntegrationTests.test_k_constructor_param.   s   ( ">>DDF
Q!s(AqD
 
 &f%c1%0d00<8<%%d&B&BC8}!!!AAAAA%f%c1%0d00<8<%%d&B&BC8}!!!AAAAA
s
   C'C'r   c                    |j                  | j                  d      }t        |      dk(  sJ t        d |D              sJ |j                  | j                  d      }t        |      dk(  sJ t        d |D              sJ y)a5  
        Test that the invoke method accepts a k parameter, representing the number of
        documents to return.

        .. dropdown:: Troubleshooting

            If this test fails, the retriever's invoke method does not accept a k
            parameter, or the retriever does not return the correct number of documents
            (`k`) when it is set.

            For example, a retriever like

            .. code-block:: python

                MyRetriever().invoke("query", k=3)

            should return 3 documents when invoked with a query.
        r&   )r   c              3   <   K   | ]  }t        |t                y wr   r   r    s     r   r#   zFRetrieversIntegrationTests.test_invoke_with_k_kwarg.<locals>.<genexpr>e   r$   r%   r   c              3   <   K   | ]  }t        |t                y wr   r   r    s     r   r#   zFRetrieversIntegrationTests.test_invoke_with_k_kwarg.<locals>.<genexpr>i   r$   r%   N)r)   r   r*   r+   )r   r   r3   r0   s       r   test_invoke_with_k_kwargz3RetrieversIntegrationTests.test_invoke_with_k_kwargP   s    & ##D$@$@A#F8}!!!AAAAA##D$@$@A#F8}!!!AAAAAr   c                     |j                  | j                        }t        |t              sJ t	        d |D              sJ y)a  
        If invoked with the example params, the retriever should return a list of
        Documents.

        .. dropdown:: Troubleshooting

            If this test fails, the retriever's invoke method does not return a list of
            `langchain_core.document.Document` objects. Please confirm that your
            `_get_relevant_documents` method returns a list of `Document` objects.
        c              3   <   K   | ]  }t        |t                y wr   r   r    s     r   r#   zKRetrieversIntegrationTests.test_invoke_returns_documents.<locals>.<genexpr>y        ?:c8,?r%   N)r)   r   r   listr+   r   r   results      r   test_invoke_returns_documentsz8RetrieversIntegrationTests.test_invoke_returns_documentsk   s>     !!$">">?&$'''?????r   c                    K   |j                  | j                         d{   }t        |t              sJ t	        d |D              sJ y7 +w)z
        If ainvoked with the example params, the retriever should return a list of
        Documents.

        See :meth:`test_invoke_returns_documents` for more information on
        troubleshooting.
        Nc              3   <   K   | ]  }t        |t                y wr   r   r    s     r   r#   zLRetrieversIntegrationTests.test_ainvoke_returns_documents.<locals>.<genexpr>   r;   r%   )ainvoker   r   r<   r+   r=   s      r   test_ainvoke_returns_documentsz9RetrieversIntegrationTests.test_ainvoke_returns_documents{   sK      !(()E)EFF&$'''????? Gs   AA,A)r
   N)__name__
__module____qualname____doc__propertyr   r   r   r   dictr   strr   pytestfixturer   r4   r8   r?   rC   r   r   r   r	   r	      s     tM':    d       ^^O= O O BDB- BD B6@} @ @ @m @PT @r   r	   )abcr   typingr   rK   langchain_core.documentsr   langchain_core.retrieversr   langchain_tests.baser   r	   r   r   r   <module>rR      s(       - 3 2{@!2 {@r   