mem0ai/mem0 · error · ValueError
Either a client or URL and token must be provided.
Error message
Either a client or URL and token must be provided.
What it means
Raised in UpstashVector.__init__ when the constructor gets neither an injected `client` nor both `url` and `token`. The branching is strict: only `url and token` together form a valid Index; passing just one of them (or neither) lands in the else. Unlike some stores there is no environment-variable fallback in this module — credentials must come from config or an injected client.
Source
Thrown at mem0/vector_stores/upstash_vector.py:64
token: Optional[str] = None,
client: Optional[Index] = None,
enable_embeddings: bool = False,
):
"""
Initialize the UpstashVector vector store.
Args:
url (str, optional): URL for Upstash Vector index. Defaults to None.
token (int, optional): Token for Upstash Vector index. Defaults to None.
client (Index, optional): Existing `upstash_vector.Index` client instance. Defaults to None.
namespace (str, optional): Default namespace for the index. Defaults to None.
"""
if client:
self.client = client
elif url and token:
self.client = Index(url, token)
else:
raise ValueError("Either a client or URL and token must be provided.")
self.collection_name = collection_name
self.enable_embeddings = enable_embeddings
def insert(
self,
vectors: List[list],
payloads: Optional[List[Dict]] = None,
ids: Optional[List[str]] = None,
):
"""
Insert vectors
Args:
vectors (list): List of vectors to insert.
payloads (list, optional): List of payloads corresponding to vectors. These will be passed as metadatas to the Upstash Vector client. Defaults to None.
ids (list, optional): List of IDs corresponding to vectors. Defaults to None.View on GitHub (pinned to 001c235229)
Solutions
- Supply both credentials in the vector store config: `"config": {"url": ..., "token": ..., "collection_name": "mem"}`.
- Or build the client yourself and pass `client=Index(url, token)`.
- If using env vars, wire them explicitly: `"url": os.environ["UPSTASH_VECTOR_REST_URL"]`.
Example fix
# before
memory = Memory.from_config({
"vector_store": {"provider": "upstash_vector", "config": {"collection_name": "mem"}}
}) # ValueError
# after
import os
memory = Memory.from_config({
"vector_store": {
"provider": "upstash_vector",
"config": {
"collection_name": "mem",
"url": os.environ["UPSTASH_VECTOR_REST_URL"],
"token": os.environ["UPSTASH_VECTOR_REST_TOKEN"],
},
}
}) Defensive patterns
Strategy: validation
Validate before calling
import os
def upstash_config() -> dict:
url = os.environ.get("UPSTASH_VECTOR_REST_URL")
token = os.environ.get("UPSTASH_VECTOR_REST_TOKEN")
if not (url and token):
raise SystemExit("Upstash Vector requires both UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN")
return {"provider": "upstash_vector", "config": {"url": url, "token": token, "collection_name": "mem"}} Try / catch
try:
store = UpstashVector(collection_name="mem", url=url, token=token)
except ValueError as e:
if "client or URL and token" in str(e):
raise RuntimeError("Upstash credentials incomplete: need both url and token") from e
raise Prevention
- Provide url and token as a pair in config, or inject a pre-built Index client.
- Do not assume env-var fallbacks exist for this store — wire credentials explicitly.
- Validate credential presence in a boot-time preflight for every configured provider.
When it happens
Trigger: `UpstashVector(collection_name="mem")` with no url/token/client; config with `"token": ...` but a missing or misnamed `"url"` key; passing url but relying on an env var for the token that this class never reads.
Common situations: Assuming UPSTASH_VECTOR_REST_URL/TOKEN env vars are picked up automatically (the hosted platform does that, this OSS store may not, depending on config wiring); typos in config keys; partially redacted config templates.
Related errors
- Either a client or URL and token must be provided.
- When embeddings are enabled, all payloads must contain a 'da
- Failed to parse googleServiceAccountJson: ${err.message}
- Vertex AI could not determine a Google Cloud project ID. Set
- Unsupported vector store provider: ${provider}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/98106e3938cf7a5f.
Report an issue: GitHub.