|
35 | 35 |
|
36 | 36 |
|
37 | 37 | class TogetherEmbeddings(BaseModel, Embeddings):
|
38 |
| - """TogetherEmbeddings embedding model. |
| 38 | + """Together embedding model integration. |
39 | 39 |
|
40 |
| - To use, set the environment variable `TOGETHER_API_KEY` with your API key or |
41 |
| - pass it as a named parameter to the constructor. |
| 40 | + Setup: |
| 41 | + Install ``langchain_together`` and set environment variable |
| 42 | + ``TOGETHER_API_KEY``. |
| 43 | +
|
| 44 | + .. code-block:: bash |
| 45 | +
|
| 46 | + pip install -U langchain_together |
| 47 | + export TOGETHER_API_KEY="your-api-key" |
| 48 | +
|
| 49 | + Key init args — completion params: |
| 50 | + model: str |
| 51 | + Name of Together model to use. |
| 52 | +
|
| 53 | + Key init args — client params: |
| 54 | + api_key: Optional[SecretStr] |
| 55 | +
|
| 56 | + See full list of supported init args and their descriptions in the params section. |
| 57 | +
|
| 58 | + Instantiate: |
| 59 | + .. code-block:: python |
| 60 | +
|
| 61 | + from __module_name__ import TogetherEmbeddings |
| 62 | +
|
| 63 | + embed = TogetherEmbeddings( |
| 64 | + model="togethercomputer/m2-bert-80M-8k-retrieval", |
| 65 | + # api_key="...", |
| 66 | + # other params... |
| 67 | + ) |
| 68 | +
|
| 69 | + Embed single text: |
| 70 | + .. code-block:: python |
| 71 | +
|
| 72 | + input_text = "The meaning of life is 42" |
| 73 | + vector = embed.embed_query(input_text) |
| 74 | + print(vector[:3]) |
42 | 75 |
|
43 |
| - Example: |
44 | 76 | .. code-block:: python
|
45 | 77 |
|
46 |
| - from langchain_together import TogetherEmbeddings |
| 78 | + [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915] |
| 79 | +
|
| 80 | + Embed multiple texts: |
| 81 | + .. code-block:: python |
| 82 | +
|
| 83 | + input_texts = ["Document 1...", "Document 2..."] |
| 84 | + vectors = embed.embed_documents(input_texts) |
| 85 | + print(len(vectors)) |
| 86 | + # The first 3 coordinates for the first vector |
| 87 | + print(vectors[0][:3]) |
| 88 | +
|
| 89 | + .. code-block:: python |
| 90 | +
|
| 91 | + 2 |
| 92 | + [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915] |
| 93 | +
|
| 94 | + Async: |
| 95 | + .. code-block:: python |
| 96 | +
|
| 97 | + vector = await embed.aembed_query(input_text) |
| 98 | + print(vector[:3]) |
| 99 | +
|
| 100 | + # multiple: |
| 101 | + # await embed.aembed_documents(input_texts) |
| 102 | +
|
| 103 | + .. code-block:: python |
47 | 104 |
|
48 |
| - model = TogetherEmbeddings() |
| 105 | + [-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188] |
49 | 106 | """
|
50 | 107 |
|
51 | 108 | client: Any = Field(default=None, exclude=True) #: :meta private:
|
|
0 commit comments