Skip to main content

What is Unstructured?

Unstructured is an open-source library that helps you extract, transform, and prepare unstructured data from documents (PDFs, Word files, images, and more) for use with LLMs and other AI applications. It provides powerful partitioning, chunking, and staging capabilities to convert raw documents into structured, AI-ready data. By combining Unstructured’s document processing with Cerebras’s ultra-fast inference, you can build intelligent document analysis pipelines that extract insights, answer questions, and generate summaries from your documents at unprecedented speeds. Learn more at https://unstructured.io/.

Prerequisites

Before you begin, ensure you have:
  • Cerebras API Key - Get a free API key here.
  • Python 3.11 or higher - Unstructured requires Python 3.11+.
  • Sample Documents - Have some PDFs, Word docs, or other files ready to process.

Installation and Setup

1

Install required dependencies

Install the Unstructured library along with the OpenAI SDK for Cerebras integration:
For processing specific file types, you may need additional dependencies. To process PDFs with OCR:
To install all available extras for maximum file type support:
2

Configure environment variables

Create a .env file in your project directory to store your API key securely:
This keeps your credentials safe and makes it easy to manage different environments.
3

Initialize the Cerebras client

Set up the OpenAI-compatible client to connect to Cerebras Inference. This client will be used to send processed document content to Cerebras models for analysis:

Basic Document Processing

1

Process a document with Unstructured

Use Unstructured to extract and partition content from your document. The partition function automatically detects the file type and extracts structured elements:
The partition function intelligently identifies different document elements like titles, paragraphs, tables, and lists, preserving the document’s structure.
2

Analyze the document with Cerebras

Send the processed document content to a Cerebras model for analysis, summarization, or question answering:
Cerebras’s fast inference means you get results in seconds, even for long documents.

Advanced: Chunking for RAG Applications

For Retrieval-Augmented Generation (RAG) applications, you’ll want to chunk your documents into smaller, semantically meaningful pieces. This improves retrieval accuracy and ensures your context fits within model token limits.
1

Chunk documents intelligently

Use Unstructured’s chunking capabilities to split documents while preserving context:
The chunk_by_title function creates semantically coherent chunks by keeping related content together based on document structure.
2

Process chunks with Cerebras for Q&A

Use the chunked content to build a question-answering system:
3

Integrate with vector databases

For production RAG systems, combine Unstructured with vector databases for semantic search:
Learn more about staging functions in the Unstructured documentation.

Complete Example: Document Analysis Pipeline

Here’s a complete example that processes a document, extracts key information, and generates insights:

Use Cases

Document Summarization

Process lengthy reports, research papers, or legal documents and generate concise summaries:

Information Extraction

Extract structured data from unstructured documents:

Multi-Document Analysis

Compare and analyze multiple documents simultaneously:

Supported File Types

Unstructured supports a wide variety of file formats: See the Unstructured documentation for the complete list of supported formats.

Best Practices

Chunking Strategy

Choose the right chunking strategy based on your use case:
  • chunk_by_title: Best for documents with clear hierarchical structure (reports, articles)
  • Fixed-size chunking: Good for uniform processing and consistent token counts
  • Semantic chunking: Ideal for maintaining context in conversational or narrative documents

Token Management

Monitor token usage to optimize costs and performance:

Error Handling

Implement robust error handling for production systems:

Frequently Asked Questions

Unstructured supports over 20 file types including PDF, DOCX, PPTX, HTML, images (with OCR), and more. For the complete list, see the supported file types documentation.
Use Unstructured’s chunking capabilities to split large documents into smaller pieces:
Process each chunk separately or use a map-reduce pattern to summarize chunks and then combine summaries.
Yes! You can use any Cerebras model. For document analysis, we recommend:
  • cerebras/gpt-oss-120b: Best for complex analysis and reasoning
Simply change the model parameter in your API calls.
Unstructured automatically identifies and extracts tables. You can access them as HTML:
Learn more in the table extraction guide.
Unstructured offers three partitioning strategies:
  • auto: Automatically selects the best strategy (recommended)
  • fast: Faster processing with basic text extraction
  • hi_res: High-resolution processing with better table and layout detection
Install the OCR dependencies and Unstructured will automatically use OCR for images and scanned PDFs:
Then process as normal:
Unstructured uses Tesseract OCR by default. You can also configure it to use other OCR engines.

Troubleshooting

Installation Issues

If you encounter errors during installation, try installing dependencies for specific file types:
On macOS, you may need to install system dependencies:

Memory Issues with Large Documents

For very large documents, use the fast strategy to reduce memory usage. Process documents in batches or use streaming approaches for very large files.

API Rate Limits

If processing many documents, implement rate limiting and error handling:

Document Processing Errors

If a document fails to process, try different strategies:

Next Steps

Additional Resources