
    dh                        S SK Jr  S SKJrJrJr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  S SKJrJr  \" S	S
SS9 " S S\5      5       rg)    )annotations)AnyDictListOptionalcast)uuid4)
deprecated)CallbackManagerForRetrieverRun)Document)BaseRetriever)
ConfigDictmodel_validatorz0.3.18z1.0z&langchain_weaviate.WeaviateVectorStore)sinceremovalalternative_importc                      \ rS rSr% SrSrS\S'    S\S'    S\S'    S	rS
\S'    SrS\S'    S\S'    Sr	S\S'    \
" SS9\    SS j5       5       r\" SS9rSS jrSSSS.           SS jjrSrg) WeaviateHybridSearchRetriever   zo`Weaviate hybrid search` retriever.

See the documentation:
  https://weaviate.io/blog/hybrid-search-explained
Nr   clientstr
index_nametext_keyg      ?floatalpha   intk	List[str]
attributesTboolcreate_schema_if_missingbefore)modec                    SS K n[        US   UR                  5      (       d  US   n[	        S[        U5       35      eUR                  S5      c  / US'   [        [        US   5      R                  US   5        UR                  SS5      (       aU  US	   US   S
/S./SS.nUS   R                  R                  US	   5      (       d  US   R                  R                  U5        U$ ! [         a    [        S5      ef = f)Nr   z_Could not import weaviate python package. Please install it with `pip install weaviate-client`.r   z5client should be an instance of weaviate.Client, got r    r   r"   Tr   text)namedataTypeztext2vec-openai)class
properties
vectorizer)weaviateImportError
isinstanceClient
ValueErrortypegetr   r   appendschemaexistscreate_class)clsvaluesr,   r   	class_objs        m/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/retrievers/weaviate_hybrid_search.pyvalidate_client-WeaviateHybridSearchRetriever.validate_client(   s   	 &*HOO<<H%FGV~V  ::l#+#%F< T6,'(//z0BC::0$77-(.z(:QR/I (#**11&2FGGx ''44Y?3  	H 	s   C* *D )arbitrary_types_allowedc                   SSK Jn  U R                  R                   n/ n[	        U5       H  u  pgUR
                  =(       d    0 nU R                  UR                  0UEn	SU;   a	  US   U   n
OU" [        5       5      n
UR                  XR                  U
5        UR                  U
5        M     SSS5        U$ ! , (       d  f       W$ = f)zUpload documents to Weaviate.r   )get_valid_uuiduuidsN)weaviate.utilr?   r   batch	enumeratemetadatar   page_contentr	   add_data_objectr   r3   )selfdocskwargsr?   rB   idsidocrD   data_properties_ids              r:   add_documents+WeaviateHybridSearchRetriever.add_documentsP   s    0[[%C#D/<<-2#'==#2B2B"Oh"O f$ /!,C(1C%%oL

3 *  
  
s   BB99
CF)where_filterscorehybrid_search_kwargsc               D   U R                   R                  R                  U R                  U R                  5      nU(       a  UR                  U5      nU(       a  UR                  SS/5      nUc  0 nUR                  " U4SU R                  0UD6R                  U R                  5      R                  5       nSU;   a  [        SUS    35      e/ nUS   S   U R                      H6  n	U	R                  U R                  5      n
UR                  [!        XS95        M8     U$ )	al  Look up similar documents in Weaviate.

query: The query to search for relevant documents
 of using weviate hybrid search.

where_filter: A filter to apply to the query.
    https://weaviate.io/developers/weaviate/guides/querying/#filtering

score: Whether to include the score, and score explanation
    in the returned Documents meta_data.

hybrid_search_kwargs: Used to pass additional arguments
 to the .with_hybrid() method.
    The primary uses cases for this are:
    1)  Search specific properties only -
        specify which properties to be used during hybrid search portion.
        Note: this is not the same as the (self.attributes) to be returned.
        Example - hybrid_search_kwargs={"properties": ["question", "answer"]}
    https://weaviate.io/developers/weaviate/search/hybrid#selected-properties-only

    2) Weight boosted searched properties -
        Boost the weight of certain properties during the hybrid search portion.
        Example - hybrid_search_kwargs={"properties": ["question^2", "answer"]}
    https://weaviate.io/developers/weaviate/search/hybrid#weight-boost-searched-properties

    3) Search with a custom vector - Define a different vector
        to be used during the hybrid search portion.
        Example - hybrid_search_kwargs={"vector": [0.1, 0.2, 0.3, ...]}
    https://weaviate.io/developers/weaviate/search/hybrid#with-a-custom-vector

    4) Use Fusion ranking method
        Example - from weaviate.gql.get import HybridFusion
        hybrid_search_kwargs={"fusion": fusion_type=HybridFusion.RELATIVE_SCORE}
    https://weaviate.io/developers/weaviate/search/hybrid#fusion-ranking-method
rR   explainScorer   errorszError during query: dataGet)rE   rD   )r   queryr2   r   r    
with_wherewith_additionalwith_hybridr   
with_limitr   dor0   popr   r3   r   )rG   rY   run_managerrQ   rR   rS   	query_objresultrH   resr&   s              r:   _get_relevant_documents5WeaviateHybridSearchRetriever._get_relevant_documentse   s   X KK%%))$//4??K	!,,\:I!117N2KLI'#%  !!%RtzzR=QRZRT 	
 v3F84D3EFGG&>%(9C774==)DKKdAB :      )r8   zDict[str, Any]returnr   )rH   List[Document]rI   r   rh   r   )rY   r   r`   r   rQ   Optional[Dict[str, object]]rR   r!   rS   rj   rh   ri   )__name__
__module____qualname____firstlineno____doc__r   __annotations__r   r   r"   r   classmethodr;   r   model_configrO   rd   __static_attributes__rg   rf   r:   r   r      s     FC;O'M*E5:AsJ*2%)d);(# 
  $B  $L
4 59<@CC 4	C
 2C C :C 
C Crf   r   N)
__future__r   typingr   r   r   r   r   uuidr	   langchain_core._apir
   langchain_core.callbacksr   langchain_core.documentsr   langchain_core.retrieversr   pydanticr   r   r   rg   rf   r:   <module>r|      sL    " 2 2  * C - 3 0 
?
VM V
Vrf   