Skip to content

Commit

Permalink
community[patch]: Skip nested directories when using S3DirectoryLoader (
Browse files Browse the repository at this point in the history
langchain-ai#17829)

- **Description:** `S3DirectoryLoader` is failing if prefix is a folder
(ex: `my_folder/`) because `S3FileLoader` will try to load that folder
and will fail. This PR skip nested directories so prefix can be set to
folder instead of `my_folder/files_prefix`.
- **Issue:**
  - langchain-ai#11917
  - langchain-ai#6535
  - langchain-ai#4326
- **Dependencies:** none
- **Twitter handle:** @Falydoor


- [x] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [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/
  • Loading branch information
Falydoor authored and gkorland committed Mar 30, 2024
1 parent eba8982 commit c1682a9
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def load(self) -> List[Document]:
bucket = s3.Bucket(self.bucket)
docs = []
for obj in bucket.objects.filter(Prefix=self.prefix):
# Skip directories
if obj.size == 0 and obj.key.endswith("/"):
continue
loader = S3FileLoader(
self.bucket,
obj.key,
Expand Down

0 comments on commit c1682a9

Please sign in to comment.