{"record":{"id":"f367166a5b95ecde","repo":"FoundationAgents/MetaGPT","slug":"to-use-rag-please-set-your-embedding-in-config2-y","errorCode":null,"errorMessage":"To use RAG, please set your embedding in config2.yaml.","messagePattern":"To use RAG, please set your embedding in config2\\.yaml\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"metagpt/rag/factories/embedding.py","lineNumber":50,"sourceCode":"        self.config = config if config else Config.default()\n\n    def get_rag_embedding(self, key: EmbeddingType = None) -> BaseEmbedding:\n        \"\"\"Key is EmbeddingType.\"\"\"\n        return super().get_instance(key or self._resolve_embedding_type())\n\n    def _resolve_embedding_type(self) -> EmbeddingType | LLMType:\n        \"\"\"Resolves the embedding type.\n\n        If the embedding type is not specified, for backward compatibility, it checks if the LLM API type is either OPENAI or AZURE.\n        Raise TypeError if embedding type not found.\n        \"\"\"\n        if self.config.embedding.api_type:\n            return self.config.embedding.api_type\n\n        if self.config.llm.api_type in [LLMType.OPENAI, LLMType.AZURE]:\n            return self.config.llm.api_type\n\n        raise TypeError(\"To use RAG, please set your embedding in config2.yaml.\")\n\n    def _create_openai(self) -> \"OpenAIEmbedding\":\n        from llama_index.embeddings.openai import OpenAIEmbedding\n\n        params = dict(\n            api_key=self.config.embedding.api_key or self.config.llm.api_key,\n            api_base=self.config.embedding.base_url or self.config.llm.base_url,\n        )\n\n        self._try_set_model_and_batch_size(params)\n\n        return OpenAIEmbedding(**params)\n\n    def _create_azure(self) -> AzureOpenAIEmbedding:\n        params = dict(\n            api_key=self.config.embedding.api_key or self.config.llm.api_key,\n            azure_endpoint=self.config.embedding.base_url or self.config.llm.base_url,\n            api_version=self.config.embedding.api_version or self.config.llm.api_version,","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/rag/factories/embedding.py#L32-L68","documentation":"RAGEmbedding._resolve_embedding_type needs to know which embedding backend to build. It first checks config.embedding.api_type; if unset it falls back to the LLM api_type but only when that is OPENAI or AZURE (backward compatibility). Any other LLM backend with no explicit embedding config raises TypeError telling you to set embedding in config2.yaml.","triggerScenarios":"Using RAG with api_type like 'qianfan', 'zhipuai', 'gemini', or a local LLM while the embedding: section of config2.yaml is absent or has no api_type; from_input/from_objs then tries to build the default embedding and this raises.","commonSituations":"Switching the project's LLM to a non-OpenAI provider and assuming embeddings follow, fresh config2.yaml missing the embedding block, or embedding.api_key present but api_type omitted.","solutions":["Add an embedding section to config2.yaml, e.g. embedding: {api_type: openai, api_key: ..., base_url: ...}.","Point embedding at a provider that matches your stack (AzureOpenAIEmbedding config, or a local embedding via the supported api types).","If your LLM is already OpenAI/Azure, ensure llm.api_type is exactly OPENAI/AZURE so the fallback applies.","Alternatively pass an explicit embed_model to SimpleEngine to bypass config resolution."],"exampleFix":"# before (config2.yaml)\nllm:\n  api_type: zhipuai\n  api_key: ...\n# no embedding section -> TypeError on RAG usage\n\n# after\nembedding:\n  api_type: openai\n  api_key: \"sk-...\"\n  base_url: \"https://api.openai.com/v1\"","handlingStrategy":"validation","validationCode":"from metagpt.const import LLMType\n\ndef embedding_resolvable(config) -> bool:\n    if config.embedding and config.embedding.api_type:\n        return True\n    return config.llm.api_type in (LLMType.OPENAI, LLMType.AZURE)\n\nassert embedding_resolvable(config), \"set embedding.api_type in config2.yaml before using RAG\"","typeGuard":null,"tryCatchPattern":"try:\n    engine = SimpleEngine.from_input(input_dir='./data')\nexcept TypeError as e:\n    if \"embedding in config2.yaml\" in str(e):\n        raise SystemExit(\"Add an embedding: {api_type: openai, api_key: ...} section to config2.yaml\") from e\n    raise","preventionTips":["Always define the embedding block when using RAG with non-OpenAI LLMs","Pass an explicit embed_model to SimpleEngine to bypass config resolution","Add a startup check that embedding.api_type is set when RAG features are enabled"],"tags":["rag","embedding","configuration","migration"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}