{"record":{"id":"b681c687a017d5c1","repo":"ruvnet/ruflo","slug":"vector-dimensions-must-match","errorCode":null,"errorMessage":"Vector dimensions must match","messagePattern":"Vector dimensions must match","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/integrations/agentic-flow.ts","lineNumber":690,"sourceCode":"    memoryUsage: number;\n  } {\n    const vectorSize = (this.config.dimensions ?? 1536) * 4; // 4 bytes per float32\n    const memoryUsage = this.vectors.size * vectorSize;\n\n    return {\n      vectorCount: this.vectors.size,\n      dimensions: this.config.dimensions ?? 1536,\n      indexType: this.config.indexType ?? 'hnsw',\n      memoryUsage,\n    };\n  }\n\n  /**\n   * Calculate cosine similarity between two vectors.\n   */\n  private cosineSimilarity(a: Float32Array, b: Float32Array): number {\n    if (a.length !== b.length) {\n      throw new Error('Vector dimensions must match');\n    }\n\n    let dotProduct = 0;\n    let normA = 0;\n    let normB = 0;\n\n    for (let i = 0; i < a.length; i++) {\n      dotProduct += a[i] * b[i];\n      normA += a[i] * a[i];\n      normB += b[i] * b[i];\n    }\n\n    const magnitude = Math.sqrt(normA) * Math.sqrt(normB);\n    if (magnitude === 0) return 0;\n\n    return dotProduct / magnitude;\n  }\n}","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/agentic-flow.ts#L672-L708","documentation":"cosineSimilarity() is the private kernel behind search(); it throws when its two vectors differ in length. In practice you see this message from search(query) when the query vector's length differs from the stored vectors' dimensions — search() itself performs no query-length pre-check, so the kernel rejects it mid-iteration. Stored vectors cannot cause it (store() already enforces config.dimensions), so the query is always the odd one out.","triggerScenarios":"Searching with an embedding produced by a different model or dimensionality than the store was initialized with; passing a padded/truncated or empty Float32Array as the query; reusing a query builder configured for another index.","commonSituations":"Switching embedding models so query-time and index-time embedders diverge; multiple embed functions in the codebase (one per feature) drifting in dimensions; hardcoded example vectors pasted into query code.","solutions":["Build queries with the exact same embedding function/model used for stored vectors","Pre-check query.length against the store's configured dimensions before calling search()","Centralize embedding in one helper used by both the store and search paths so dimensions cannot diverge"],"exampleFix":"// before\nconst hits = await db.search(embedSmall(queryText)); // 384-dim vs 1536-dim store → throws\n\n// after\nconst dims = 1536;\nconst q = embed1536(queryText); // same model as indexing\nif (q.length !== dims) throw new RangeError(`query is ${q.length}d, index expects ${dims}d`);\nconst hits = await db.search(q);","handlingStrategy":"validation","validationCode":"const DIMS = 1536; // dimensions the store was initialized with\nconst q = embed(queryText);\nif (q.length !== DIMS) {\n  throw new RangeError(`query is ${q.length}d; index expects ${DIMS}d — wrong embedder?`);\n}\nconst hits = await db.search(q);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use one shared embed() helper for both indexing and querying","Add a startup assertion: embed('ping').length === configured dimensions","When changing embedding models, rebuild the store and re-embed all vectors atomically"],"tags":["agentdb","vectors","search","embeddings"],"backgroundTag":"vector-dimension-mismatch","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}