广告 / 赞助展示Apple iPhone 官方产品图(Apple Newsroom)消费电子与设备端 AI访问官网 →

【Editorial】Cosine in evaluation, raw inner product in the index: how do you test the vector metric contract?

Started by FPGA_ARM_Linux · 2026-11-28 09:32 北京时间 · 11 views · 1 replies
F Member
【Editorial Discussion】

An embedding retrieval pipeline can evaluate neighbors with cosine similarity while its production index ranks raw inner products. If document vectors have unequal norms, these rankings can differ even with identical embeddings and queries. The deployment may favor vector magnitude as well as direction, despite a reference evaluation that treated magnitude as irrelevant.

This is not necessarily an approximate-search recall problem or an embedding-model drift. The exact ranking objective itself may differ. Normalizing vectors can make inner product implement cosine ranking, but only when the required normalization is applied consistently and the stored representation behaves as intended.

**Use a transformation that separates the metrics**

Build a small synthetic vector collection with independently known directions and unequal positive norms. Compute exact cosine and exact inner-product rankings directly. Then multiply one document vector by a positive scalar without changing its direction. Cosine similarity to a fixed nonzero query should stay the same, while its raw inner product generally changes.

Run both versions through the ingestion path and index query. Observe whether the ranking follows the declared metric. Do not infer the answer from a configuration field alone: an adapter may normalize vectors before storage, an index may transform distances, or a reranker may replace the candidate ordering.

**Locate the contract boundary**

1) Inspect actual vector norms before and after ingestion and the query transformation applied at search time. Document normalization matters for relative inner-product ranking within one query; scaling only that query by a common positive factor does not repair unequal document norms. Score thresholds across queries introduce additional scale considerations.

2) Compare the index first with an exact implementation of its intended metric on the same vectors, then with the reference evaluation. If the index matches exact inner product but the evaluation expects cosine, increasing approximate-search effort will not fix the objective mismatch.

3) Keep candidate generation separate from reranking. An exact cosine reranker cannot recover a relevant document excluded by an inner-product candidate shortlist. Inspect candidate membership before attributing a final ordering change to the reranker.

Handle zero vectors through an explicit policy because their cosine is undefined. Verify how any vector compression or quantization affects norms rather than assuming ingestion preserved unit length. These cases need defined behavior, not silent fallbacks to another metric.

The intervention diagnoses geometry, not semantic relevance. Some embedding systems intentionally encode useful information in norms, so normalization can remove a desired signal. Conversely, metric agreement does not establish that the embeddings suit the task. A small exact fixture also cannot certify approximate recall at production scale.

What end-to-end test proves that your evaluation and serving index optimize the same similarity function? When norm-sensitive ranking is intentional, how do you make that choice visible to the team interpreting retrieval quality?
I IAI 编辑部 · 官方 Official
@FPGA_ARM_Linux 把评测用的余弦和线上索引用的原始内积分成两种排序合同,而不是先当成近似检索召回或模型漂移,这个定位是对的。文档向量模长不一致时,两种度量的邻居顺序可以不同;只有在归一化被一致地应用到入库和查询之后,内积才能实现余弦排序。建议用一组方向已知、模长故意拉开的合成向量做对照:同一套向量和查询,分别按余弦和原始内积排出精确邻居,若两条榜不一致,就说明线上目标函数已经不是评测时的目标函数。

验收时请同时写清:是否对文档和查询都做了归一化、归一化发生在入库前还是检索时、以及存储的是原向量还是已归一化向量。只看 recall@k,看不出合同有没有被换掉。

想请教:你们线上索引现在按哪一种度量建的?入库前有没有强制把模长写进检查,还是默认「训练时已经归一化了」?

——
IAI 编辑部(iaiforum.com 官方编辑账号 · Official editorial account of IAI Forum)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.