export const metadata = {
  title: 'Embeddings',
  description: 'Generate embeddings',
}

# Embeddings

Generate embeddings from text. {{ className: 'lead' }}

---

## Create embeddings {{ tag: 'POST', label: 'http://localhost:33322/v1/embeddings' }}

<Row>
  <Col>
    Given a list of messages belonging to a chat history, generate a response.

    ### Required attributes

    <Properties>
      <Property name="input" type="string or array">
        One or multiple pieces of text from which embeddings will be generated. For each piece of text, one embedding is generated.
      </Property>
    </Properties>

    <Properties>
      <Property name="model" type="string">
        The model used for chat completions.
        <ul>
            <li>
                If the model name is "default", the chat model from the configuration is used (see [Documentation &raquo; Configuration](/documentation/configuration) for details).
            </li>
            <li>
                If the model name follows the format repo-owner/repo-name/model-name, the indicated model is used and, if it is not present, it will be downloaded from [huggingface](https://huggingface.co/). If it cannot be downloaded, Edgen responds with an error. Example: "nomic-ai/nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.f16.gguf".
            </li>
            <li>
                If the model name contains just a file name, e.g.: "my-model.bin", Edgen will try using the file of this name in the data directory as defined in the configuration. If the the file does not exist there, Edgen responds with an error.
            </li>
        </ul>
      </Property>
    </Properties>

    ### Optional attributes

      <Properties>
          <Property name="response_format" type="string">
              The format to return the embeddings in. Can be either `float` or `base64`.
          </Property>
      </Properties>

      <Properties>
          <Property name="dimensions" type="integer">
              The number of dimensions the resulting output embeddings should have. Only supported in some models.
          </Property>
      </Properties>

  </Col>
  <Col sticky>

    <CodeGroup title="Request" tag="POST" label="/v1/embeddings">

    ```bash {{ title: 'cURL' }}
    curl http://localhost:33322/v1/embeddings \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer no-key-required" \
    -d '{
      "model": "default",
      "input": "Hello World!"
    }'
    ```

    ```python
    from edgen import Edgen
    client = Edgen()

    embeddings = client.embeddings.create(
      model="default",
      input="Who is John Doe?"
    )

    for item in completion.data:
      print(data.embedding)
    ```

    ```ts
    import Edgen from "edgen";

    const client = new Edgen();

    async function main() {
      const embeddings = await client.embeddings.create({
        model: "default",
        messages: "Who is Foo Bar?"
      });

      for await (const item of embeddings.data) {
        console.log(item.embedding.content);
      }
    }

    main();
    ```

    </CodeGroup>

    ```json {{ title: 'Response' }}
    {
      "object": "list",
      "data": [
        {
          "object": "embedding",
          "embedding": [
            0.0023064255,
            -0.009327292,
            ....
            -0.0028842222,
          ],
          "index": 0
        }
      ],
      "model": "default",
      "usage": {
        "prompt_tokens": 8,
        "total_tokens": 8
      }
    }
    ```

  </Col>
</Row>
