[PR #28876] chore(docker): update nltk data download process to include unstructured download_nltk_packages #32219

Closed
opened 2026-02-21 20:50:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28876

State: closed
Merged: Yes


add unstructured download_nltk_packages, Fix the issue https://github.com/langgenius/dify/issues/28902.

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

When using the document extractor, unstructured nltk files are automatically downloaded to the /home/dify/nltk_data/ directory.

dify@dify-api-7b8d54658f-cxnfr:/app/api$ ls -al /home/dify/nltk_data/tokenizers/
total 4236
drwxr-xr-x  3 dify dify    4096 Nov 28 02:39 .
drwxr-xr-x  4 dify dify    4096 Nov 28 02:38 ..
drwxr-xr-x 21 dify dify    4096 Nov 28 02:39 punkt_tab
-rw-r--r--  1 dify dify 4319076 Nov 28 02:39 punkt_tab.zip
dify@dify-api-7b8d54658f-cxnfr:/app/api$ ls -al /home/dify/nltk_data/t
taggers/    tokenizers/
dify@dify-api-7b8d54658f-cxnfr:/app/api$ ls -al /home/dify/nltk_data/taggers/
total 1516
drwxr-xr-x 3 dify dify    4096 Nov 28 02:38 .
drwxr-xr-x 4 dify dify    4096 Nov 28 02:38 ..
drwxr-xr-x 2 dify dify    4096 Nov 28 02:38 averaged_perceptron_tagger_eng
-rw-r--r-- 1 dify dify 1539115 Nov 28 02:38 averaged_perceptron_tagger_eng.zip

https://github.com/Unstructured-IO/unstructured/blob/91a9888d35b645988529e99b539eee9b7ffd30e3/unstructured/nlp/tokenize.py#L29

download_nltk_packages The downloaded packages do not match those specified in the Dockerfile, causing documents to be downloaded again during extraction. Use the download_nltk_packages method to download directly.

After modifying the Dockerfile to download in advance, unstructured will not download again.

dify@dify-api-6df5fdfb57-btp9k:/app/api$ ls -al /usr/local/share/nltk_data/taggers/
total 3988
drwxr-xr-x 4 root root    4096 Nov 28 06:26 .
drwxr-xr-x 5 root root    4096 Nov 28 06:26 ..
drwxr-xr-x 2 root root    4096 Nov 28 06:26 averaged_perceptron_tagger
-rwxr-xr-x 1 root root 2526731 Nov 28 06:26 averaged_perceptron_tagger.zip
drwxr-xr-x 2 root root    4096 Nov 28 06:26 averaged_perceptron_tagger_eng
-rwxr-xr-x 1 root root 1539115 Nov 28 06:26 averaged_perceptron_tagger_eng.zip
dify@dify-api-6df5fdfb57-btp9k:/app/api$ ls -al /usr/local/share/nltk_data/tokenizers/
total 17816
drwxr-xr-x  4 root root     4096 Nov 28 06:26 .
drwxr-xr-x  5 root root     4096 Nov 28 06:26 ..
drwxr-xr-x  3 root root     4096 Nov 28 06:26 punkt
-rwxr-xr-x  1 root root 13905355 Nov 28 06:26 punkt.zip
drwxr-xr-x 21 root root     4096 Nov 28 06:26 punkt_tab
-rwxr-xr-x  1 root root  4319076 Nov 28 06:26 punkt_tab.zip

Screenshots

Before After
NLTK_DATA=/usr/local/share/nltk_data python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger'); nltk.download('stopwords')" && NLTK_DATA=/usr/local/share/nltk_data python -c "import nltk; from unstructured.nlp.tokenize import download_nltk_packages; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger'); nltk.download('stopwords'); download_nltk_packages()"

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/28876 **State:** closed **Merged:** Yes --- add unstructured download_nltk_packages, Fix the issue https://github.com/langgenius/dify/issues/28902. > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary When using the document extractor, unstructured nltk files are automatically downloaded to the `/home/dify/nltk_data/` directory. ``` dify@dify-api-7b8d54658f-cxnfr:/app/api$ ls -al /home/dify/nltk_data/tokenizers/ total 4236 drwxr-xr-x 3 dify dify 4096 Nov 28 02:39 . drwxr-xr-x 4 dify dify 4096 Nov 28 02:38 .. drwxr-xr-x 21 dify dify 4096 Nov 28 02:39 punkt_tab -rw-r--r-- 1 dify dify 4319076 Nov 28 02:39 punkt_tab.zip dify@dify-api-7b8d54658f-cxnfr:/app/api$ ls -al /home/dify/nltk_data/t taggers/ tokenizers/ dify@dify-api-7b8d54658f-cxnfr:/app/api$ ls -al /home/dify/nltk_data/taggers/ total 1516 drwxr-xr-x 3 dify dify 4096 Nov 28 02:38 . drwxr-xr-x 4 dify dify 4096 Nov 28 02:38 .. drwxr-xr-x 2 dify dify 4096 Nov 28 02:38 averaged_perceptron_tagger_eng -rw-r--r-- 1 dify dify 1539115 Nov 28 02:38 averaged_perceptron_tagger_eng.zip ``` https://github.com/Unstructured-IO/unstructured/blob/91a9888d35b645988529e99b539eee9b7ffd30e3/unstructured/nlp/tokenize.py#L29 `download_nltk_packages` The downloaded packages do not match those specified in the Dockerfile, causing documents to be downloaded again during extraction. Use the `download_nltk_packages` method to download directly. After modifying the Dockerfile to download in advance, unstructured will not download again. ```bash dify@dify-api-6df5fdfb57-btp9k:/app/api$ ls -al /usr/local/share/nltk_data/taggers/ total 3988 drwxr-xr-x 4 root root 4096 Nov 28 06:26 . drwxr-xr-x 5 root root 4096 Nov 28 06:26 .. drwxr-xr-x 2 root root 4096 Nov 28 06:26 averaged_perceptron_tagger -rwxr-xr-x 1 root root 2526731 Nov 28 06:26 averaged_perceptron_tagger.zip drwxr-xr-x 2 root root 4096 Nov 28 06:26 averaged_perceptron_tagger_eng -rwxr-xr-x 1 root root 1539115 Nov 28 06:26 averaged_perceptron_tagger_eng.zip dify@dify-api-6df5fdfb57-btp9k:/app/api$ ls -al /usr/local/share/nltk_data/tokenizers/ total 17816 drwxr-xr-x 4 root root 4096 Nov 28 06:26 . drwxr-xr-x 5 root root 4096 Nov 28 06:26 .. drwxr-xr-x 3 root root 4096 Nov 28 06:26 punkt -rwxr-xr-x 1 root root 13905355 Nov 28 06:26 punkt.zip drwxr-xr-x 21 root root 4096 Nov 28 06:26 punkt_tab -rwxr-xr-x 1 root root 4319076 Nov 28 06:26 punkt_tab.zip ``` ## Screenshots | Before | After | |--------|-------| | `NLTK_DATA=/usr/local/share/nltk_data python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger'); nltk.download('stopwords')"` | ` && NLTK_DATA=/usr/local/share/nltk_data python -c "import nltk; from unstructured.nlp.tokenize import download_nltk_packages; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger'); nltk.download('stopwords'); download_nltk_packages()" ` | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:50:59 -05:00
yindo closed this issue 2026-02-21 20:50:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32219