Tool

Integrate Box with LlamaIndex for RAG

LlamaIndex readers that bring Box.com files, text, and Box AI extraction into RAG pipelines.

Works with box

79
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Empower your LLM applications by seamlessly integrating Box.com documents into LlamaIndex for advanced Retrieval Augmented Generation (RAG) and data querying.

Outcomes

What it gets done

01

Read files directly from Box.com

02

Extract text using Box's native text representation

03

Leverage Box AI for advanced text and structured data extraction (E+ customers)

04

Index Box content for efficient RAG queries

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-box | bash

Overview

LlamaIndex: Box Readers

The Box Readers bring Box.com content into LlamaIndex through four readers -- plain file reading, text extraction, and two Box AI-powered readers for context prompting and structured-data extraction (E+ plan required) -- authenticated via CCG, JWT, OAuth 2.0, or a developer token. Use it when you need Box.com files, or AI-extracted content from them, loaded into LlamaIndex for RAG. The two Box AI readers require an E+ Box plan; the plain readers do not.

What it does

This integration brings Box.com's capabilities to LlamaIndex for RAG and other LLM applications. It provides four readers: Box Reader (implements the SimpleReader interface to read files from Box), Box Text Extraction (uses Box's text representation to extract text from a document), Box AI Prompt (uses Box AI to extract context from documents), and Box AI Extraction (uses Box AI to extract structured data from documents). Box AI features are limited to Box's Enterprise Plus (E+) customers.

When to use - and when NOT to

Use it when you need to read files from Box into LlamaIndex documents, optionally using Box AI to extract context or structured data from them for RAG pipelines. The Box AI readers specifically require an E+ Box plan, so those two readers are not usable on lower-tier Box accounts -- the plain Box Reader and Text Extraction reader have no such restriction.

Inputs and outputs

Install with:

pip install llama-index-readers-box

To work with any Box reader you first need a BoxClient, authenticated via one of four methods: Client Credential Grant (CCG), JSON Web Tokens (JWT), OAuth 2.0, or a developer token -- CCG and JWT are the two walked through in setup detail. For CCG, set BOX_CLIENT_ID, BOX_CLIENT_SECRET, BOX_ENTERPRISE_ID, and optionally BOX_USER_ID in a .env file, then:

from box_sdk_gen import CCGConfig, BoxCCGAuth, BoxClient

config = CCGConfig(
    client_id="your_client_id",
    client_secret="your_client_secret",
    enterprise_id="your_enterprise_id",
    user_id="your_ccg_user_id",  # Optional
)
auth = BoxCCGAuth(config)
if config.user_id:
    auth.with_user_subject(config.user_id)
client = BoxClient(auth)

reader = BoxReader(box_client=client)

The CCG snippet above builds a CCGConfig from the client ID, client secret, and enterprise ID, wraps it in a BoxCCGAuth, and -- if a user_id was supplied -- calls auth.with_user_subject(config.user_id) before constructing the BoxClient and passing it to BoxReader(box_client=client); that with_user_subject call is what switches the client from the default service account over to acting as a specific user.

For JWT, set BOX_ENTERPRISE_ID, BOX_USER_ID, and JWT_CONFIG_PATH (pointing to a .config.json from the Box Developer Console), and install the extra dependency box-sdk-gen[jwt]. By default both CCG and JWT use a service account, which may not have access to every file depending on how they are shared -- specifying a different user_id requires the application to be able to impersonate or generate tokens for that user.

Who it's for

Developers building RAG or other LLM applications on Box.com content, who need either straightforward file access or Box AI-powered context or structured-data extraction on an E+ plan.

Source README

LlamaIndex: Box Readers

This open-source integration brings the capabilities of Box.com to the LLama-Index, empowering developers building Retrieval Augmented Generation (RAG) and other LLM applications.

This README will guide you through installation, usage, and explore the functionalities of each reader.

Installation

pip install llama-index-readers-box

Available readers

We provide multiple readers, including:

  • Box Reader - Implementation of the SimpleReader interface to read files from Box.
  • Box Text Extraction - Uses Box text representation to extract text from document.
  • Box AI Prompt - Uses Box AI to extract context from documents
  • Box AI Extraction - Uses Box AI to extract structured data from documents

Authentication

Client credential gran (CCG)

Create a new application in the Box Developer Console and generate a new client ID and client secret.
Create a .env file with the following content:

### CCG settings
BOX_CLIENT_ID = YOUR_CLIENT_ID
BOX_CLIENT_SECRET = YOUR_CLIENT_SECRET

### Common Settings
BOX_ENTERPRISE_ID = YOUR_BOX_ENTERPRISE_ID
BOX_USER_ID = YOUR_BOX_USER_ID (optional)

By default the CCG client will use a service account associated with the application. Depending on how the files are shared, the service account may not have access to all the files.

If you want to use a different user, you can specify the user ID in the .env file. In this case make sure your application can impersonate and/or generate user tokens in the scope.

Checkout this guide for more information on how to setup the CCG: Box CCG Guide

JSON web tokens (JWT)

Create a new application in the Box Developer Console and generate a new .config.json file.
Create a .env file with the following content:

### Common settings
BOX_ENTERPRISE_ID = 877840855
BOX_USER_ID = 18622116055

### JWT Settings
JWT_CONFIG_PATH = /path/to/your/.config.json

By default the JWT client will use a service account associated with the application. Depending on how the files are shared, the service account may not have access to all the files.

If you want to use a different user, you can specify the user ID in the .env file. In this case make sure your application can impersonate and/or generate user tokens in the scope.

Checkout this guide for more information on how to setup the JWT: Box JWT Guide

pip install "box-sdk-gen[jwt]"

Box Client

To work with the box readers, you will need to provide a Box Client.
The Box Client can be created using either the Client Credential Grant (CCG), JSON Web Tokens (JWT), OAuth 2.0, and developer token.

Using CCG authentication

from box_sdk_gen import CCGConfig, BoxCCGAuth, BoxClient

config = CCGConfig(
    client_id="your_client_id",
    client_secret="your_client_secret",
    enterprise_id="your_enterprise_id",
    user_id="your_ccg_user_id",  # Optional
)
auth = BoxCCGAuth(config)
if config.user_id:
    auth.with_user_subject(config.user_id)
client = BoxClient(auth)

reader = BoxReader(box_client=client)

Using JWT authentication

from box_sdk_gen import JWTConfig, BoxJWTAuth, BoxClient

#### Using manual configuration
config = JWTConfig(
    client_id="YOUR_BOX_CLIENT_ID",
    client_secret="YOUR_BOX_CLIENT_SECRET",
    jwt_key_id="YOUR_BOX_JWT_KEY_ID",
    private_key="YOUR_BOX_PRIVATE_KEY",
    private_key_passphrase="YOUR_BOX_PRIVATE_KEY_PASSPHRASE",
    enterprise_id="YOUR_BOX_EN

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.