{"record":{"id":"cddc88956af4f18d","repo":"FoundationAgents/MetaGPT","slug":"to-use-the-similarity-search-you-need-to-install","errorCode":null,"errorMessage":"To use the similarity search, you need to install the RAG module.","messagePattern":"To use the similarity search, you need to install the RAG module\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"metagpt/tools/libs/editor.py","lineNumber":1132,"sourceCode":"            query (str): The search query string to look for in the indexed files.\n            path (Union[str, Path]): A pathname or filename to search within.\n\n        Returns:\n            List[str]: A list of results as strings, containing the text from the merged results\n                        and any direct results from non-indexed files.\n\n        Example:\n            >>> query = \"The problem to be analyzed from the document\"\n            >>> file_or_path = \"The pathname or filename you want to search within\"\n            >>> texts: List[str] = await Editor.similarity_search(query=query, path=file_or_path)\n            >>> print(texts)\n        \"\"\"\n        try:\n            from metagpt.tools.libs.index_repo import IndexRepo\n\n            return await IndexRepo.cross_repo_search(query=query, file_or_path=path)\n        except ImportError:\n            raise ImportError(\"To use the similarity search, you need to install the RAG module.\")\n\n    @staticmethod\n    def is_large_file(content: str, mix_token_count: int = 0) -> bool:\n        encoding = tiktoken.get_encoding(\"cl100k_base\")\n        token_count = len(encoding.encode(content))\n        mix_token_count = mix_token_count or DEFAULT_MIN_TOKEN_COUNT\n        return token_count >= mix_token_count\n","sourceCodeStart":1114,"sourceCodeEnd":1140,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/tools/libs/editor.py#L1114-L1140","documentation":"Raised by Editor.similarity_search when importing metagpt.tools.libs.index_repo fails, meaning the optional RAG dependencies (the llama-index based RAG module) are not installed. similarity_search delegates to IndexRepo.cross_repo_search, which requires the rag extra; the bare ImportError is re-raised with a clearer message.","triggerScenarios":"Awaiting Editor.similarity_search(query=..., path=...) in an environment where MetaGPT was installed without the rag extra, so `from metagpt.tools.libs.index_repo import IndexRepo` raises ImportError.","commonSituations":"pip install metagpt (core only) then calling similarity search; a deployment image trimmed of optional deps; local editable install without extras.","solutions":["Install the RAG extra: pip install -e.[rag] (or pip install metagpt[rag])","Verify with: python -c \"from metagpt.tools.libs.index_repo import IndexRepo\"","If you cannot install extras, use search_file/find_file (string search) instead of similarity search"],"exampleFix":"# before: ImportError raised at call time\nawait Editor.similarity_search(query=q, path=p)\n# after\ntexts = await Editor.similarity_search(query=q, path=p)  # after: pip install -e.[rag]","handlingStrategy":"fallback","validationCode":"try:\n    from metagpt.tools.libs.index_repo import IndexRepo  # noqa: F401\n    has_rag = True\nexcept ImportError:\n    has_rag = False","typeGuard":null,"tryCatchPattern":"try:\n    texts = await Editor.similarity_search(query=q, path=p)\nexcept ImportError:\n    texts = []  # fall back to editor.search_file(p) string search","preventionTips":["Install optional extras up front if you plan to use similarity search","Probe importability once at startup instead of failing mid-run","Keep a string-search fallback path for environments without RAG deps"],"tags":["optional-dependency","rag","import-error","editor"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}