{
  "id": "llm/embedding-vector-normalization-mismatch",
  "signature": "openai.BadRequestError: vector length must be 1 for cosine similarity",
  "signature_zh": "openai.BadRequestError: 向量长度必须为1以计算余弦相似度",
  "regex": "vector length must be 1 for cosine similarity",
  "domain": "llm",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "OpenAI's embedding API returns unit-normalized vectors by default, but custom embedding models or manual preprocessing may produce unnormalized vectors, causing cosine similarity computations to fail or return incorrect results.",
  "root_cause_type": "generic",
  "root_cause_zh": "OpenAI 的嵌入 API 默认返回单位归一化向量，但自定义嵌入模型或手动预处理可能产生未归一化的向量，导致余弦相似度计算失败或返回错误结果。",
  "versions": [
    {
      "version": "openai==1.3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "openai==1.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "text-embedding-ada-002",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "text-embedding-3-small",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "text-embedding-3-large",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Different embedding models produce vectors with different normalization properties; the root cause is not the model but the normalization step.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Dimension is unrelated to normalization; padding introduces noise and doesn't fix the length constraint.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Normalize vectors manually before insertion or query: `vector = vector / np.linalg.norm(vector)`",
      "success_rate": 0.95,
      "how": "Normalize vectors manually before insertion or query: `vector = vector / np.linalg.norm(vector)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use OpenAI's default embeddings which are already normalized; avoid custom models or manual normalization unless necessary.",
      "success_rate": 0.9,
      "how": "Use OpenAI's default embeddings which are already normalized; avoid custom models or manual normalization unless necessary.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Configure the vector database to use inner product distance instead of cosine similarity if supported (e.g., `metric='ip'` in Pinecone or Weaviate).",
      "success_rate": 0.75,
      "how": "Configure the vector database to use inner product distance instead of cosine similarity if supported (e.g., `metric='ip'` in Pinecone or Weaviate).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在插入或查询前手动归一化向量：`vector = vector / np.linalg.norm(vector)`",
    "使用 OpenAI 默认的嵌入（已归一化），除非必要，否则避免自定义模型或手动归一化。",
    "如果支持，将向量数据库配置为使用内积距离代替余弦相似度（例如，在 Pinecone 或 Weaviate 中设置 `metric='ip'`）。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/guides/embeddings/embedding-models",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-11-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}