Skip to content
K2 Chat

Embedding systems K2 engineering

Dimensions are not an embedding contract

Two vectors can have the same length and still describe completely different spaces. Safe migrations require a model contract and a corpus plan.

A vector database may accept a query as long as its length matches the index. That shape check is necessary, but it does not establish that the query and indexed passages mean the same thing geometrically.

Consider two embedding models that each return 768 numbers. Each model learned its own mapping from text into vectors. The coordinate at position 42 in one model has no general reason to correspond to coordinate 42 in the other. Matching dimensionality makes the arrays compatible with the database API; it does not make their neighborhoods comparable.

This matters whenever a system embeds documents at ingestion time and embeds questions later. If the document vectors come from model A and the query vector comes from model B, nearest-neighbor search still produces a ranking. The ranking can look orderly while being semantically meaningless. A successful request and a plausible score are not evidence that the embedding spaces match.

Define one contract for both sides

K2 Chat uses Gemini gemini-embedding-2 with an output dimensionality of 768 for both document passages and queries. The important property is the shared model contract, not the number alone. Ingestion failures propagate into the retry path instead of switching to a different embedding model with a coincidentally matching shape.

The contract should be explicit enough to review and enforce. At minimum, it identifies the provider model, requested output size, and expected vector shape. The system also rejects malformed output, including vectors with the wrong length or non-finite values. Those checks catch broken responses, while using the same model on both sides protects semantic compatibility.

Generation fallback is a separate decision. A chat completion provider can change without changing the vector space used for retrieval. Embedding fallback cannot be treated as the same kind of resilience feature because it changes the coordinates against which the corpus was indexed.

Treat a model change as a corpus migration

Once vectors exist, changing the embedding model changes the interpretation of every stored point. A safe migration therefore has two parts: produce vectors for the corpus under the new contract, and ensure queries use that same contract. Re-embedding only new uploads creates a mixed index. Switching query embeddings first makes old points difficult to retrieve. Either partial transition can silently degrade results.

The previous cross-model embedding fallback means existing corpora may contain vectors produced in more than one space. Those corpora need reindexing with the canonical model. A reindex is not just a bulk API call: each result should remain tied to the correct tenant, document, and source version, and readiness should only be declared when expected vectors are present and verified.

A migration plan should make the cutover conditions concrete. Keep track of which versions have been rebuilt, verify vector counts and metadata, then test retrieval through tenant filters before requiring the new metadata in the query path. Until a corpus is ready, compatibility behavior should be an explicit migration choice rather than an accidental mixture.

Test semantics and shape separately

Unit tests can confirm that the configured model and output dimensionality are sent and that malformed vectors are rejected. Those tests protect the mechanical contract. Retrieval evaluation can then check whether relevant evidence appears for representative questions after a reindex. Neither a 768-element array nor a successful provider response proves the new corpus works end to end.

The broader lesson applies to any vector system: dimensions describe shape, while model identity and version describe the coordinate system. Pin the embedding contract, fail clearly when it cannot be honored, and migrate the corpus whenever that contract changes. This turns a subtle retrieval regression into a visible operational event.