langchain/docs/extras/integrations/text_embedding
Jiayi Ni 1efb9bae5f
FEAT: Integrate Xinference LLMs and Embeddings (#8171)
- [Xorbits
Inference(Xinference)](https://github.com/xorbitsai/inference) is a
powerful and versatile library designed to serve language, speech
recognition, and multimodal models. Xinference supports a variety of
GGML-compatible models including chatglm, whisper, and vicuna, and
utilizes heterogeneous hardware and a distributed architecture for
seamless cross-device and cross-server model deployment.
- This PR integrates Xinference models and Xinference embeddings into
LangChain.
- Dependencies: To install the depenedencies for this integration, run
    
    `pip install "xinference[all]"`
    
- Example Usage:

To start a local instance of Xinference, run `xinference`.

To deploy Xinference in a distributed cluster, first start an Xinference
supervisor using `xinference-supervisor`:

`xinference-supervisor -H "${supervisor_host}"`

Then, start the Xinference workers using `xinference-worker` on each
server you want to run them on.

`xinference-worker -e "http://${supervisor_host}:9997"`

To use Xinference with LangChain, you also need to launch a model. You
can use command line interface (CLI) to do so. Fo example: `xinference
launch -n vicuna-v1.3 -f ggmlv3 -q q4_0`. This launches a model named
vicuna-v1.3 with `model_format="ggmlv3"` and `quantization="q4_0"`. A
model UID is returned for you to use.

Now you can use Xinference with LangChain:

```python
from langchain.llms import Xinference

llm = Xinference(
    server_url="http://0.0.0.0:9997", # suppose the supervisor_host is "0.0.0.0"
    model_uid = {model_uid} # model UID returned from launching a model
)

llm(
    prompt="Q: where can we visit in the capital of France? A:",
    generate_config={"max_tokens": 1024},
)
```

You can also use RESTful client to launch a model:
```python
from xinference.client import RESTfulClient

client = RESTfulClient("http://0.0.0.0:9997")

model_uid = client.launch_model(model_name="vicuna-v1.3", model_size_in_billions=7, quantization="q4_0")
```

The following code block demonstrates how to use Xinference embeddings
with LangChain:
```python
from langchain.embeddings import XinferenceEmbeddings

xinference = XinferenceEmbeddings(
    server_url="http://0.0.0.0:9997",
    model_uid = model_uid
)
```

```python
query_result = xinference.embed_query("This is a test query")
```

```python
doc_result = xinference.embed_documents(["text A", "text B"])
```

Xinference is still under rapid development. Feel free to [join our
Slack
community](https://xorbitsio.slack.com/join/shared_invite/zt-1z3zsm9ep-87yI9YZ_B79HLB2ccTq4WA)
to get the latest updates!

- Request for review: @hwchase17, @baskaryan
- Twitter handle: https://twitter.com/Xorbitsio

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-27 21:23:19 -07:00
..
aleph_alpha.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
Awa.ipynb Add embeddings for AwaEmbedding (#8353) 2023-07-27 17:08:00 -07:00
azureopenai.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
bedrock.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
clarifai.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
cohere.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
dashscope.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
deepinfra.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
elasticsearch.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
embaas.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
fake.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
google_vertex_ai_palm.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
gpt4all.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
huggingfacehub.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
index.mdx mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
instruct_embeddings.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
jina.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
llamacpp.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
localai.ipynb Add embeddings for LocalAI (#8134) 2023-07-24 12:16:49 -07:00
minimax.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
modelscope_hub.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
mosaicml.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
nlp_cloud.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
openai.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
sagemaker-endpoint.ipynb Update SageMaker Endpoint Embeddings docs to be up to date with current requirements (#8103) 2023-07-24 13:35:06 -07:00
self-hosted.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
sentence_transformers.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
spacy_embedding.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
tensorflowhub.ipynb mv module integrations docs (#8101) 2023-07-23 23:23:16 -07:00
xinference.ipynb FEAT: Integrate Xinference LLMs and Embeddings (#8171) 2023-07-27 21:23:19 -07:00