Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unstructured, community, initialize langchain-unstructured package #22779

Merged
merged 115 commits into from
Jul 24, 2024

Conversation

Coniferish
Copy link
Contributor

@Coniferish Coniferish commented Jun 11, 2024

Update (2):

A single UnstructuredLoader is added to handle both local and api partitioning. This loader also handles single or multiple documents.

Changes in community:

Changes here do not affect users. In the initial process of using the SDK for the API Loaders, the Loaders in community were refactored.
Other changes include:
The UnstructuredBaseLoader has a new check to see if both mode="paged" and chunking_strategy="by_page". It also now has Element.element_id added to the Document.metadata. UnstructuredAPIFileLoader and UnstructuredAPIFileIOLoader. As such, now both directly inherit from UnstructuredBaseLoader and initialize their file_path/file attributes respectively and implement their own _post_process_elements methods.


Update:

New SDK Loaders in a partner package are introduced to prevent breaking changes for users (see discussion below).

TODO:
  • Test docstring examples

  • Description: UnstructuredAPIFileIOLoader and UnstructuredAPIFileLoader calls to the unstructured api are now made using the unstructured-client sdk.

  • New Dependencies: unstructured-client

  • Add tests and docs: If you're adding a new integration, please include

    • a test for the integration, preferably unit tests that do not rely on network access,
    • update the description in docs/docs/integrations/providers/unstructured.mdx
  • Lint and test: Run make format, make lint and make test from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:

  • Make sure optional dependencies are imported within a function.
  • Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests.
  • Most PRs should not touch more than one package.
  • Changes should be backwards compatible.
  • If you are adding something to community, do not re-import it in langchain.

TODO:

  • Update https://python.langchain.com/v0.1/docs/integrations/document_loaders/unstructured_file/#unstructured-api
    • langchain/docs/docs/integrations/document_loaders/unstructured_file.ipynb
    • The description here needs to indicate that users should install unstructured-client instead of unstructured. Read over closely to look for any other changes that need to be made.
  • Update the lazy_load method in UnstructuredBaseLoader to handle json responses from the API instead of just lists of elements.
    • This method may need to be overwritten by the API loaders instead of changing it in the UnstructuredBaseLoader.
  • Update the documentation links in the class docstrings (the Unstructured documents have moved)
  • Update Document.metadata to include element_id (see thread here)

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 11, 2024
Copy link

vercel bot commented Jun 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2024 11:18pm

@dosubot dosubot bot added Ɑ: doc loader Related to document loader module (not documentation) 🤖:improvement Medium size change to existing code to handle new use-cases labels Jun 11, 2024
@Coniferish Coniferish marked this pull request as draft June 11, 2024 15:22
Previously, the API Loaders inherited from their respective File/FileIO loaders (which both interhited from the Base Loader). This was problematic for switching from having 'unstructured' as a dependency to 'unstructured-client' because the Base Loader checked if 'unstructured' was installed. Now the 'unstructured'/'unstructured-client' check happens in the get_elements_from_api function and the other Loaders are responsible for checking the packages they depend on. With the API loaders inheriting directly from the Base Loader now, they also now initialize their 'file'/'file_path' attributes and call the super.__init__() method of the Base Loader directly.
Refactor calls to get_elements_from_api so that Loaders handle single or multiple files. Change metadata_filename variable name in tests/unstructured_kwargs. Import elements_from_json. Etc.
…again and update _get_elements method.

Also add test for UnstructuredFileIOLoader
Also, remove API Loaders dependency on unstructured and add comments.
… classes

Also, change type hints for List/list, Dict/dict, etc. and improve docstrings
zc277584121 and others added 2 commits July 24, 2024 16:45
add dynamic field feature to langchain_milvus
more unittest, more robustic

plan to deprecate the `metadata_field` in the future, because it's
function is the same as `enable_dynamic_field`, but the latter one is a
more advanced concept in milvus

Signed-off-by: ChengZi <chen.zhang@zilliz.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
- **cli: remove snapshot flag from pytest defaults**
- **x**
- **x**
@efriis efriis changed the title community: Update unstructured API loaders to use sdk: unstructured, community, initialize langchain-unstructured package Jul 24, 2024
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Jul 24, 2024
@efriis efriis enabled auto-merge (squash) July 24, 2024 22:59
@efriis efriis merged commit d59c656 into langchain-ai:master Jul 24, 2024
53 checks passed
olgamurraft pushed a commit to olgamurraft/langchain that referenced this pull request Aug 16, 2024
…angchain-ai#22779)

#### Update (2): 
A single `UnstructuredLoader` is added to handle both local and api
partitioning. This loader also handles single or multiple documents.

#### Changes in `community`:
Changes here do not affect users. In the initial process of using the
SDK for the API Loaders, the Loaders in community were refactored.
Other changes include:
The `UnstructuredBaseLoader` has a new check to see if both
`mode="paged"` and `chunking_strategy="by_page"`. It also now has
`Element.element_id` added to the `Document.metadata`.
`UnstructuredAPIFileLoader` and `UnstructuredAPIFileIOLoader`. As such,
now both directly inherit from `UnstructuredBaseLoader` and initialize
their `file_path`/`file` attributes respectively and implement their own
`_post_process_elements` methods.

--------
#### Update:
New SDK Loaders in a [partner
package](https://python.langchain.com/v0.1/docs/contributing/integrations/#partner-package-in-langchain-repo)
are introduced to prevent breaking changes for users (see discussion
below).

##### TODO:
- [x] Test docstring examples
--------
- **Description:** UnstructuredAPIFileIOLoader and
UnstructuredAPIFileLoader calls to the unstructured api are now made
using the unstructured-client sdk.
- **New Dependencies:** unstructured-client

- [x] **Add tests and docs**: If you're adding a new integration, please
include
- [x] a test for the integration, preferably unit tests that do not rely
on network access,
- [x] update the description in
`docs/docs/integrations/providers/unstructured.mdx`
- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

TODO:
- [x] Update
https://python.langchain.com/v0.1/docs/integrations/document_loaders/unstructured_file/#unstructured-api
-
`langchain/docs/docs/integrations/document_loaders/unstructured_file.ipynb`
- The description here needs to indicate that users should install
`unstructured-client` instead of `unstructured`. Read over closely to
look for any other changes that need to be made.
- [x] Update the `lazy_load` method in `UnstructuredBaseLoader` to
handle json responses from the API instead of just lists of elements.
- This method may need to be overwritten by the API loaders instead of
changing it in the `UnstructuredBaseLoader`.
- [x] Update the documentation links in the class docstrings (the
Unstructured documents have moved)
- [x] Update Document.metadata to include `element_id` (see thread
[here](https://unstructuredw-kbe4326.slack.com/archives/C044N0YV08G/p1718187499818419))

---------

Signed-off-by: ChengZi <chen.zhang@zilliz.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
Co-authored-by: Isaac Francisco <78627776+isahers1@users.noreply.github.com>
Co-authored-by: ChengZi <chen.zhang@zilliz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community Ɑ: doc loader Related to document loader module (not documentation) 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder 🤖:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features 🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. partner size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants