A vector collection groups records whose embeddings can be compared under one numeric contract. Its dimension must be fixed because distance functions compare coordinates position by position; a 768-value vector and a 1,536-value vector do not inhabit the same coordinate space. For marketplace duplicate detection, use one embedding model and preprocessing version per collection, validate length before accepting a write, and migrate model changes into a new collection. That preserves retrieval quality without moving contract errors onto the latency-sensitive query path.

TL;DR: dimension is part of the collection schema, not incidental metadata. Store model and preprocessing revisions with that schema, reject malformed writes, and make retries idempotent.

What does a fixed dimension actually guarantee?

An embedding is an ordered list of floating-point values. Similarity measures such as cosine similarity require equal lengths because the dot product multiplies corresponding coordinates. A fixed dimension tells the index how many values each record contributes. It does not prove that two vectors mean the same thing.

That distinction matters. Two models may both emit 768 values while assigning different meanings to the coordinates. Even one model is insufficient as a contract if one path embeds a title while another embeds title, category, attributes, and description. Record the immutable model revision, dimension, text-normalization version, distance metric, source ID, and content revision.

The invariant in my runbook is simple: every candidate compared in one search comes from the same embedding contract. Fixed length blocks invalid arithmetic; versioned provenance exposes invalid meaning.

Length is necessary. It is not sufficient.

A collection is therefore a typed index, not a bag of arrays. It owns vectors, identifiers, metadata, and indexing configuration. In retrieval-augmented generation, neighbors can become generation context. Here they become candidate marketplace listings for a later duplicate decision. Retrieval proposes. It should not silently make the final decision.

The incident lesson: validate before acknowledging the job

The production failure shape is familiar from cron and queues: a scheduled re-embedding job changes behavior, deliveries retry, and workers do not switch revisions simultaneously. Queues can deliver a message more than once, so the write path must tolerate duplicates. A loud rejection is manageable. A partly migrated corpus whose answers still look plausible is harder to detect.

Silent drift is worse.

I treat the collection boundary like an on-call boundary. Validate the declared contract before acknowledging work, and build the write key from the source revision plus embedding revision. A retry then overwrites the same artifact rather than creating another candidate. If validation fails, retain the job for repair and keep it out of the searchable set.

package vectors import ( "context" "errors" "fmt" ) type Contract struct { Collection, Model, Preprocessor string Dimension int } type Record struct { ID string Vector []float32 Metadata map[string]string } type Store interface { Upsert(context.Context, string, Record) error } func Index(ctx context.Context, store Store, c Contract, r Record) error { if c.Dimension <= 0 { return errors.New("collection dimension must be positive") } if len(r.Vector) != c.Dimension { return fmt.Errorf("embedding dimension: got %d, want %d", len(r.Vector), c.Dimension) } if r.ID == "" { return errors.New("stable record ID is required") } if r.Metadata["model"] != c.Model || r.Metadata["preprocessor"] != c.Preprocessor { return errors.New("embedding contract mismatch") } return store.Upsert(ctx, c.Collection, r) } 

Do not retry a dimension mismatch forever. It is permanent until code, configuration, or data changes. Record expected and actual dimensions, revisions, job ID, and collection generation. Alert on a sustained rejection rate, while preserving each rejected item for repair.

Retrieval quality versus latency is a staged decision

Near-duplicate listings are messier than identical text. Sellers reorder words, omit attributes, translate descriptions, or reuse generic captions. Semantic retrieval can find candidates that token matching misses, but it also retrieves related products that are not duplicates. A 256 GB phone and its 128 GB sibling may be linguistically close and still be the wrong merge.

Use the vector index for candidate generation, then apply deterministic constraints and a separately evaluated decision rule. Category, region, normalized units, model number, condition, and structured attributes can filter or rerank candidates. Selective filters may save work early; weak filters may add latency without improving precision. Measure both outcomes.

Stage Purpose Quality risk Latency control
Normalize Stable embedding input Lost attributes Version and cache
Retrieve Find semantic candidates Related but distinct items Bound candidate count
Check facts Enforce listing constraints Missing fields Apply selective checks first
Decide Label or review a pair False merge Keep a review band

There is no universal similarity threshold. Build a labeled set from the marketplace's duplicate policy, including hard negatives such as adjacent sizes, capacities, bundle quantities, and refurbished versus new condition. Evaluate recall at the candidate limit because a downstream classifier cannot recover a true match retrieval omitted. Track precision separately for automatic actions; route ambiguous pairs to review.

Latency needs percentiles, not an average. Track p50, p95, and p99 with candidate recall, filtered counts, generation, and timeout rate. These are measurement buckets, not benchmark claims. A smaller candidate limit reduces downstream work but may lose duplicates. A larger one spends more latency on checks. Set it from a service objective and labeled evaluation, not a ten-record demo.

This trade-off has no free setting.

Migrating without mixing comparison spaces

A model change is a schema migration even when output dimension stays the same. Create a new collection generation, backfill it, and leave the old one serving while coverage grows. Dual-write new listing revisions if the team can operate that path safely. Otherwise record a high-water mark and catch up before cutover.

Do not query both spaces, concatenate their scores, and sort. Scores from different models are not automatically calibrated. Evaluate both generations against the same labeled queries and compare candidate recall, false-candidate burden, latency percentiles, and coverage. Promote with one atomic alias or configuration change after acceptance criteria pass. Keep rollback boring.

The scheduler needs explicit states: created, backfilling, catching up, verified, active, and retired. A lease prevents two workers from owning one partition; checkpoints bound restart work. Upserts remain idempotent. Split metrics by generation so a healthy old index cannot hide a stalled replacement.

Fixed dimension earns its keep here: different-length output fails during ingestion instead of contaminating results. Same-length semantic drift still needs generation boundaries and evaluation. Dimension alone cannot catch it.

When is a vector collection the wrong tool?

The main limitation is that semantic proximity is not identity. Exact identifiers should win when trustworthy ones exist. Use normalized manufacturer identifiers or other authoritative keys before semantic matching. Hashes and canonical fields work better for byte-identical or mechanically equivalent records. Vector retrieval helps when identity signals are missing, multilingual, or indirect, but its downside is a candidate set that still needs policy-aware verification. Automatic merging is not suitable when false positives can transfer reviews, inventory, or seller history between distinct products. In that case, keep vectors as a recall-oriented first stage and require deterministic evidence or human review before changing records.

Sometimes a slice and a loop are enough.

An index may be unnecessary when the corpus is small enough for offline comparison within the response-time requirement. It trades operational complexity for bounded online search, bringing rebuilds, backups, capacity planning, and stale-generation procedures. The operational cost is real: the team owns migrations, recovery tests, capacity alarms, and the failure mode where an apparently healthy endpoint serves an old generation. Choose brute-force offline comparison for bounded batch work, exact matching for authoritative identifiers, and a vector collection only when semantic candidate retrieval at corpus scale justifies that machinery.

The decision is not which dimension is universally best. Dimension follows the embedding contract. Select a model with representative marketplace evaluation, verify that its quality, storage, and latency fit the service objective, and lock its output length at the collection boundary. Treat later model or preprocessing changes as new indexed data with a measured migration.

Fixed dimension prevents one class of invalid comparison. Pair it with provenance, idempotent ingestion, staged decisions, and generation-based rollout. Those controls keep a scheduled embedding job from becoming a silent retrieval incident.

Sources