# Embedding

Embeddings are vector representations of text or other data that can be used in various machine learning and language processing applications. Embeddings convert words, sentences, or documents into numerical vectors in a high-dimensional space, making it easier for computers to understand and process the meaning of the data being analyzed. Here are some common uses of embeddings:

* **Search** works by converting each document and query into vectors. Search results are ranked based on the similarity of embedding vectors between the query and documents. The closer the vectors, the more relevant the result.
* **Clustering** works by grouping sentences converted into embedding vectors using clustering algorithms such as K-Means. Texts with similar embedding vectors are grouped together.
* **Recommendation** works by converting item descriptions into embedding vectors. When a user shows interest in an item, the system searches for other items with similar embedding vectors to recommend.
* **Anomaly Detection** works by converting sentences into vectors, so vectors that are significantly different from the majority of other vectors are identified as anomalies.
* **Diversity Measurement** works by obtaining vectors from sentences to analyze how diverse the sentences are in vector space, which can be measured by looking at the distribution of distances between vectors.
* **Classification** works by comparing sentence vectors with vectors of existing labels and classifying the sentence into the category with the most similar vector.

This endpoint uses the POST method, where request data is sent to the server for processing. The following endpoints are available for Embeddings that can be utilized.

At this time, only the following model, `baai/bge-multilingual-gemma2`, can be used for Embeddings. Here is the endpoint you can send:

{% tabs %}
{% tab title="Terminal" %}
{% code title="Example Request" lineNumbers="true" %}

```json
curl https://dekallm.cloudeka.ai/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "input": "Your text string goes here",
    "model": "baai/bge-multilingual-gemma2"
  }'
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code title="Example Request" lineNumbers="true" %}

```python
import requests

# URL endpoint
url = "https://dekallm.cloudeka.ai/v1/embeddings"

# Header with type conten and authorization
headers = {
    "Content-Type": "application/json",
    "Authorization": "API_KEY"  # replace API_KEY with your API key
}

# JSON data to be sent
data = {
    "input": "Your text string goes here",
    "model": "baai/bge-multilingual-gemma2"
}

# Request POST
response = requests.post(url, headers=headers, json=data)

# Checks whether the request was successful
if response.status_code == 200:
    print("Response:", response.json())
else:
    print("Failed to get embeddings. Status code:", response.status_code)
    print("Response:", response.text)
```

{% endcode %}
{% endtab %}
{% endtabs %}

Following are the results of the responses received.

{% code title="Response" lineNumbers="true" %}

```json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        .... (1536 floats total for ada-002)
        -0.0028842222,
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloudeka.ai/deka-llm/api-deka-llm/embedding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
