Skip to content

Commit e414bbc

Browse files
eyurtsevolgamurraft
authored andcommitted
togetherai[patch]: Update API Reference for together AI embeddings model (langchain-ai#25295)
Issue: langchain-ai#24856
1 parent 78a460a commit e414bbc

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

libs/partners/together/langchain_together/embeddings.py

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,74 @@
3535

3636

3737
class TogetherEmbeddings(BaseModel, Embeddings):
38-
"""TogetherEmbeddings embedding model.
38+
"""Together embedding model integration.
3939
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])
4275
43-
Example:
4476
.. code-block:: python
4577
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
47104
48-
model = TogetherEmbeddings()
105+
[-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]
49106
"""
50107

51108
client: Any = Field(default=None, exclude=True) #: :meta private:

0 commit comments

Comments
 (0)