{"record":{"id":"11067c8d0c816c20","repo":"MemPalace/mempalace","slug":"where-document-operator-key-r-not-supported-11067c","errorCode":null,"errorMessage":"where_document operator {key!r} not supported","messagePattern":"where_document operator (.+?) not supported","errorType":"validation","errorClass":"UnsupportedFilterError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/sqlite_exact.py","lineNumber":231,"sourceCode":"def _matches_where_document(document: str, where_document: Optional[dict]) -> bool:\n    if not where_document:\n        return True\n    if not isinstance(where_document, dict):\n        return False\n    for key, value in where_document.items():\n        if key == \"$contains\":\n            if str(value) not in document:\n                return False\n            continue\n        if key == \"$and\":\n            if not all(_matches_where_document(document, clause) for clause in value or []):\n                return False\n            continue\n        if key == \"$or\":\n            if not any(_matches_where_document(document, clause) for clause in value or []):\n                return False\n            continue\n        raise UnsupportedFilterError(f\"where_document operator {key!r} not supported\")\n    return True\n\n\ndef _validate_write_batch(\n    *,\n    documents: list[str],\n    ids: list[str],\n    metadatas: Optional[list[dict]],\n    embeddings: Optional[list[list[float]]],\n) -> None:\n    n = len(ids)\n    if len(documents) != n:\n        raise ValueError(f\"documents length {len(documents)} does not match ids length {n}\")\n    if metadatas is not None and len(metadatas) != n:\n        raise ValueError(f\"metadatas length {len(metadatas)} does not match ids length {n}\")\n    if embeddings is not None and len(embeddings) != n:\n        raise ValueError(f\"embeddings length {len(embeddings)} does not match ids length {n}\")\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/sqlite_exact.py#L213-L249","documentation":"Raised by sqlite_exact when a `where_document` filter uses an operator other than the supported `$contains`, `$and`, and `$or`. `where_document` matches the stored verbatim document text, and this backend only implements substring containment plus the two logical combinators. Any other `$`-prefixed key is rejected outright rather than guessed at.","triggerScenarios":"Calling get/query/delete with `where_document={\"$regex\": \"...\"}`, `{\"$eq\": \"...\"}`, `{\"$not\": {\"$contains\": \"...\"}}`, or any operator outside {$contains, $and, $or}. Nested clauses inherit the same restriction.","commonSituations":"Porting ChromaDB `where_document` filters that use `$regex` or `$eq`; assuming full Mongo document-operator support; filters generated by an LLM or template that invents operator names.","solutions":["Rewrite the filter using only `$contains` under `$and`/`$or`, e.g. multiple `$contains` clauses under `$and` approximate an AND-of-substrings.","For regex or negation, fetch with a `$contains` pre-filter (or none) and apply the regex in Python on the returned documents.","If you require `$regex`, switch to the ChromaDB backend which supports richer where_document operators."],"exampleFix":"# before\ncol.get(where_document={\"$regex\": \"palace.*room\"})\n\n# after\nrows = col.get(where_document={\"$contains\": \"palace\"})\nresult = [r for r in rows[\"documents\"] if re.search(r\"palace.*room\", r)]","handlingStrategy":"validation","validationCode":"SUPPORTED_WD = {\"$contains\", \"$and\", \"$or\"}\n\ndef validate_where_document(wd: dict) -> None:\n    for key in wd:\n        if key not in SUPPORTED_WD:\n            raise ValueError(f\"where_document operator {key!r} unsupported; only $contains/$and/$or\")","typeGuard":"def is_supported_where_document(wd: dict) -> bool:\n    return all(k in {\"$contains\", \"$and\", \"$or\"} for k in wd)","tryCatchPattern":"try:\n    col.get(where_document=wd)\nexcept UnsupportedFilterError:\n    text = wd.get(\"$regex\") or next(iter(wd.values()), None)\n    rows = col.get()\n    results = [r for r in rows[\"documents\"] if re.search(pattern, r)]","preventionTips":["Treat where_document as substring-only ($contains) by contract in your codebase.","Do regex matching in Python on returned documents, not in the filter.","Lint for $regex in where_document when targeting sqlite_exact."],"tags":["sqlite-exact","where-document","filter","full-text"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}