> For the complete documentation index, see [llms.txt](https://docs.tensorx.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorx.ai/api-reference/embeddings.md).

# Embeddings

TensorX serves text embeddings through the standard OpenAI-compatible `/v1/embeddings` endpoint. One embedding model is available:

| Model                     | Output dimensions | Max input     | Pricing                                            |
| ------------------------- | ----------------- | ------------- | -------------------------------------------------- |
| `qwen/qwen3-embedding-8b` | 4096 (fixed)      | 40,960 tokens | See [tensorx.ai/models](https://tensorx.ai/models) |

## Basic usage

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.tensorx.ai/v1"
)

resp = client.embeddings.create(
    model="qwen/qwen3-embedding-8b",
    input="The capital of France is Paris."
)

vector = resp.data[0].embedding   # list of 4096 floats
```

Batch inputs by passing a list. Each item gets its own vector, returned in the same order:

```python
resp = client.embeddings.create(
    model="qwen/qwen3-embedding-8b",
    input=["first document", "second document", "third document"]
)
vectors = [d.embedding for d in resp.data]
```

## Input limit

The model context length is **40,960 tokens**. Requests above this are rejected; nothing is truncated for you.

For RAG or document indexing, chunk your text to well under 40,960 tokens per item before sending. Chunks of 512 to 1,024 tokens are typical for retrieval.

{% hint style="warning" %}
Every item in a batch must be non-empty. A blank or whitespace-only string fails the whole request. Filter empty strings before sending.
{% endhint %}

## The `dimensions` parameter is not supported

OpenAI's `text-embedding-3` models accept a `dimensions` parameter to shorten the output vector. Some client libraries and tools (for example Cherry Studio, and some Open WebUI setups) send it automatically.

`qwen/qwen3-embedding-8b` **does not accept `dimensions`**. Sending it fails the request. If your tool sets `dimensions` automatically, turn that option off. The model always returns the full 4096-dimensional vector.

{% hint style="info" %}
**Need smaller vectors?** Qwen3-Embedding uses Matryoshka Representation Learning, so you can shorten the vector yourself: request the full 4096-dim embedding, keep the first N values, then re-normalise (L2). Normalising *after* truncation is what preserves quality.

```python
import numpy as np

full = np.array(resp.data[0].embedding)   # 4096 dims
short = full[:512]                         # keep the first 512
short = short / np.linalg.norm(short)      # re-normalise
```

{% endhint %}

## Errors

All of the cases below return the same generic response:

```
HTTP 400
{ "error": { "message": "The request contained an invalid argument.
  Please check your request parameters and try again.",
  "type": "invalid_request_error", "code": "400" } }
```

The API does not tell you which of these caused it, so check them in order:

| Cause                                    | What to change                              |
| ---------------------------------------- | ------------------------------------------- |
| Sent a `dimensions` parameter            | Remove it; truncate client-side (see above) |
| Input over 40,960 tokens                 | Chunk the input to smaller pieces           |
| Blank or whitespace-only item in a batch | Filter empty inputs before sending          |

## See Also

* [Models](/api-reference/models.md) - full model catalogue
* [Rate Limits](/api-reference/rate-limits.md)
* [API Examples](/api-reference/api-examples.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.tensorx.ai/api-reference/embeddings.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
