Skip to content

fix(ivr): reimplement TfidfLoopDetector with numpy to remove scikit-learn dependency - #6867

Open
Mugunth007 wants to merge 1 commit into
livekit:mainfrom
Mugunth007:fix/issue-6778-tfidf-loop-detector
Open

fix(ivr): reimplement TfidfLoopDetector with numpy to remove scikit-learn dependency#6867
Mugunth007 wants to merge 1 commit into
livekit:mainfrom
Mugunth007:fix/issue-6778-tfidf-loop-detector

Conversation

@Mugunth007

@Mugunth007 Mugunth007 commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #6778.

Summary

TfidfLoopDetector previously relied on scikit-learn, which was not declared as a dependency or extra in pyproject.toml. On standard installations without scikit-learn, check_loop_detection() silently returned False and disabled loop detection.

Changes

  • Replaced sklearn.feature_extraction.text.TfidfVectorizer and sklearn.metrics.pairwise.cosine_similarity with a pure numpy implementation.
  • Matched TfidfVectorizer defaults (token_pattern=r"(?u)\b\w\w+\b", smooth IDF formula ln((1 + N) / (1 + df)) + 1, and L2 normalization).
  • Added test_tfidf_loop_detector_without_sklearn in tests/test_ivr_activity.py to ensure loop detection works independent of scikit-learn.

Testing

  • uv run pytest tests/test_ivr_activity.py (6/6 passed)
  • uv run ruff check & uv run ruff format passed

…earn dependency

Fixes livekit#6778. Replaces sklearn TfidfVectorizer and cosine_similarity with a pure numpy TF-IDF calculation. This resolves silent loop detection failures on installations where scikit-learn is not installed.
@Mugunth007
Mugunth007 requested a review from a team as a code owner August 15, 2026 06:22

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IVR loop detection silently disabled: TfidfLoopDetector requires undeclared scikit-learn dependency

1 participant