mem0ai/mem0 · critical · Error

Collection ${name} exists but has wrong vector size. Expecte

Error message

Collection ${name} exists but has wrong vector size. Expected: ${size}, got: ${vectorConfig.size}

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/qdrant.ts:596

        this._hasBm25Slot = true;
      }
      if (name === this.collectionName) {
        await this.createFilterIndexes(name);
      }
    } catch (error: any) {
      if (
        error?.status === 409 ||
        error?.status === 401 ||
        error?.status === 403
      ) {
        // Collection already exists — verify configuration for the main collection
        if (name === this.collectionName) {
          try {
            const collectionInfo = await this.client.getCollection(name);
            const vectorConfig = collectionInfo.config?.params?.vectors;

            if (vectorConfig && vectorConfig.size !== size) {
              throw new Error(
                `Collection ${name} exists but has wrong vector size. ` +
                  `Expected: ${size}, got: ${vectorConfig.size}`,
              );
            }

            if (enableBm25) {
              // Existing collection: enable BM25 only if the slot is present.
              const sparseConfig = (collectionInfo.config?.params as any)
                ?.sparse_vectors;
              this._hasBm25Slot = !!(
                sparseConfig && BM25_VECTOR_NAME in sparseConfig
              );
              if (!this._hasBm25Slot) {
                console.warn(
                  `Collection '${name}' predates hybrid search (no '${BM25_VECTOR_NAME}' sparse slot). ` +
                    "BM25 keyword scoring is disabled for this collection; semantic search works normally. " +
                    "Use a fresh collection to enable hybrid keyword search.",
                );

View on GitHub (pinned to 001c235229)

Solutions

  1. Align the store's dimension with the existing collection (fix embeddingModelDims/config to match what the collection reports)
  2. Or delete and recreate the collection with the new dimension: qdrant PUT /collections/<name> after DELETE, then re-ingest memories
  3. If switching embedding models permanently, re-embed all stored memories into a fresh collection — vectors from different models are not comparable
  4. Use a new collection name per embedding model (e.g. memories_768) to avoid collisions

Example fix

// before (collection exists with size 1536)
const vs = new Qdrant({ collectionName: 'memories', embeddingModelDims: 768 });

// after: use a separate collection per dimension
const vs = new Qdrant({ collectionName: 'memories_768', embeddingModelDims: 768 });
Defensive patterns

Strategy: validation

Validate before calling

import { QdrantClient } from '@qdrant/js-client-rest';
async function assertCollectionDims(url: string, name: string, expected: number): Promise<void> {
  const client = new QdrantClient({ url });
  const info = await client.getCollection(name);
  const size = (info.config?.params?.vectors as any)?.size;
  if (size && size !== expected) {
    throw new Error(`Dimension mismatch: collection=${size}, app=${expected}`);
  }
}
await assertCollectionDims(qdrantUrl, 'memories', 768);

Type guard

const dimsMatch = (a?: number, b?: number): boolean => a === undefined || b === undefined || a === b;

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/7a17b019f0c4e094. Report an issue: GitHub.