Semantic search using Elasticsearch and OpenAI (Part 9)
Encode a question with OpenAI embedding model
To perform semantic search, we need to encode queries with the same embedding model used to encode the documents at index time. In this example, we need to use the text-embedding-ada-002 model.

You'll need your OpenAI API key to generate the embeddings.

# Get OpenAI API key
OPENAI_API_KEY = getpass("Enter OpenAI API key")

# Set API key
openai.api_key = OPENAI_API_KEY

# Define model
EMBEDDING_MODEL = "text-embedding-ada-002"

# Define question
question = 'Is the Atlantic the biggest ocean in the world?'

# Create embedding
question_embedding = openai.Embedding.create(input=question, model=EMBEDDING_MODEL)