{"record":{"id":"9abe6861e769994d","repo":"agentscope-ai/agentscope","slug":"agentscope-embedding-model-returned-no-embeddings","errorCode":null,"errorMessage":"\"AgentScope embedding model returned no embeddings.\"","messagePattern":"\"AgentScope embedding model returned no embeddings\\.\"","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py","lineNumber":271,"sourceCode":"                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))\n        if not response.embeddings:\n            raise RuntimeError(\n                \"AgentScope embedding model returned no embeddings.\",\n            )\n        # AgentScope EmbeddingResponse.embeddings is List[List[float]];\n        # mem0 expects a single vector for a single-text call.\n        return response.embeddings[0]\n\n\n# ----------------------------------------------------------------------\n# Build a mem0 MemoryConfig wired to AgentScope models\n# ----------------------------------------------------------------------\n\n# The provider name we register under in mem0's factory + config layer.\n_AGENTSCOPE_PROVIDER = \"agentscope\"\n\n\ndef build_mem0_config(\n    *,\n    chat_model: ChatModelBase | None = None,","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py#L253-L289","documentation":"embed() calls the AgentScope embedding model and expects a non-empty embeddings list in the response. If the model returns an EmbeddingResponse with empty embeddings, there is no vector to return and a RuntimeError is raised.","triggerScenarios":"A misbehaving or mocked embedding model returning EmbeddingResponse(embeddings=[]) or embedding=False; provider returning an empty body.","commonSituations":"Mocked models in tests that forget to populate embeddings; provider errors that still parse into a response object.","solutions":["Test the embedding model directly to verify it returns vectors","Fix mocks to include at least one vector","Check provider API key/quota and input text validity"],"exampleFix":"// before\nmock_model.return_value = EmbeddingResponse(embeddings=[])\n// after\nmock_model.return_value = EmbeddingResponse(embeddings=[[0.1, 0.2, 0.3]])","handlingStrategy":"validation","validationCode":"resp = await embedding_model(['ping'])\nif not resp.embeddings:\n    raise RuntimeError('embedding model returned no vectors — check provider/key')","typeGuard":null,"tryCatchPattern":"try:\n    vec = emb.embed('text')\nexcept RuntimeError as e:\n    if 'no embeddings' in str(e):\n        vec = retry_with_backoff(lambda: emb.embed('text'))\n    else:\n        raise","preventionTips":["Health-check the embedding model once at startup with a single-string call","Populate embeddings in all test mocks"],"tags":["agentscope","mem0","embedding","empty-response"],"backgroundTag":"empty-api-response-body","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}