graphify icon indicating copy to clipboard operation
graphify copied to clipboard

feat: add --label-language flag and GRAPHIFY_LABEL_LANGUAGE env var for LLM community labels

Open poorvith-mp opened this issue 4 months ago • 0 comments

Fixes #1824

Problem

The prompt in _label_batch_with_retry (llm.py) was a hardcoded English string with no language directive. Since the LLM inferred output language ambientlyfrom sampled node labels, the same community could be named in English in one relabel pass and in the team's natural language in another. This made diffing labels across reclusters noisy and forced manual normalization for non-English teams.

Solution

Added an explicit language instruction to the labeling prompt, controllable via:

  • --label-language flag on both graphify label and graphify cluster-only
  • GRAPHIFY_LABEL_LANGUAGE environment variable as a fallback

When neither is set, behavior is identical to before (no language directive in the prompt), so this is fully backward compatible.

Changes

graphify/llm.py

  • Added label_language: str | None = None parameter to _label_batch_with_retry, label_communities, and generate_community_labels
  • Injected _lang_clause into the labeling prompt when a language is specified, e.g. " Respond in Portuguese."
  • Reads GRAPHIFY_LABEL_LANGUAGE env var as fallback when no explicit value is passed
  • Threaded label_language through recursive retry calls so it is not lost on batch splits

graphify/cli.py

  • Added --label-language argument parsing (supports both --label-language Portuguese and --label-language=Portuguese forms) to the shared cluster-only / label handler
  • Passed label_language through to generate_community_labels

Usage

# CLI flag
graphify label --label-language Portuguese
graphify cluster-only . --label-language Japanese

# Environment variable
GRAPHIFY_LABEL_LANGUAGE=French graphify label

Backward Compatibility

No breaking changes. When --label-language is not set and GRAPHIFY_LABEL_LANGUAGE is unset, the prompt is identical to before.

poorvith-mp avatar Jul 13 '26 09:07 poorvith-mp