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

# OpenAI

LanceDB registers the OpenAI embeddings function in the registry by default, as `openai`. Below are the parameters that you can customize when creating the instances:

| Parameter | Type | Default Value | Description |
| - | - | - | - |
| `name` | `str` | `"text-embedding-ada-002"` | The name of the model. |
| `dim` | `int` | Model default | Requested output dimensions for models that support shortening embeddings. Required for model names other than the OpenAI ones listed by `model_names()` (for example a model served behind an OpenAI-compatible `base_url`), where it is the model's embedding dimension. Use `func.ndims()` when defining the vector field. |
| `use_azure` | bool | `False` | Set true to use Azure OpenAI SDK |

Python 0.41.0 accepts only the model names returned by `model_names()`;
setting `dim` does not enable an arbitrary model name in that version. Custom
OpenAI-compatible model names with an explicit `dim` require the
[0.42.0b8 client](https://docs.lancedb.com/enterprise/v1-12-0/basics/sdk.md#enterprise-client-versions).

Set your OpenAI API key before running the example:

```bash Bash icon="terminal" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
export OPENAI_API_KEY="your-api-key"
```

```python Python icon="python" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
import tempfile
from pathlib import Path

import lancedb
from lancedb.embeddings import get_registry
from lancedb.pydantic import LanceModel, Vector

db_path = Path(tempfile.mkdtemp()) / "openai-embeddings"
db = lancedb.connect(str(db_path))
func = get_registry().get("openai").create(name="text-embedding-ada-002")

class Words(LanceModel):
    text: str = func.SourceField()
    vector: Vector(func.ndims()) = func.VectorField()

table = db.create_table("words", schema=Words, mode="overwrite")
table.add(
    [
        {"text": "hello world"},
        {"text": "goodbye world"},
    ]
)

query = "greetings"
actual = table.search(query).limit(1).to_pydantic(Words)[0]
print(actual.text)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.