# TogetherEmbeddings

> **Class** in `langchain_together`

📖 [View in docs](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings)

Together embedding model integration.

## Signature

```python
TogetherEmbeddings()
```

## Description

**Setup:**

Install ``langchain_together`` and set environment variable
``TOGETHER_API_KEY``.

.. code-block:: bash

    pip install -U langchain_together
    export TOGETHER_API_KEY="your-api-key"

Key init args — completion params:
    model: str
        Name of Together model to use.

Key init args — client params:
  api_key: Optional[SecretStr]

See full list of supported init args and their descriptions in the params section.

**Instantiate:**

.. code-block:: python

from __module_name__ import TogetherEmbeddings

embed = TogetherEmbeddings(
    model="togethercomputer/m2-bert-80M-8k-retrieval",
    # api_key="...",
    # other params...
)

**Embed single text:**

.. code-block:: python

    input_text = "The meaning of life is 42"
    vector = embed.embed_query(input_text)
    print(vector[:3])

.. code-block:: python

    [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]

**Embed multiple texts:**

.. code-block:: python

     input_texts = ["Document 1...", "Document 2..."]
    vectors = embed.embed_documents(input_texts)
    print(len(vectors))
    # The first 3 coordinates for the first vector
    print(vectors[0][:3])

.. code-block:: python

    2
    [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]

**Async:**

.. code-block:: python

    vector = await embed.aembed_query(input_text)
   print(vector[:3])

    # multiple:
    # await embed.aembed_documents(input_texts)

.. code-block:: python

    [-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]

## Extends

- `BaseModel`
- `Embeddings`

## Properties

- `client`
- `async_client`
- `model`
- `dimensions`
- `together_api_key`
- `together_api_base`
- `embedding_ctx_length`
- `allowed_special`
- `disallowed_special`
- `chunk_size`
- `max_retries`
- `request_timeout`
- `show_progress_bar`
- `model_kwargs`
- `skip_empty`
- `default_headers`
- `default_query`
- `http_client`
- `http_async_client`
- `model_config`

## Methods

- [`build_extra()`](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings/build_extra)
- [`post_init()`](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings/post_init)
- [`embed_documents()`](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings/embed_documents)
- [`embed_query()`](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings/embed_query)
- [`aembed_documents()`](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings/aembed_documents)
- [`aembed_query()`](https://reference.langchain.com/python/langchain-together/embeddings/TogetherEmbeddings/aembed_query)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-together/blob/1a6545d022497fbef3b414258a985d96b02a1963/libs/together/langchain_together/embeddings.py#L33)