You will generate embeddings using an API call to an embedding model providers like OpenAI, Cohere, or any open source models from a hub like huggingFace.
OpenAI text embedding is a good place to get started:
curl https://api.openai.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"input": "Your text string goes here",
"model": "text-embedding-3-small"
}'
Here’s a python code sample of doing that:
openai.api_key = os.getenv("OPENAI_API_KEY")
model = "text-embedding-ada-002"
def generate_embedding(text: str) -> list[float]:
resp = openai.Embedding.create(
input=[text],
model=model)
return resp["data"][0]["embedding"]
(taken from Building Generative AI Applications Using MongoDB: Harnessing the Power of Atlas Vector Search and Open Source Models | MongoDB)