Skip to content

Commit

Permalink
Make graspologic optional
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem committed Aug 20, 2024
1 parent 2af4c81 commit 289ccfb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 192 deletions.
2 changes: 1 addition & 1 deletion go/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module r2r-cli

go 1.23.0

replace github.com/yourusername/r2r_go_sdk => ../r2r_go_sdk
replace github.com/yourusername/r2r_go_sdk => ../sdk

require (
github.com/spf13/cobra v1.8.1
Expand Down
181 changes: 0 additions & 181 deletions go/cli/rag_operations.go

This file was deleted.

22 changes: 13 additions & 9 deletions py/core/pipes/kg/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
RunLoggingSingleton,
Triple,
)
from graspologic.partition import hierarchical_leiden

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,15 +69,20 @@ def _compute_leiden_communities(
seed: int = 0xDEADBEEF,
) -> dict[int, dict[str, int]]:
"""Compute Leiden communities."""
community_mapping = hierarchical_leiden(
graph, max_cluster_size=self.max_cluster_size, random_seed=seed
)
results: dict[int, dict[str, int]] = {}
for partition in community_mapping:
results[partition.level] = results.get(partition.level, {})
results[partition.level][partition.node] = partition.cluster
try:
from graspologic.partition import hierarchical_leiden

return results
community_mapping = hierarchical_leiden(
graph, max_cluster_size=self.max_cluster_size, random_seed=seed
)
results: dict[int, dict[str, int]] = {}
for partition in community_mapping:
results[partition.level] = results.get(partition.level, {})
results[partition.level][partition.node] = partition.cluster

return results
except ImportError as e:
raise ImportError("Please install the graspologic package.") from e

async def cluster_kg(self, triples: list[Triple]) -> list[Community]:
"""
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ core = [
"uvicorn", "aiosqlite", "asyncpg", "redis", "beautifulsoup4", "openpyxl",
"markdown", "pypdf", "python-pptx", "python-docx", "vecs", "litellm", "openai",
"fsspec", "posthog", "sqlalchemy", "ollama", "neo4j", "passlib", "bcrypt",
"pyjwt", "toml", "pyyaml", "poppler-utils", "psutil", "deepdiff", "graspologic"
"pyjwt", "toml", "pyyaml", "poppler-utils", "psutil", "deepdiff",
]
ingest-movies = ["opencv-python", "moviepy"]
kgs = ["graspologic"]
all = ["core", "ingest-movies"]

[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 289ccfb

Please sign in to comment.