
    dhO                         S r SSKrSSK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   " S
 S\5      rS\S\S\4S jrg)zMilvus Retriever    N)AnyDictListOptional)CallbackManagerForRetrieverRun)Document)
Embeddings)BaseRetriever)model_validator)Milvusc            	           \ rS rSr% Sr\\S'   Sr\\S'   Sr	\
\\\4      \S'   Sr\
\\\4      \S'   S	r\\S
'   Sr\
\   \S'   \\S'   \\S'   \" SS9\S\S\4S j5       5       r SS\\   S\
\\      SS4S jjrS\S\S\S\\   4S jrSrg)MilvusRetriever   a  Milvus API retriever.

See detailed instructions here: https://python.langchain.com/docs/integrations/retrievers/milvus_hybrid_search/

Setup:
    Install ``langchain-milvus`` and other dependencies:

    .. code-block:: bash

        pip install -U pymilvus[model] langchain-milvus

Key init args:
    collection: Milvus Collection

Instantiate:
    .. code-block:: python

        retriever = MilvusCollectionHybridSearchRetriever(collection=collection)

Usage:
    .. code-block:: python

        query = "What are the story about ventures?"

        retriever.invoke(query)

    .. code-block:: none

        [Document(page_content="In 'The Lost Expedition' by Caspian Grey...", metadata={'doc_id': '449281835035545843'}),
        Document(page_content="In 'The Phantom Pilgrim' by Rowan Welles...", metadata={'doc_id': '449281835035545845'}),
        Document(page_content="In 'The Dreamwalker's Journey' by Lyra Snow..", metadata={'doc_id': '449281835035545846'})]

Use within a chain:
    .. code-block:: python

        from langchain_core.output_parsers import StrOutputParser
        from langchain_core.prompts import ChatPromptTemplate
        from langchain_core.runnables import RunnablePassthrough
        from langchain_openai import ChatOpenAI

        prompt = ChatPromptTemplate.from_template(
            """Answer the question based only on the context provided.

        Context: {context}

        Question: {question}"""
        )

        llm = ChatOpenAI(model="gpt-3.5-turbo-0125")

        def format_docs(docs):
            return "\n\n".join(doc.page_content for doc in docs)

        chain = (
            {"context": retriever | format_docs, "question": RunnablePassthrough()}
            | prompt
            | llm
            | StrOutputParser()
        )

        chain.invoke("What novels has Lila written and what are their contents?")

    .. code-block:: none

         "Lila Rose has written 'The Memory Thief,' which follows a charismatic thief..."

embedding_functionLangChainCollectioncollection_nameNcollection_propertiesconnection_argsSessionconsistency_levelsearch_paramsstore	retrieverbefore)modevaluesreturnc                 |    [        US   US   US   US   US   5      US'   US   R                  SUS   0S	9US
'   U$ )z&Create the Milvus store and retriever.r   r   r   r   r   r   paramr   )search_kwargsr   )r   as_retriever)clsr   s     ]/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/retrievers/milvus.pycreate_retriever MilvusRetriever.create_retriever`   ss     !'($%*+$%&'
w %Wo::"F?$;< ; 
{     texts	metadatasc                 :    U R                   R                  X5        g)zAdd text to the Milvus store

Args:
    texts (List[str]): The text
    metadatas (List[dict]): Metadata dicts, must line up with existing store
N)r   	add_texts)selfr'   r(   s      r#   r*   MilvusRetriever.add_textsp   s     	

U.r&   queryrun_managerkwargsc                \    U R                   R                  " U4SUR                  5       0UD6$ )Nr.   )r   invoke	get_child)r+   r-   r.   r/   s       r#   _get_relevant_documents'MilvusRetriever._get_relevant_documents{   s7     ~~$$
*446
:@
 	
r&    )N)__name__
__module____qualname____firstlineno____doc__r	   __annotations__r   strr   r   r   r   r   r   r   dictr   r
   r   classmethodr$   r   r*   r   r   r3   __static_attributes__r5   r&   r#   r   r      s    BH #"0OS06:8DcN3:04OXd38n-4&s&$(M8D>(M(#d s   $ CG	/#Y	/+3DJ+?	/		/	
	
 4		

 	
 
h	
r&   r   argsr/   r   c                  N    [         R                  " S[        5        [        U 0 UD6$ )zDeprecated MilvusRetreiver. Please use MilvusRetriever ('i' before 'e') instead.

Args:
    *args:
    **kwargs:

Returns:
    MilvusRetriever
zfMilvusRetreiver will be deprecated in the future. Please use MilvusRetriever ('i' before 'e') instead.)warningswarnDeprecationWarningr   )r@   r/   s     r#   MilvusRetreiverrE      s*     MM	?
 D+F++r&   )r:   rB   typingr   r   r   r   langchain_core.callbacksr   langchain_core.documentsr   langchain_core.embeddingsr	   langchain_core.retrieversr
   pydanticr   'langchain_community.vectorstores.milvusr   r   rE   r5   r&   r#   <module>rM      sL      , , C - 0 3 $ :
s
m s
l,3 ,# ,/ ,r&   