> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trychroma.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sentence Transformer

export const Callout = ({title, children}) => <div className="my-6">
    <div className="relative pr-1.5 pb-1.5">
      <div className="absolute top-1.5 left-1.5 right-0 bottom-0 bg-blue-500 dark:bg-blue-600" />
      <div className="relative border border-black dark:border-gray-500 px-5 py-4 bg-white dark:bg-neutral-900">
        {title && <p className="block mb-2"><strong>{title}</strong></p>}
        {children}
      </div>
    </div>
  </div>;

Chroma provides a convenient wrapper around the Sentence Transformers library. This embedding function runs locally and uses pre-trained models from Hugging Face.

<Tabs>
  <Tab title="Python" icon="python">
    This embedding function relies on the `sentence_transformers` python package, which you can install with `pip install sentence_transformers`.

    ```python theme={null}
    from chromadb.utils.embedding_functions import SentenceTransformerEmbeddingFunction

    sentence_transformer_ef = SentenceTransformerEmbeddingFunction(
        model_name="all-MiniLM-L6-v2",
        device="cpu",
        normalize_embeddings=False
    )

    texts = ["Hello, world!", "How are you?"]
    embeddings = sentence_transformer_ef(texts)
    ```

    You can pass in optional arguments:

    * `model_name`: The name of the Sentence Transformer model to use (default: "all-MiniLM-L6-v2")
    * `device`: Device used for computation, "cpu" or "cuda" (default: "cpu")
    * `normalize_embeddings`: Whether to normalize returned vectors (default: False)

    For a full list of available models, visit [Sentence Transformers models on Hugging Face](https://huggingface.co/models?library=sentence-transformers) or [SBERT documentation](https://www.sbert.net/docs/pretrained_models.html).
  </Tab>

  <Tab title="TypeScript" icon="js">
    ```typescript theme={null}
    // npm install @chroma-core/sentence-transformer

    import { SentenceTransformersEmbeddingFunction } from "@chroma-core/sentence-transformer";

    const sentenceTransformerEF = new SentenceTransformersEmbeddingFunction({
        modelName: "all-MiniLM-L6-v2",
        device: "cpu",
        normalizeEmbeddings: false,
    });

    const texts = ["Hello, world!", "How are you?"];
    const embeddings = await sentenceTransformerEF.generate(texts);
    ```
  </Tab>
</Tabs>

<Callout>
  Sentence Transformers are great for semantic search tasks. Popular models include `all-MiniLM-L6-v2` (fast and efficient) and `all-mpnet-base-v2` (higher quality). Visit [SBERT documentation](https://www.sbert.net/docs/pretrained_models.html) for more model recommendations.
</Callout>
