{"record":{"id":"45b1c33bfbe6b866","repo":"crewAIInc/crewAI","slug":"client-is-not-initialized","errorCode":null,"errorMessage":"Client is not initialized","messagePattern":"Client is not initialized","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/adapters/crewai_rag_adapter.py","lineNumber":95,"sourceCode":"    ) -> str:\n        \"\"\"Query the knowledge base with a question.\n\n        Args:\n            question: The question to ask\n            similarity_threshold: Minimum similarity score for results (default: 0.6)\n            limit: Maximum number of results to return (default: 5)\n\n        Returns:\n            Relevant content from the knowledge base\n        \"\"\"\n        search_limit = limit if limit is not None else self.limit\n        search_threshold = (\n            similarity_threshold\n            if similarity_threshold is not None\n            else self.similarity_threshold\n        )\n        if self._client is None:\n            raise ValueError(\"Client is not initialized\")\n\n        results: list[SearchResult] = self._client.search(\n            collection_name=self.collection_name,\n            query=question,\n            limit=search_limit,\n            score_threshold=search_threshold,\n        )\n\n        if not results:\n            return \"No relevant content found.\"\n\n        contents: list[str] = []\n        for result in results:\n            content: str = result.get(\"content\", \"\")\n            if content:\n                contents.append(content)\n\n        return \"\\n\\n\".join(contents)","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/adapters/crewai_rag_adapter.py#L77-L113","documentation":"ValueError raised in CrewAIRagAdapter.query/search: the adapter holds no knowledge-storage client (self._client is None), so the search cannot run. The client is normally attached when the adapter is wired into the underlying storage/tool; calling query before that wiring (or on a detached adapter) triggers this.","triggerScenarios":"Instantiating CrewAIRagAdapter directly and calling its query/retrieve method without connecting it to a knowledge client, or reusing an adapter after its client was closed/reset.","commonSituations":"Using the adapter standalone in tests; calling search before initialize/connect; copying example code that assumes a framework-managed lifecycle.","solutions":["Use the adapter through the owning tool/service so the framework injects the client instead of calling it bare.","Ensure any connect/initialize step completes before the first query.","Guard calls with a client check (see validation below) and fail with a clear message at the call site."],"exampleFix":"# before\nadapter = CrewAIRagAdapter(...)\nanswer = adapter.query(\"what is crewai?\")  # ValueError: Client is not initialized\n\n# after\nif adapter._client is None:\n    raise RuntimeError(\"connect the RAG adapter before querying\")\nanswer = adapter.query(\"what is crewai?\")","handlingStrategy":"type-guard","validationCode":"if adapter._client is None:\n    raise RuntimeError(\"RAG adapter has no client; run its connect/initialize step first\")","typeGuard":"def rag_adapter_ready(adapter: CrewAIRagAdapter) -> bool:\n    return getattr(adapter, \"_client\", None) is not None","tryCatchPattern":"try:\n    answer = adapter.query(q)\nexcept ValueError as e:\n    if \"Client is not initialized\" in str(e):\n        raise RuntimeError(\"connect adapter before querying\") from e\n    raise","preventionTips":["Always initialize/connect the adapter before first query.","Prefer framework-managed construction over manual instantiation.","Add a startup readiness check for the adapter's client."],"tags":["rag","adapter","initialization","client","crewai-tools"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}