mem0ai/mem0 · critical · Error
PGVector requires either connectionString or ${missingFields
Error message
PGVector requires either connectionString or ${missingFields.join(", ")} What it means
PgVector accepts either a connectionString or discrete connection fields. If no usable connection string is found and any of user, password, host, port is missing/empty, the constructor throws this error listing the missing fields. It fails fast before any network call is attempted.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/pgvector.ts:186
hnsw?: boolean;
}
function getConnectionString(config: PGVectorConfig): string | undefined {
return config.connectionString?.trim() || undefined;
}
function validateConnectionConfig(config: PGVectorConfig): void {
if (getConnectionString(config)) {
return;
}
const missingFields = ["user", "password", "host", "port"].filter((field) => {
const v = config[field as keyof PGVectorConfig];
return v === undefined || v === null || v === "";
});
if (missingFields.length > 0) {
throw new Error(
`PGVector requires either connectionString or ${missingFields.join(", ")}`,
);
}
}
function buildClientConfig(
config: PGVectorConfig,
database?: string,
): ClientConfig {
const connectionString = getConnectionString(config);
if (connectionString) {
return {
connectionString,
...(config.ssl !== undefined ? { ssl: config.ssl } : {}),
};
}
return {View on GitHub (pinned to 001c235229)
Solutions
- Provide a full connection string: new PgVector({ connectionInfo: 'postgres://user:pass@host:5432/db', ... })
- Or supply all discrete fields: user, password, host, port (and optionally database)
- Check that the env vars feeding the config are actually set in the runtime environment (docker-compose env, k8s secrets, dotenv loaded)
- Verify none of the values are empty strings — empty counts as missing
Example fix
// before
const vs = new PgVector({ host: 'db', port: 5432, database: 'mem0' });
// after
const vs = new PgVector({
user: 'mem0',
password: process.env.PGPASSWORD,
host: 'db',
port: 5432,
database: 'mem0',
}); Defensive patterns
Strategy: validation
Validate before calling
function validatePgConfig(c: any): void {
const cs = c?.connectionString ?? c?.connectionInfo;
if (cs && String(cs).trim() !== '') return;
const missing = ['user','password','host','port'].filter(f => !c?.[f]);
if (missing.length) throw new Error(`PG config missing: ${missing.join(', ')}`);
}
validatePgConfig(pgConfig); Type guard
const hasPgCredentials = (c: any): boolean => !!(c?.connectionString ?? c?.connectionInfo) || ['user','password','host','port'].every(f => !!c?.[f]);
Try / catch
try { const vs = new PgVector(pgConfig); } catch (e) { if (e instanceof Error && e.message.includes('PGVector requires')) { /* fail deployment config check, do not retry */ } throw e; } Prevention
- Prefer a single CONNECTION STRING env var over four discrete ones
- Fail fast at app boot: assert required env vars exist before constructing stores
- Include PG config in a smoke test that constructs the store in CI
When it happens
Trigger: Constructing PgVector with only { host, port, database } (no user/password and no connectionString), passing an empty-string connectionString, or reading config from env vars that are undefined (e.g. process.env.PGHOST set but PGUSER/PGPASSWORD unset when building the discrete config).
Common situations: Switching from a connection URL to individual env vars in Docker/Kubernetes and forgetting one; a .env file not loaded so PG* vars are undefined; trailing whitespace or empty strings in config; deploying with a partially templated secret.
Related errors
- Invalid ${label} '${name}': only letters, digits, and unders
- Pinecone API key required: pass apiKey or set PINECONE_API_K
- Together API key is required
- Failed to parse googleServiceAccountJson: ${err.message}
- Vertex AI could not determine a Google Cloud project ID. Set
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/6d5028eee6fbbec6.
Report an issue: GitHub.