BoxLoader and BoxBlobLoader
The langchain-box
package provides two methods to index your files from Box: BoxLoader
and BoxBlobLoader
. BoxLoader
allows you to ingest text representations of files that have a text representation in Box. The BoxBlobLoader
allows you download the blob for any document or image file for processing with the blob parser of your choice.
This notebook details getting started with both of these. For detailed documentation of all BoxLoader features and configurations head to the API Reference pages for BoxLoader and BoxBlobLoader.
Overview
The BoxLoader
class helps you get your unstructured content from Box in Langchain's Document
format. You can do this with either a List[str]
containing Box file IDs, or with a str
containing a Box folder ID.
The BoxBlobLoader
class helps you get your unstructured content from Box in Langchain's Blob
format. You can do this with a List[str]
containing Box file IDs, a str
containing a Box folder ID, a search query, or a BoxMetadataQuery
.
If getting files from a folder with folder ID, you can also set a Bool
to tell the loader to get all sub-folders in that folder, as well.
A Box instance can contain Petabytes of files, and folders can contain millions of files. Be intentional when choosing what folders you choose to index. And we recommend never getting all files from folder 0 recursively. Folder ID 0 is your root folder.
The BoxLoader
will skip files without a text representation, while the BoxBlobLoader
will return blobs for all document and image files.
Integration details
Class | Package | Local | Serializable | JS support |
---|---|---|---|---|
BoxLoader | langchain_box | ✅ | ❌ | ❌ |
BoxBlobLoader | langchain_box | ✅ | ❌ | ❌ |
Loader features
Source | Document Lazy Loading | Async Support |
---|---|---|
BoxLoader | ✅ | ❌ |
BoxBlobLoader | ✅ | ❌ |
Setup
In order to use the Box package, you will need a few things:
- A Box account — If you are not a current Box customer or want to test outside of your production Box instance, you can use a free developer account.
- A Box app — This is configured in the developer console, and for Box AI, must have the
Manage AI
scope enabled. Here you will also select your authentication method - The app must be enabled by the administrator. For free developer accounts, this is whomever signed up for the account.
Credentials
For these examples, we will use token authentication. This can be used with any authentication method. Just get the token with whatever methodology. If you want to learn more about how to use other authentication types with langchain-box
, visit the Box provider document.
import getpass
import os
box_developer_token = getpass.getpass("Enter your Box Developer Token: ")
Enter your Box Developer Token: ········
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"
Installation
Install langchain_box.
%pip install -qU langchain_box
Initialization
Load files
If you wish to load files, you must provide the List
of file ids at instantiation time.
This requires 1 piece of information:
- box_file_ids (
List[str]
)- A list of Box file IDs.
BoxLoader
from langchain_box.document_loaders import BoxLoader
box_file_ids = ["1514555423624", "1514553902288"]
loader = BoxLoader(
box_developer_token=box_developer_token,
box_file_ids=box_file_ids,
character_limit=10000, # Optional. Defaults to no limit
)
BoxBlobLoader
from langchain_box.blob_loaders import BoxBlobLoader
box_file_ids = ["1514555423624", "1514553902288"]
loader = BoxBlobLoader(
box_developer_token=box_developer_token, box_file_ids=box_file_ids
)
Load from folder
If you wish to load files from a folder, you must provide a str
with the Box folder ID at instantiation time.
This requires 1 piece of information:
- box_folder_id (
str
)- A string containing a Box folder ID.