Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions redisvl/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,14 @@ def _set_stopwords(self, stopwords: Optional[Union[str, Set[str]]] = "english"):
self._stopwords = set()
elif isinstance(stopwords, str):
try:
nltk.download("stopwords", quiet=True)
self._stopwords = set(nltk_stopwords.words(stopwords))
# Try loading first; only download if not already present.
# This avoids race conditions when parallel workers (e.g.
# pytest-xdist) call nltk.download() concurrently.
try:
self._stopwords = set(nltk_stopwords.words(stopwords))
except LookupError:
nltk.download("stopwords", quiet=True)
self._stopwords = set(nltk_stopwords.words(stopwords))
except ImportError:
raise ValueError(
f"Loading stopwords for {stopwords} failed: nltk is not installed."
Expand Down
10 changes: 8 additions & 2 deletions redisvl/utils/full_text_query_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ def _get_stopwords(
return set()
elif isinstance(stopwords, str):
try:
nltk.download("stopwords", quiet=True)
return set(nltk_stopwords.words(stopwords))
# Try loading first; only download if not already present.
# This avoids race conditions when parallel workers (e.g.
# pytest-xdist) call nltk.download() concurrently.
try:
return set(nltk_stopwords.words(stopwords))
except LookupError:
nltk.download("stopwords", quiet=True)
return set(nltk_stopwords.words(stopwords))
except ImportError:
raise ValueError(
f"Loading stopwords for {stopwords} failed: nltk is not installed."
Expand Down