langchain_community.embeddings.xinference.XinferenceEmbeddings

class langchain_community.embeddings.xinference.XinferenceEmbeddings(server_url: Optional[str] = None, model_uid: Optional[str] = None)[source]

运行 Xinference 嵌入模型。

要使用,您应该已安装 xinference 库:

pip install xinference

如果您只是使用 Xinference 提供的服务,可以使用 xinference_client 包:

pip install xinference_client

查看:https://github.com/xorbitsai/inference 要运行,您需要在一个服务器上启动 Xinference 监督员,并在其他服务器上启动 Xinference 工作者。

示例:

要启动 Xinference 的本地实例,请运行

$ xinference

您还可以在分布式集群中部署 Xinference。以下是步骤:

启动监督员:

$ xinference-supervisor

如果您只是使用 Xinference 提供的服务,可以使用 xinference_client 包:

pip install xinference_client

启动工作者:

$ xinference-worker

然后,使用命令行界面(CLI)启动模型。

示例:

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

它将返回一个模型 UID。然后您可以使用 LangChain 中的 Xinference 嵌入。

示例:

from langchain_community.embeddings import XinferenceEmbeddings

xinference = XinferenceEmbeddings(
    server_url="http://0.0.0.0:9997",
    model_uid = {model_uid} # 用从启动模型返回的模型 UID 替换 model_uid
)

Attributes

client

server_url

xinference服务器的URL

model_uid

启动模型的UID

Methods

__init__([server_url, model_uid])

aembed_documents(texts)

Asynchronous 嵌入搜索文档。

aembed_query(text)

Asynchronous 嵌入查询文本。

embed_documents(texts)

使用Xinference嵌入文档列表。 参数: texts:要嵌入的文本列表。 返回: 每个文本的嵌入列表。

embed_query(text)

使用Xinference嵌入文档查询。 参数: text:要嵌入的文本。 返回: 文本的嵌入。

Parameters
  • server_url (Optional[str]) –

  • model_uid (Optional[str]) –

__init__(server_url: Optional[str] = None, model_uid: Optional[str] = None)[source]
Parameters
  • server_url (Optional[str]) –

  • model_uid (Optional[str]) –

async aembed_documents(texts: List[str]) List[List[float]]

Asynchronous 嵌入搜索文档。

Parameters

texts (List[str]) –

Return type

List[List[float]]

async aembed_query(text: str) List[float]

Asynchronous 嵌入查询文本。

Parameters

text (str) –

Return type

List[float]

embed_documents(texts: List[str]) List[List[float]][source]

使用Xinference嵌入文档列表。 参数:

texts:要嵌入的文本列表。

返回:

每个文本的嵌入列表。

Parameters

texts (List[str]) –

Return type

List[List[float]]

embed_query(text: str) List[float][source]

使用Xinference嵌入文档查询。 参数:

text:要嵌入的文本。

返回:

文本的嵌入。

Parameters

text (str) –

Return type

List[float]

Examples using XinferenceEmbeddings