{"record":{"id":"aaaf4fe9e4ab0053","repo":"agentscope-ai/agentscope","slug":"f-agentscopeembedding-model-must-be-an-embedding","errorCode":null,"errorMessage":"f\"AgentScopeEmbedding `model` must be an EmbeddingModelBase, got {type(self.config.model).__name__}.\"","messagePattern":"f\"AgentScopeEmbedding `model` must be an EmbeddingModelBase, got (.+?)\\.\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py","lineNumber":251,"sourceCode":"    ``EmbeddingModelBase``.\"\"\"\n\n    def __init__(\n        self,\n        config: BaseEmbedderConfig | dict | None = None,\n    ) -> None:\n        # mem0's EmbeddingBase (unlike LLMBase) does NOT auto-convert\n        # dict configs — it stores whatever is passed. Normalize here\n        # so callers can use the same dict-config style as the LLM.\n        if isinstance(config, dict):\n            config = BaseEmbedderConfig(**config)\n        super().__init__(config)\n        if self.config.model is None:\n            raise ValueError(\n                \"AgentScopeEmbedding requires `model` in the config \"\n                \"to be an AgentScope EmbeddingModelBase instance.\",\n            )\n        if not isinstance(self.config.model, EmbeddingModelBase):\n            raise TypeError(\n                f\"AgentScopeEmbedding `model` must be an \"\n                f\"EmbeddingModelBase, got \"\n                f\"{type(self.config.model).__name__}.\",\n            )\n        self._agentscope_model: EmbeddingModelBase = self.config.model\n        self._bridge = _AsyncBridge()\n\n    # ----- EmbeddingBase interface -----\n    # pylint: disable=unused-argument\n    def embed(\n        self,\n        text: str | list[str],\n        memory_action: str | None = None,  # mem0 contract — unused\n    ) -> list[float]:\n        \"\"\"mem0 ``EmbeddingBase`` entry — runs the AgentScope embedding\n        model synchronously and returns the first vector.\"\"\"\n        text_list = [text] if isinstance(text, str) else list(text)\n        response = self._bridge.run(self._agentscope_model(text_list))","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py#L233-L269","documentation":"The embedding adapter type-checks config.model; anything that is not an AgentScope EmbeddingModelBase (string model name, raw OpenAI client, sentence-transformers model) raises this TypeError with the actual type name.","triggerScenarios":"AgentScopeEmbedding({'model': 'text-embedding-3-small'}) or passing a SentenceTransformer/HuggingFace object as model.","commonSituations":"Assuming mem0's string-based embedder config style carries over; mixing HuggingFace locals with the AgentScope adapter.","solutions":["Wrap the provider with an AgentScope embedding class and pass the instance","Verify the import came from agentscope.model, not the provider SDK","Delegate construction to build_mem0_config(embedding_model=...)"],"exampleFix":"// before\nAgentScopeEmbedding({'model': 'text-embedding-3-small'})\n// after\nfrom agentscope.model import OpenAIEmbedding\nAgentScopeEmbedding({'model': OpenAIEmbedding(model='text-embedding-3-small')})","handlingStrategy":"type-guard","validationCode":"from agentscope.model import EmbeddingModelBase\nif not isinstance(config.get('model'), EmbeddingModelBase):\n    raise TypeError('model must be an EmbeddingModelBase instance')","typeGuard":"from agentscope.model import EmbeddingModelBase\ndef is_embedding_model_base(m) -> bool:\n    return isinstance(m, EmbeddingModelBase)","tryCatchPattern":"try:\n    emb = AgentScopeEmbedding(cfg)\nexcept TypeError as e:\n    raise SystemExit(f'Bad embedder config: {e}') from e","preventionTips":["Wrap embedders in agentscope.model classes before passing them as config.model"],"tags":["agentscope","mem0","embedding","type-error"],"backgroundTag":"wrong-type-config-value","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}