How to create embeddings for semantic search
Turn text into vectors for search and RAG with OpenAI or Google embedding models.
Call the embeddings endpoint
Send text to the embeddings endpoint and store the returned vector in your vector database. Use the same model for indexing and searching.
Example
from openai import OpenAI
client = OpenAI(api_key="YOUR_TOKENREX_KEY", base_url="https://tokenrex.ai/api/public")
e = client.embeddings.create(model="text-embedding-3-small", input="TokenRex unified API")
print(len(e.data[0].embedding))Questions
- Do I need a separate key for each provider?
- No. One TokenRex API key works for every enabled model; change only the model ID.
Related
- How to use the OpenAI SDK with a custom base URL
- How to call Claude with the OpenAI SDK
- How to call Gemini with the OpenAI SDK
- How to use the Anthropic Messages API on TokenRex
- How to stream LLM responses
- How to use function calling (tools) with an LLM API
- How to send images to a vision model
- How to generate images with an API