{"record":{"id":"fc50d37b8e321d36","repo":"MemPalace/mempalace","slug":"where-document-operator-key-r-not-supported-fc50d3","errorCode":null,"errorMessage":"where_document operator {key!r} not supported","messagePattern":"where_document operator (.+?) not supported","errorType":"exception","errorClass":"UnsupportedFilterError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/qdrant.py","lineNumber":216,"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":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/qdrant.py#L198-L234","documentation":"where_document filters on the qdrant backend support only $contains plus $and/$or composition over such clauses. _matches_where_document raises UnsupportedFilterError for any other operator (e.g. $regex, $eq on documents), refusing to guess rather than silently mis-filtering content.","triggerScenarios":"Calling query(where_document={\"$regex\": \"note-.*\"}) or get(where_document={\"$eq\": \"exact text\"}) on a qdrant collection.","commonSituations":"Porting ChromaDB filters that use $regex on documents; UI search features offering regex over content.","solutions":["Use {\"$contains\": \"substring\"} for content matching.","Combine multiple $contains clauses with $and/$or when you need OR semantics.","For regex needs, fetch broader results and apply re.search in your own code."],"exampleFix":"# before\ncol.query(query_embeddings=[vec], where_document={\"$regex\": \"note-\"})\n\n# after\ncol.query(query_embeddings=[vec], where_document={\"$contains\": \"note-\"})","handlingStrategy":"validation","validationCode":"def validate_where_document(wd):\n    def walk(node):\n        for k, v in (node or {}).items():\n            if k not in {\"$contains\", \"$and\", \"$or\"}:\n                raise ValueError(f\"where_document operator {k} unsupported; use $contains\")\n            if isinstance(v, (list, dict)):\n                for child in (v if isinstance(v, list) else [v]):\n                    if isinstance(child, dict): walk(child)\n    walk(wd)\n    return wd","typeGuard":"def is_supported_where_document(wd: dict) -> bool:\n    return all(k in {\"$contains\", \"$and\", \"$or\"} for k in (wd or {}))","tryCatchPattern":"try:\n    col.query(query_embeddings=vecs, where_document=wd)\nexcept UnsupportedFilterError:\n    # fall back to substring matching client-side\n    wd = {\"$contains\": extract_substring(wd)}","preventionTips":["Use $contains for all content filtering on qdrant.","Apply regex in your own code after retrieval, not in where_document."],"tags":["qdrant","where-document","filters","unsupported-operation"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}