# Embedding Models

To store text in a vector database, it must first be converted into a vector,
also known as an embedding. Typically, this vectorization is done by a third
party.

By selecting an embedding model when you create your Upstash Vector database,
you can now upsert and query raw string data when using your database instead of
converting your text to a vector first. The vectorization is done automatically
by your selected model.

## Models

Upstash Vector hosts the following embedding model for dense and hybrid indexes:

| Name                                                                                      | Dimension | Sequence Length | MTEB |
| ----------------------------------------------------------------------------------------- | --------- | --------------- | ---- |
| [openai/text-embedding-3-small](https://platform.openai.com/docs/guides/embeddings)       | 1536      | 8191            | 62.3 |

The MTEB score is the average reported by OpenAI in its
[model announcement](https://openai.com/index/new-embedding-models-and-api-updates/).

<Note>
  The sequence length is not a hard limit. The model truncates the input
  appropriately when given raw text that would result in more tokens than
  the given sequence length. However, we recommend not exceeding the sequence
  length to have more accurate results.
</Note>

For sparse and hybrid indexes, the following model can be selected:

| Name                                             |
| ------------------------------------------------ |
| [BM25](https://en.wikipedia.org/wiki/Okapi_BM25) |

See [Creating Sparse Vectors](/vector/features/sparseindexes#creating-sparse-vectors) for the details of the above model.

<Note>
  The BGE models (`BAAI/bge-large-en-v1.5`, `BAAI/bge-base-en-v1.5`,
  `BAAI/bge-small-en-v1.5` and `BAAI/bge-m3`) are no longer available for new
  indexes. If you need a different model, you can generate the embeddings
  yourself and create the index with a custom dimension.
</Note>

## Using a Model

To start using embedding models, create the index with a model of your choice.

<Frame style={{ width: '600px' }}>
  <img src='/img/vector/create_index_with_model.png' alt="Create a Vector index with an embedding model" />
</Frame>

Then, you can start upserting and querying raw text data without any extra
setup.

<Tabs>

<Tab title="Python">

```python
from upstash_vector import Index

index = Index(
    url="UPSTASH_VECTOR_REST_URL",
    token="UPSTASH_VECTOR_REST_TOKEN",
)

index.upsert(
    [("id-0", "Upstash is a serverless data platform.", {"field": "value"})],
)
```

</Tab>

<Tab title="JavaScript">

```js
import { Index } from "@upstash/vector"

const index = new Index({
  url: "UPSTASH_VECTOR_REST_URL",
  token: "UPSTASH_VECTOR_REST_TOKEN",
})

await index.upsert({
  id: "id-0",
  data: "Upstash is a serverless data platform.",
  metadata: {
    field: "value",
  },
})
```

</Tab>

<Tab title="Go">

```go
package main

import (
	"github.com/upstash/vector-go"
)

func main() {
	index := vector.NewIndex("UPSTASH_VECTOR_REST_URL", "UPSTASH_VECTOR_REST_TOKEN")

	index.UpsertData(vector.UpsertData{
		Id:       "id-0",
		Data:     "Upstash is a serverless data platform.",
		Metadata: map[string]any{"field": "value"},
	})
}
```

</Tab>

<Tab title="PHP">

```php
use Upstash\Vector\Index;
use Upstash\Vector\DataUpsert;

$index = new Index(
  url: 'UPSTASH_VECTOR_REST_URL',
  token: 'UPSTASH_VECTOR_REST_TOKEN',
);

$index->upsertData(new DataUpsert(
  id: 'id-0',
  data: 'Upstash is a serverless data platform.',
  metadata: [
    'field' => 'value',
  ],
));
```

</Tab>

<Tab title="curl">

```shell
curl $UPSTASH_VECTOR_REST_URL/upsert-data \
  -X POST \
  -H "Authorization: Bearer $UPSTASH_VECTOR_REST_TOKEN" \
  -d '{"id": "1", "data": "Upstash is a serverless data platform.", "metadata": {"field": "value"}}'
```

</Tab>

</Tabs>

<Tabs>

<Tab title="Python">

```python
from upstash_vector import Index

index = Index(
    url="UPSTASH_VECTOR_REST_URL",
    token="UPSTASH_VECTOR_REST_TOKEN",
)

index.query(
    data="What is Upstash?",
    top_k=1,
    include_metadata=True,
)
```

</Tab>

<Tab title="JavaScript">

```js
import { Index } from "@upstash/vector"

const index = new Index({
  url: "UPSTASH_VECTOR_REST_URL",
  token: "UPSTASH_VECTOR_REST_TOKEN",
})

await index.query({
  data: "What is Upstash?",
  topK: 1,
  includeMetadata: true,
})
```

</Tab>

<Tab title="Go">

```go
package main

import (
	"github.com/upstash/vector-go"
)

func main() {
	index := vector.NewIndex("UPSTASH_VECTOR_REST_URL", "UPSTASH_VECTOR_REST_TOKEN")

	index.QueryData(vector.QueryData{
		Data:            "What is Upstash?",
		TopK:            1,
		IncludeMetadata: true,
	})
}
```

</Tab>

<Tab title="PHP">

```php
use Upstash\Vector\Index;
use Upstash\Vector\DataQuery;

$index = new Index(
  url: 'UPSTASH_VECTOR_REST_URL',
  token: 'UPSTASH_VECTOR_REST_TOKEN',
);

$index->queryData(new DataQuery(
  data: 'What is Upstash?',
  topK: 1,
  includeMetadata: true,
));
```

</Tab>

<Tab title="curl">

```shell
curl $UPSTASH_VECTOR_REST_URL/query-data \
  -H "Authorization: Bearer $UPSTASH_VECTOR_REST_TOKEN" \
  -d '{"data": "What is Upstash?", "topK": 1, "includeMetadata": "true"}'
```

</Tab>

</Tabs>
