{"record":{"id":"7a17b019f0c4e094","repo":"mem0ai/mem0","slug":"collection-name-exists-but-has-wrong-vector-siz","errorCode":null,"errorMessage":"Collection ${name} exists but has wrong vector size. Expected: ${size}, got: ${vectorConfig.size}","messagePattern":"Collection (.+?) exists but has wrong vector size\\. Expected: (.+?), got: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/vector_stores/qdrant.ts","lineNumber":596,"sourceCode":"        this._hasBm25Slot = true;\n      }\n      if (name === this.collectionName) {\n        await this.createFilterIndexes(name);\n      }\n    } catch (error: any) {\n      if (\n        error?.status === 409 ||\n        error?.status === 401 ||\n        error?.status === 403\n      ) {\n        // Collection already exists — verify configuration for the main collection\n        if (name === this.collectionName) {\n          try {\n            const collectionInfo = await this.client.getCollection(name);\n            const vectorConfig = collectionInfo.config?.params?.vectors;\n\n            if (vectorConfig && vectorConfig.size !== size) {\n              throw new Error(\n                `Collection ${name} exists but has wrong vector size. ` +\n                  `Expected: ${size}, got: ${vectorConfig.size}`,\n              );\n            }\n\n            if (enableBm25) {\n              // Existing collection: enable BM25 only if the slot is present.\n              const sparseConfig = (collectionInfo.config?.params as any)\n                ?.sparse_vectors;\n              this._hasBm25Slot = !!(\n                sparseConfig && BM25_VECTOR_NAME in sparseConfig\n              );\n              if (!this._hasBm25Slot) {\n                console.warn(\n                  `Collection '${name}' predates hybrid search (no '${BM25_VECTOR_NAME}' sparse slot). ` +\n                    \"BM25 keyword scoring is disabled for this collection; semantic search works normally. \" +\n                    \"Use a fresh collection to enable hybrid keyword search.\",\n                );","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/qdrant.ts#L578-L614","documentation":"When the Qdrant store tries to create a collection and gets a 409 (already exists), it fetches the existing collection's config and compares the configured vector size against this store's dimension. A mismatch throws, because inserting vectors of a different dimension into the collection would fail at the API level and usually means the embedding model changed.","triggerScenarios":"Creating the Qdrant store with dimension 768 while the existing collection was created with 1536 (or vice versa); switching embedding models (e.g. from text-embedding-ada-002 to a 768-dim model) without recreating collections; setting embeddingModelDims differently across services sharing one Qdrant collection.","commonSituations":"Rolling out a new embedding model to one service while others still use the old one; stale collections from earlier experiments; typo in dimension config; multiple environments pointing at the same Qdrant instance.","solutions":["Align the store's dimension with the existing collection (fix embeddingModelDims/config to match what the collection reports)","Or delete and recreate the collection with the new dimension: qdrant PUT /collections/<name> after DELETE, then re-ingest memories","If switching embedding models permanently, re-embed all stored memories into a fresh collection — vectors from different models are not comparable","Use a new collection name per embedding model (e.g. memories_768) to avoid collisions"],"exampleFix":"// before (collection exists with size 1536)\nconst vs = new Qdrant({ collectionName: 'memories', embeddingModelDims: 768 });\n\n// after: use a separate collection per dimension\nconst vs = new Qdrant({ collectionName: 'memories_768', embeddingModelDims: 768 });","handlingStrategy":"validation","validationCode":"import { QdrantClient } from '@qdrant/js-client-rest';\nasync function assertCollectionDims(url: string, name: string, expected: number): Promise<void> {\n  const client = new QdrantClient({ url });\n  const info = await client.getCollection(name);\n  const size = (info.config?.params?.vectors as any)?.size;\n  if (size && size !== expected) {\n    throw new Error(`Dimension mismatch: collection=${size}, app=${expected}`);\n  }\n}\nawait assertCollectionDims(qdrantUrl, 'memories', 768);","typeGuard":"const dimsMatch = (a?: number, b?: number): boolean => a === undefined || b === undefined || a === b;","tryCatchPattern":"try { const vs = new Qdrant(config); await vs.createCol(undefined, 768); } catch (e) { if (e instanceof Error && e.message.includes('wrong vector size')) { /* pick new collection name or migrate, not a retry */ } throw e; }","preventionTips":["Pin one embedding model and dimension per collection, and encode the dimension in the collection name","Check collection dims in a startup probe before serving traffic","When changing embedding models, always recreate collections and re-embed data"],"tags":["qdrant","embedding-dimension","configuration","migration","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}