{"record":{"id":"ef821d5cc8499679","repo":"mem0ai/mem0","slug":"vector-operations-failed-please-ensure-1-the-ve","errorCode":null,"errorMessage":"Vector operations failed. Please ensure:\n1. The vector extension is enabled\n2. The table \"${this.tableName}\" exists with correct schema\n3. The match_vectors function is created\n4. Row Level Security policies allow the configured Supabase key to read the table\n\nRUN THE FOLLOWING SQL IN YOUR SUPABASE SQL EDITOR:\n\n-- Enable the vector extension\ncreate extension if not exists vector;\n\n-- Create the memories table\ncreate table if not exists memories (\n  id text primary key,\n  embedding vector(1536),\n  metadata jsonb,\n  created_at timestamp with time zone default timezone('utc', now()),\n  updated_at timestamp with time zone default timezone('utc', now())\n);\n\n-- Create the memory migrations table\ncreate table if not exists memory_migrations (\n  user_id text primary key,\n  created_at timestamp with time zone default timezone('utc', now())\n);\n\n-- Create the vector similarity search function\ncreate or replace function match_vectors(\n  query_embedding vector(1536),\n  match_count int,\n  filter jsonb default '{}'::jsonb\n)\nreturns table (\n  id text,\n  similarity float,\n  metadata jsonb\n)\nlanguage plpgsql\nas $$\nbegin\n  return query\n  select\n    t.id::text,\n    1 - (t.embedding <=> query_embedding) as similarity,\n    t.metadata\n  from memories t\n  where case\n    when filter::text = '{}'::text then true\n    else t.metadata @> filter\n  end\n  order by t.embedding <=> query_embedding\n  limit match_count;\nend;\n$$;\n\nSee the SQL migration instructions in the code comments.","messagePattern":"Vector operations failed\\. Please ensure:\n1\\. The vector extension is enabled\n2\\. The table \"\\$\\{this\\.tableName\\}\" exists with correct schema\n3\\. The match_vectors function is created\n4\\. Row Level Security policies allow the configured Supabase key to read the table\n\nRUN THE FOLLOWING SQL IN YOUR SUPABASE SQL EDITOR:\n\n-- Enable the vector extension\ncreate extension if not exists vector;\n\n-- Create the memories table\ncreate table if not exists memories \\(\n  id text primary key,\n  embedding vector\\(1536\\),\n  metadata jsonb,\n  created_at timestamp with time zone default timezone\\('utc', now\\(\\)\\),\n  updated_at timestamp with time zone default timezone\\('utc', now\\(\\)\\)\n\\);\n\n-- Create the memory migrations table\ncreate table if not exists memory_migrations \\(\n  user_id text primary key,\n  created_at timestamp with time zone default timezone\\('utc', now\\(\\)\\)\n\\);\n\n-- Create the vector similarity search function\ncreate or replace function match_vectors\\(\n  query_embedding vector\\(1536\\),\n  match_count int,\n  filter jsonb default '\\{\\}'::jsonb\n\\)\nreturns table \\(\n  id text,\n  similarity float,\n  metadata jsonb\n\\)\nlanguage plpgsql\nas \\$\\$\nbegin\n  return query\n  select\n    t\\.id::text,\n    1 - \\(t\\.embedding <=> query_embedding\\) as similarity,\n    t\\.metadata\n  from memories t\n  where case\n    when filter::text = '\\{\\}'::text then true\n    else t\\.metadata @> filter\n  end\n  order by t\\.embedding <=> query_embedding\n  limit match_count;\nend;\n\\$\\$;\n\nSee the SQL migration instructions in the code comments\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/vector_stores/supabase.ts","lineNumber":135,"sourceCode":"\n  async initialize(): Promise<void> {\n    if (!this._initPromise) {\n      this._initPromise = this._doInitialize();\n    }\n    return this._initPromise;\n  }\n\n  private async _doInitialize(): Promise<void> {\n    await this.ensureClient();\n    try {\n      const { error: probeError } = await this.client\n        .from(this.tableName)\n        .select(this.embeddingColumnName)\n        .limit(1);\n\n      if (probeError) {\n        console.error(\"Table probe error:\", probeError);\n        throw new Error(\n          `Vector operations failed. Please ensure:\n1. The vector extension is enabled\n2. The table \"${this.tableName}\" exists with correct schema\n3. The match_vectors function is created\n4. Row Level Security policies allow the configured Supabase key to read the table\n\nRUN THE FOLLOWING SQL IN YOUR SUPABASE SQL EDITOR:\n\n-- Enable the vector extension\ncreate extension if not exists vector;\n\n-- Create the memories table\ncreate table if not exists memories (\n  id text primary key,\n  embedding vector(1536),\n  metadata jsonb,\n  created_at timestamp with time zone default timezone('utc', now()),\n  updated_at timestamp with time zone default timezone('utc', now())","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/supabase.ts#L117-L153","documentation":"During initialization, the Supabase vector store probes the configured table with a one-row select on the embedding column. If Supabase returns an error (missing table, missing vector extension, RLS blocking the key, wrong column), the store throws this aggregate error with ready-to-run SQL that creates the memories table, memory_migrations table, and match_vectors similarity function. It is a setup/diagnostic error, not a transient failure.","triggerScenarios":"First use of the Supabase vector store against a fresh Supabase project where the vector extension, memories table, or match_vectors function does not exist; using an anon key whose RLS policies deny SELECT on the table; renaming tableName or embeddingColumnName in config to values that don't exist in the schema.","commonSituations":"New Supabase project without migrations applied; using service-role vs anon key with restrictive RLS; config.tableName pointing at a custom table that was never created; pgvector extension disabled on the project.","solutions":["Open the Supabase SQL editor and run the exact SQL block embedded in the error message (extension, tables, match_vectors function).","Verify the API key has access: either use the service_role key or add RLS SELECT policies for the authenticated/anon role on the table.","Check config.tableName and the embedding column name match your actual schema (default 'memories' / 'embedding', vector(1536)).","Adjust the vector(1536) literal in the SQL if your embedding model outputs a different dimension, then recreate."],"exampleFix":"-- run in Supabase SQL editor (from the error message)\ncreate extension if not exists vector;\ncreate table if not exists memories (\n  id text primary key,\n  embedding vector(1536),\n  metadata jsonb,\n  created_at timestamptz default timezone('utc', now()),\n  updated_at timestamptz default timezone('utc', now())\n);\n-- plus memory_migrations table and match_vectors function from the error text","handlingStrategy":"validation","validationCode":"// pre-flight: verify table probe succeeds before creating Memory\nconst { createClient } = await import('@supabase/supabase-js');\nconst sb = createClient(url, key);\nconst { error } = await sb.from('memories').select('embedding').limit(1);\nif (error) throw new Error(`Supabase not ready — run the setup SQL first: ${error.message}`);","typeGuard":null,"tryCatchPattern":"try { const memory = new Memory({ vectorStore: { provider: 'supabase', config } }); } catch (e) { if (e instanceof Error && e.message.includes('RUN THE FOLLOWING SQL')) { await runMigrations(); /* then retry construction */ } else throw e; }","preventionTips":["Apply the SQL migration as part of environment provisioning (IaC/migrations pipeline)","Use the service_role key or add RLS SELECT policies","Keep tableName and vector dimension in config aligned with the schema"],"tags":["supabase","pgvector","setup","sql","rls"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}