
    dh                     >    S r SSKJrJrJr  SSKJr   " S S\5      rg)z+Wrapper around Xinference embedding models.    )AnyListOptional)
Embeddingsc                      ^  \ rS rSr% Sr\\S'   \\   \S'    \\   \S'     SS\\   S\\   4U 4S jjjr	S\
\   S\
\
\      4S	 jrS
\S\
\   4S jrSrU =r$ )XinferenceEmbeddings   a  Xinference embedding models.

To use, you should have the xinference library installed:

.. code-block:: bash

    pip install xinference

If you're simply using the services provided by Xinference, you can utilize the xinference_client package:

.. code-block:: bash

    pip install xinference_client

Check out: https://github.com/xorbitsai/inference
To run, you need to start a Xinference supervisor on one server and Xinference workers on the other servers.

Example:
    To start a local instance of Xinference, run

    .. code-block:: bash

       $ xinference

    You can also deploy Xinference in a distributed cluster. Here are the steps:

    Starting the supervisor:

    .. code-block:: bash

       $ xinference-supervisor

    If you're simply using the services provided by Xinference, you can utilize the xinference_client package:

    .. code-block:: bash

        pip install xinference_client

    Starting the worker:

    .. code-block:: bash

       $ xinference-worker

Then, launch a model using command line interface (CLI).

Example:

.. code-block:: bash

   $ xinference launch -n orca -s 3 -q q4_0

It will return a model UID. Then you can use Xinference Embedding with LangChain.

Example:

.. code-block:: python

    from langchain_community.embeddings import XinferenceEmbeddings

    xinference = XinferenceEmbeddings(
        server_url="http://0.0.0.0:9997",
        model_uid = {model_uid} # replace model_uid with the model UID return from launching the model
    )

client
server_url	model_uidc                   >  SSK Jn  [        TU ]  5         Uc  [        S5      eUc  [        S5      eXl        X l        U" U5      U l	        g ! [         a(     SSKJn   NW! [         a  n[        S5      UeS nAff = ff = f)Nr   )RESTfulClientzCould not import RESTfulClient from xinference. Please install it with `pip install xinference` or `pip install xinference_client`.zPlease provide server URLzPlease provide the model UID)
xinference.clientr   ImportErrorxinference_clientsuper__init__
ValueErrorr   r   r
   )selfr   r   r   e	__class__s        a/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/xinference.pyr   XinferenceEmbeddings.__init__R   s    		7 	899;<<$"#J/+  	; !Y 	s)   A 
A?A  
A;*A66A;;A?textsreturnc           	         U R                   R                  U R                  5      nU Vs/ sH  o2R                  U5      S   S   S   PM     nnU Vs/ sH  n[	        [        [        U5      5      PM     sn$ s  snf s  snf )zEmbed a list of documents using Xinference.
Args:
    texts: The list of texts to embed.
Returns:
    List of embeddings, one for each text.
datar   	embeddingr
   	get_modelr   create_embeddinglistmapfloat)r   r   modeltext
embeddingsr   s         r   embed_documents$XinferenceEmbeddings.embed_documentsn   s     %%dnn5 NS
MRT""4(03K@U 	 
 .88ZS]#Z88
 9s   "A7"A<r&   c                     U R                   R                  U R                  5      nUR                  U5      nUS   S   S   n[	        [        [        U5      5      $ )zvEmbed a query of documents using Xinference.
Args:
    text: The text to embed.
Returns:
    Embeddings for the text.
r   r   r   r   )r   r&   r%   embedding_resr   s        r   embed_query XinferenceEmbeddings.embed_query}   sR     %%dnn5..t4!&)!,[9	Cy)**    )r
   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   __annotations__r   strr   r   r$   r(   r,   __static_attributes____classcell__)r   s   @r   r   r      s    AF K&}# LP0"3-0;CC=0 089T#Y 94U3D 9+ +U + +r.   r   N)r3   typingr   r   r   langchain_core.embeddingsr   r    r.   r   <module>r;      s    1 & & 0C+: C+r.   