{"record":{"id":"a41b5ed02c4dccf1","repo":"MemPalace/mempalace","slug":"operator-key-r-not-supported-by-milvus","errorCode":null,"errorMessage":"operator {key!r} not supported by milvus","messagePattern":"operator (.+?) not supported by milvus","errorType":"exception","errorClass":"UnsupportedFilterError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/milvus.py","lineNumber":162,"sourceCode":"def _translate_clause(clause: dict) -> str:\n    if not isinstance(clause, dict):\n        raise UnsupportedFilterError(f\"where clause must be a dict, got {type(clause).__name__}\")\n    if not clause:\n        return \"\"\n    parts = []\n    for key, value in clause.items():\n        if key == \"$and\":\n            if not isinstance(value, list) or not value:\n                raise UnsupportedFilterError(\"$and requires a non-empty list of clauses\")\n            nested = [_translate_clause(item) for item in value]\n            parts.append(\"(\" + \" and \".join(part for part in nested if part) + \")\")\n        elif key == \"$or\":\n            if not isinstance(value, list) or not value:\n                raise UnsupportedFilterError(\"$or requires a non-empty list of clauses\")\n            nested = [_translate_clause(item) for item in value]\n            parts.append(\"(\" + \" or \".join(part for part in nested if part) + \")\")\n        elif key.startswith(\"$\"):\n            raise UnsupportedFilterError(f\"operator {key!r} not supported by milvus\")\n        else:\n            parts.append(_translate_field(key, value))\n    return \" and \".join(part for part in parts if part)\n\n\ndef translate_where(where: Optional[dict]) -> str:\n    \"\"\"Translate the portable metadata where DSL into a Milvus filter string.\"\"\"\n    if not where:\n        return \"\"\n    return _translate_clause(where)\n\n\ndef translate_where_document(where_document: Optional[dict]) -> str:\n    \"\"\"Translate the portable document filter subset into a Milvus filter.\"\"\"\n    if not where_document:\n        return \"\"\n    if not isinstance(where_document, dict):\n        raise UnsupportedFilterError(\"where_document must be a dict\")","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/milvus.py#L144-L180","documentation":"Raised in _translate_clause() when a where-clause key starts with '$' but is neither '$and' nor '$or'. At the clause level only those two logical operators exist; all $-prefixed field names or misplaced operators ($in, $contains at top level, $nor, etc.) hit this branch and raise UnsupportedFilterError. This guards against typos and against putting field-level operators at the wrong nesting depth.","triggerScenarios":"where={\"$in\": [...]}, where={\"$not\": {...}}, or a metadata field literally named \"$price\" used as a clause key. Distinct from error 24, which fires for unknown operators nested inside a field's condition dict.","commonSituations":"Misplaced operators after refactoring filter-building code; Mongo $nor/$not habits; metadata keys that begin with a dollar sign.","solutions":["Move operators inside a field dict: {\"wing\": {\"$in\": [...]}} not {\"$in\": [...]}","Rename metadata keys that start with '$' — _field_name would reject them anyway","Rewrite $not via $ne/$nin on the field"],"exampleFix":"// before\nwhere = {\"$in\": [\"a\", \"b\"]}\n\n// after\nwhere = {\"wing\": {\"$in\": [\"a\", \"b\"]}}","handlingStrategy":"validation","validationCode":"CLAUSE_LEVEL_OPS = {\"$and\", \"$or\"}\n\ndef no_misplaced_operators(where: dict) -> bool:\n    return all(k in CLAUSE_LEVEL_OPS or not k.startswith(\"$\") for k in where)","typeGuard":null,"tryCatchPattern":"from mempalace.backends.base import UnsupportedFilterError\ntry:\n    collection.query(query_texts=[q], where=where, n_results=k)\nexcept UnsupportedFilterError as e:\n    if \"not supported by milvus\" in str(e):\n        raise ValueError(f\"move operator {e} inside a field's condition dict\") from e\n    raise","preventionTips":["Operators like $in/$contains belong inside a field dict, not at clause level","Never name metadata fields with a leading '$'","Lift shared filter-shape checks into unit tests"],"tags":["milvus","filter","unsupported-operator","clause-level"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}