{"record":{"id":"f54f6894369aaed6","repo":"pathwaycom/pathway","slug":"leann-connector-requires-the-leann-package-plea","errorCode":null,"errorMessage":"LEANN connector requires the `leann` package. Please visit https://github.com/yichuan-w/LEANN and follow the installation instructions there.","messagePattern":"LEANN connector requires the `leann` package\\. Please visit https://github\\.com/yichuan-w/LEANN and follow the installation instructions there\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/leann/__init__.py","lineNumber":91,"sourceCode":"            self._dirty = True\n        else:\n            if self.documents.pop(key, None) is not None:\n                self._dirty = True\n\n    def on_time_end(self, time: int) -> None:\n        if self._dirty:\n            self._build_index()\n            self._dirty = False\n\n    def on_end(self) -> None:\n        if self._dirty or not self.index_path.exists():\n            self._build_index()\n\n    def _build_index(self) -> None:\n        try:\n            from leann import LeannBuilder\n        except ImportError as e:\n            raise ImportError(_LEANN_INSTALL_ERROR_MESSAGE) from e\n\n        if not self.documents:\n            logger.warning(\"No documents to index - skipping index build\")\n            return\n\n        builder_kwargs: dict[str, Any] = {\"backend_name\": self.backend_name}\n        if self.embedding_mode:\n            builder_kwargs[\"embedding_mode\"] = self.embedding_mode\n        if self.embedding_model:\n            builder_kwargs[\"embedding_model\"] = self.embedding_model\n        if self.embedding_options:\n            builder_kwargs[\"embedding_options\"] = self.embedding_options\n\n        builder = LeannBuilder(**builder_kwargs)\n        for doc in self.documents.values():\n            builder.add_text(**doc)\n\n        # Ensure parent directory exists","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/leann/__init__.py#L73-L109","documentation":"The LEANN sink builds a vector index at the end of the pipeline, which requires the third-party `leann` Python package. When the import inside _build_index() fails, Pathway re-raises a helpful ImportError pointing at the LEANN project's install instructions. The error surfaces lazily — at index build time (on_flush/on_end), not at write() call time.","triggerScenarios":"Calling pw.io.leann.write(...) in an environment where `import leann` fails; because _build_index runs in an observer callback, the pipeline may run for a while before the ImportError appears.","commonSituations":"Missing optional dependency (leann is not bundled with pathway); partially installed leann without its native backend; CI image that installs pathway but not the extra.","solutions":["Install the leann package following https://github.com/yichuan-w/LEANN instructions (e.g. pip install leann)","Verify with `python -c \"import leann\"` before running the pipeline","Prefer the eager check by relying on pw.io.leann.write's own _check_leann_available() — call pw.io.leann.write early so the ImportError triggers at graph-build time rather than mid-run"],"exampleFix":"# before: pipeline fails at index build\npw.io.leann.write(table, \"idx\", table.text)\n\n# after: fail fast in setup\nimport leann  # ImportError surfaces immediately if missing\npw.io.leann.write(table, \"idx\", table.text)","handlingStrategy":"validation","validationCode":"try:\n    import leann  # noqa\nexcept ImportError:\n    raise SystemExit(\"Install leann first: see https://github.com/yichuan-w/LEANN\")","typeGuard":null,"tryCatchPattern":"try:\n    pw.io.leann.write(table, \"idx\", table.text)\nexcept ImportError as e:\n    print(\"Missing dependency:\", e)\n    raise","preventionTips":["Declare leann in your project's dependency list so environments always have it","Import leann at application startup to surface missing installs immediately","Pin a leann version to avoid breaking upstream API changes"],"tags":["leann","pathway","import","optional-dependency","installation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}