Skip to content

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

Merged
crazywoola merged 6 commits intolanggenius:mainfrom
lework:add_unstructured_nltk_data
Jan 5, 2026
Merged

chore(docker): update nltk data download process to include unstructured download_nltk_packages#28876
crazywoola merged 6 commits intolanggenius:mainfrom
lework:add_unstructured_nltk_data

Conversation

@lework
Copy link
Contributor

@lework lework commented Nov 28, 2025

add unstructured download_nltk_packages, Fix the issue #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
@lework lework requested a review from QuantumGhost as a code owner November 28, 2025 08:10
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Nov 28, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lework, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request optimizes the NLTK data download process within the Docker build for the API service. Previously, the unstructured library would trigger additional NLTK data downloads at runtime during document extraction, causing inefficiencies. By incorporating the download_nltk_packages function from unstructured.nlp.tokenize directly into the Dockerfile, all required NLTK data is now pre-downloaded during image creation, preventing redundant downloads and streamlining the document extraction workflow.

Highlights

  • NLTK Data Download Optimization: Integrated the unstructured.nlp.tokenize.download_nltk_packages function directly into the Dockerfile build process to ensure all necessary NLTK data is pre-downloaded.
  • Runtime Efficiency Improvement: Eliminated redundant NLTK data downloads that previously occurred during document extraction when using the unstructured library, leading to more efficient operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Dockerfile to pre-download NLTK packages required by the unstructured library. This is a good optimization to prevent downloads at runtime. The change correctly uses the download_nltk_packages function from unstructured. My review includes a suggestion to simplify the command by removing redundant package download calls, which will improve the clarity and maintainability of the Dockerfile.

@crazywoola
Copy link
Member

Please create an issue and link it in the description.

@lework
Copy link
Contributor Author

lework commented Nov 28, 2025

Please create an issue and link it in the description.

Added.

@crazywoola crazywoola requested a review from laipz8200 November 29, 2025 10:47
@lework
Copy link
Contributor Author

lework commented Dec 8, 2025

@laipz8200 @QuantumGhost Please review.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 24, 2025
@crazywoola crazywoola merged commit 34f3b28 into langgenius:main Jan 5, 2026
15 checks passed
@zhaobingshuang
Copy link
Contributor

@crazywoola This PR also resolves issue #30092

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

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

5 participants