mirror of
https://github.com/qdrant/landing_page.git
synced 2026-09-30 08:28:32 +02:00
47 lines
1.2 KiB
Markdown
47 lines
1.2 KiB
Markdown
---
|
|
title: OpenAI
|
|
weight: 800
|
|
aliases: [ ../integrations/openai/ ]
|
|
---
|
|
|
|
# OpenAI
|
|
|
|
Qdrant can also easily work with [OpenAI embeddings](https://platform.openai.com/docs/guides/embeddings/embeddings).
|
|
|
|
There is an official OpenAI Python package that simplifies obtaining them, and it might be installed with pip:
|
|
|
|
```bash
|
|
pip install openai
|
|
```
|
|
|
|
Once installed, the package exposes the method allowing to retrieve the embedding for given text. OpenAI requires an API key that has to be provided either as an environmental variable `OPENAI_API_KEY` or set in the source code directly, as presented below:
|
|
|
|
```python
|
|
import openai
|
|
import qdrant_client
|
|
|
|
from qdrant_client.http.models import Batch
|
|
|
|
# Choose one of the available models:
|
|
# https://platform.openai.com/docs/models/embeddings
|
|
embedding_model = "text-embedding-ada-002"
|
|
|
|
openai_client = openai.Client(
|
|
api_key="<< your_api_key >>"
|
|
)
|
|
response = openai_client.embeddings.create(
|
|
input="The best vector database",
|
|
model=embedding_model,
|
|
)
|
|
|
|
qdrant_client = qdrant_client.QdrantClient()
|
|
qdrant_client.upsert(
|
|
collection_name="MyCollection",
|
|
points=Batch(
|
|
ids=[1],
|
|
vectors=[response.data[0].embedding],
|
|
),
|
|
)
|
|
```
|
|
|