Embeddings

Give the server an embedding model and a namespace can embed one text attribute itself: rows are written without vectors, and queries rank by text. Embeddings are cached, so repeated texts and queries skip the provider.

Embedding is an opt-in convenience. Writes and queries always accept vectors you compute yourself: without an embedding section in the server config, or in namespaces without an embed attribute, vectors are sent as usual, and even in a namespace that embeds, any row may carry its own vector and any query may rank by vector instead of text.

Configuring a model

The server talks to providers through Rig, so one config shape covers every provider:

providerAPIExample model
openaiOpenAI, or any OpenAI-compatible endpoint: Azure OpenAI, vLLM, Ollama, LiteLLMtext-embedding-3-small
cohereCohere v1/embedembed-v4.0
geminiGoogle Geminigemini-embedding-001
bedrockAmazon Bedrock: Titan Text Embeddings v2, Cohere Embed v3 and v4amazon.titan-embed-text-v2:0, cohere.embed-v4:0
yaml
# cluster.yaml
embedding:
  provider: openai
  model: text-embedding-3-small
  api_key: { source: env, name: OPENAI_API_KEY }  # or source: file
  dimensions: 512      # optional: shorter vectors
  # endpoint: http://ollama:11434/v1   # optional API root
  batch_size: 96       # texts per request
  timeout: 30          # seconds
  cache:
    capacity: 67108864 # bytes; 0 disables
  max_input_chars: 24573 # optional: longest text sent to the model
  split:               # passages of documents written without any
    max_chars: 8000    # optional
    overlap_chars: 0

api_key is read on every request, so a rotated key file applies without a restart. Endpoints that need no key, such as a local Ollama, can leave it out. Without dimensions, the server learns the model's vector length by embedding one probe text the first time it needs it. dimensions shortens vectors for models that support it: OpenAI's text-embedding-3-*, Gemini, Titan v2 (256, 512 or 1024), and Cohere Embed v4 on Bedrock (256, 512, 1024 or 1536). Cohere's own API embeds at a fixed size, so dimensions is rejected for cohere.

Cohere models, on Cohere's API or Bedrock, embed documents and queries differently: rows are embedded as search_document and query texts as search_query. The other models embed both the same way.

Amazon Bedrock

Bedrock authenticates with the AWS credential chain rather than api_key: an IAM role (IRSA or EKS Pod Identity on Kubernetes), the usual AWS_* environment variables, or a Bedrock API key in AWS_BEARER_TOKEN_BEDROCK. region picks the runtime endpoint, and defaults to the chain's region. endpoint doesn't apply.

yaml
embedding:
  provider: bedrock
  model: amazon.titan-embed-text-v2:0
  region: us-east-1
  dimensions: 512      # optional: 256, 512 or 1024 (the default)
yaml
embedding:
  provider: bedrock
  model: us.cohere.embed-v4:0  # or cohere.embed-english-v3, cohere.embed-multilingual-v3
  region: us-east-2
  dimensions: 1024             # optional, v4 only: 256, 512, 1024 or 1536 (the default)

The supported models are Titan Text Embeddings v2 and Cohere Embed v3 (English or multilingual) and v4; model can also be a cross-region inference profile id or ARN for one of them, such as us.cohere.embed-v4:0 or global.cohere.embed-v4:0. Where Bedrock serves a model only through inference profiles, as it does Cohere Embed v4 in most regions, the bare model id fails with "on-demand throughput isn't supported" and model must be a profile. The role then needs bedrock:InvokeModel on the profile and on the foundation model in every region the profile routes to. Namespaces pin the foundation model id without the profile, so moving between profiles of one model keeps existing namespaces usable. Application inference profiles aren't supported, because their ARNs don't name the model. Titan embeds one text per request, so a batch is sent as consecutive requests. Cohere models take up to 96 texts per request, so batch_size can't exceed 96 for them. Cohere Embed v3 embeds at a fixed 1024 dimensions, and Bedrock rejects v3 texts over 2,048 characters, which the server's input limit keeps them under.

On Kubernetes

Set spec.config.embedding on the Vector resource. The operator copies the key from apiKeySecretRef into the config Secret and points the servers at it:

yaml
apiVersion: telemetry.plural.sh/v1alpha1
kind: Vector
metadata:
  name: vector
spec:
  config:
    embedding:
      provider: cohere
      model: embed-v4.0
      apiKeySecretRef: { name: cohere, key: api-key }
      cacheSize: 128Mi    # per replica; 0 disables
      split: { maxChars: 4000, overlapChars: 200 }   # optional; also maxInputChars

For Bedrock, leave out apiKeySecretRef and give the pods AWS credentials instead, for example an IAM role allowed bedrock:InvokeModel, through the ServiceAccount:

yaml
spec:
  serviceAccount:
    annotations:
      eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/vector
  config:
    embedding:
      provider: bedrock
      model: cohere.embed-v4:0
      region: us-east-1

Every writer and reader gets the same model: writers embed rows, and readers embed query texts. Rotating the key Secret reaches running pods when the kubelet refreshes their Secret volume, without a restart. Changing the model, endpoint, or any other field restarts them.

Embedding an attribute

Mark one string attribute embed in a namespace's schema. A namespace created this way can leave out dimensions and take the model's:

bash
curl -X POST localhost:8080/api/v1/namespaces/articles/write \
  -H 'content-type: application/json' \
  -d '{
    "schema": { "body": { "type": "string", "embed": true, "full_text_search": true } },
    "upsert_rows": [
      { "id": 1, "title": "Rotating credentials", "body": "Rotate keys every 90 days…" },
      { "id": 2, "title": "Draft", "body": "…", "vector": [0.1, 0.2, …] }
    ]
  }'

Rows are embedded only when they are written without a vector:

  • Upserts and documents. A row or passage without a vector gets the embedding of its embed attribute. A row with neither is rejected with 400. A passage can inherit the attribute from its document's attributes, and a document without passages is split into them.
  • Patches. A patch that sets the embed attribute re-embeds the row, unless it sets vector too. Removing the attribute with null keeps the old vector.
  • Explicit vectors. A vector in the request is always used as given, for example to import vectors computed elsewhere with the same model.

The texts of one request are embedded together, in batches of batch_size. With the cache enabled, that happens before the namespace's write lock is taken, so a slow provider doesn't hold up other writes to the namespace. A provider failure fails the write with 502. Upserted rows and documents are embedded before any operation applies; patches are re-embedded as they apply, after the operations before them.

An embedded attribute is stored like any other, so it can also be returned, filtered, and declared full_text_search for hybrid search.

Input limits and splitting

The server sizes text for the model, so clients don't need to know its context window.

Every text is cut to the model's input limit before it's embedded: rows, passages, patches, and query texts alike. The attribute is still stored whole; only the text sent to the model is cut. The limit is max_input_chars, or without it the model's own:

ModelDefault limit, in characters
OpenAI and OpenAI-compatible endpoints24,573 (8,191 tokens)
Cohere v3 models, on Cohere's API1,536 (512 tokens)
Cohere v3 models, on Bedrock2,048, Bedrock's cap
Cohere Embed v4, on either API384,000 (128k tokens)
Gemini6,144 (2,048 tokens)
Titan Text Embeddings v224,576 (8,192 tokens)

Limits given in tokens are converted at 3 characters per token, which leaves room for code and JSON, as they tokenize more densely than prose. Models served by OpenAI-compatible endpoints such as vLLM or Ollama are assumed to take as much as OpenAI's; set max_input_chars for ones that take less.

Documents written without passages are split by the server. The document's embed attribute is split into passages of at most split.max_chars characters (8,000 by default, or the input limit if that's smaller), and each passage row holds its part of the text in that attribute alongside the document's other attributes. Splits fall at the coarsest boundary that fits: paragraphs, then lines, sentences, words, and as a last resort mid-word. With split.overlap_chars, each passage starts with up to that much of the previous one's end, so text near a boundary can be found from either side.

bash
curl -X POST localhost:8080/api/v1/namespaces/articles/write \
  -H 'content-type: application/json' \
  -d '{
    "upsert_documents": [{
      "id": "kb-42",
      "attributes": { "title": "Rotating credentials", "body": "A long article…" }
    }]
  }'

The document is stored as rows kb-42#0, kb-42#1, …, which queries collapse back to documents with limit.per. Sending passages instead keeps the split up to the client, as before. Upserting the document again re-splits it and drops passages beyond the new count. Changing the split settings applies to documents written afterwards.

Querying by text

ANN and kNN take a text in place of a vector in a namespace with an embed attribute:

json
{
  "rank_by": { "op": "ANN", "text": "how often should keys rotate?" },
  "filters": { "op": "Gte", "attribute": "year", "value": 2025 },
  "top_k": 5
}

Exactly one of vector and text is allowed. In a multi-query, the texts of every sub-query are embedded in one provider request, which makes hybrid search one round trip to the provider:

json
{
  "queries": [
    { "rank_by": { "op": "ANN", "text": "rotate credentials" } },
    { "rank_by": { "op": "BM25", "attribute": "body", "query": "rotate credentials" } }
  ],
  "rrf": {}
}

Models and namespaces

Vectors from different models can't be compared, so a namespace never mixes them. When a namespace first gets an embed attribute, it pins the configured model as its embedding_model, for example openai:text-embedding-3-small:512 (provider, model, and requested dimensions). The model's vector length must equal the namespace's dimensions.

From then on, embedding in that namespace requires the server to be configured with the same model. After a model change, or with the embedding section removed, writes that need embedding and text queries in namespaces pinned to the old model fail with 400, while writes with explicit vectors and vector queries still work. To move to a new model, create a new namespace, rewrite the rows into it (they are embedded with the new model), and switch clients over.

Caching

Each replica caches embeddings in memory with foyer, up to cache.capacity bytes (64 MiB by default, about 21,000 vectors of 768 dimensions). On Kubernetes, without cacheSize, the operator sizes it from each pod's memory limit; see memory and cache sizing. Entries are keyed by a hash of the model, the input kind (document or query), and the exact text. A row upserted again with the same text, a patch that sets the text back, and a repeated query all skip the provider. Within one request, duplicate texts are sent once.

MetricMeaning
vector_embedding_cache_hits_totalTexts served from the cache
vector_embedding_cache_misses_totalDistinct texts sent to the provider
vector_embedding_request_duration_secondsProvider request latency
vector_embedding_request_errors_totalFailed provider requests