Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OpenAI Embeddings

Plugin ID: nexus.embeddings.openai

Advertises the embeddings.provider capability backed by OpenAI’s /v1/embeddings API. Supports text-embedding-3-small (default), text-embedding-3-large, and text-embedding-ada-002. Compatible with Azure OpenAI and OpenAI-compatible proxies via base_url.

Configuration

nexus.embeddings.openai:
  api_key_env: OPENAI_API_KEY        # default; ignored if api_key is set directly
  # api_key: sk-...                  # direct literal (avoid checking in)
  # model: text-embedding-3-small    # default
  # dimensions: 1536                 # provider default; smaller = cheaper
  # base_url: https://api.openai.com/v1/embeddings
  # timeout: 30s
KeyTypeDefaultDescription
api_keystringOpenAI API key (direct literal).
api_key_envstringOPENAI_API_KEYEnv var name to read the key from when api_key is unset.
modelstringtext-embedding-3-smallEmbedding model.
dimensionsint(provider default)Optional truncation. text-embedding-3-* accepts arbitrary smaller dims; older models ignore this.
base_urlstringhttps://api.openai.com/v1/embeddingsOverride for Azure / proxies.
timeoutduration30sHTTP timeout for the embeddings call.

Model picking

ModelDim (default)Notes
text-embedding-3-small1536Default. Cheap, good enough for most retrieval.
text-embedding-3-large3072~3× the price; better on hard semantic tasks, more storage.
text-embedding-ada-0021536Legacy. Cheaper than 3-large, less accurate than 3-small.

You can request a smaller dimensionality from text-embedding-3-* to trade some quality for storage and search latency:

nexus.embeddings.openai:
  model: text-embedding-3-large
  dimensions: 1024     # roughly 3-small accuracy at 2/3 the storage

Switching models

The embedding cache (in nexus.rag.ingest) is keyed on content hash, not model. Mixing vectors from two models in one namespace produces nonsense rankings, so when you change model or dimensions you should:

rm -rf ~/.nexus/vectors/_cache/
nexus ingest --namespace=kb ./docs    # re-embed under the new model

Events

EventDirectionPayload
embeddings.requestAny → plugin*EmbeddingsRequest

Pointer-fill: the plugin sets req.Vectors, req.Provider, req.Model, req.Usage (or req.Error) in place.

Errors

  • no API key configured (set api_key in config or OPENAI_API_KEY env var) at boot — set the key in env or in the config block.
  • openai returned HTTP 401 — invalid or expired key. Check the variable name in api_key_env is the one actually set in the shell.
  • expected N embeddings, got M — the API returned a different number of vectors than the input text count. The adapter retries the request internally; if you see this surfaced, the API call partially failed mid-stream. Re-running ingest will pick up where the cache stopped.