Automate smart file management pipelines by document type | Alpha | PandaiTech

Automate smart file management pipelines by document type

Building a router system that detects file types (SEC filings, contracts, or infrastructure images) and automatically routes them to the correct processing workflow.

Learning Timeline
Key Insights

Model Selection Based on Task

Use large models (like Gemini) for complex visual tasks, but use smaller, more affordable models for structured data extraction tasks like Form 4 extraction to save on operational costs.

Smart Routing Techniques

Don't process all files the same way. By classifying files at an early stage (router), you can use different prompts and models for each document type, making the pipeline more efficient and accurate.
Prompts

Document Classification Logic

Target: DSPy Signature / LLM
Given these images (the first few pages of a document), identify the type. Options: [SEC filing, Contract, City Infrastructure Image]. Return only the document type.
Step by Step

Building an Automated File Classification Pipeline with DSPy

  1. Import the DSPy and attachments libraries to handle various media input types uniformly.
  2. Configure API keys for two types of models: a standard model (LLM) for text and a Visual Model (such as Gemini) for image recognition.
  3. Use the 'classify_file' function to send documents (PDFs or images) to the DSPy program.
  4. Extract the first three pages or the first few images from the source document to serve as input fields.
  5. Define 'Document Type' as the signature output to determine if the file is an SEC filing, a contract, or an infrastructure image.
  6. Use 'if-else' or 'switch' logic based on the classification results to determine the routing for the subsequent process.
  7. For SEC Filing files: Run the 'form4 extraction' function using a smaller model to reduce costs.
  8. For Contract files: Call the 'recursive summarization' function to summarize the entire document and detect document boundaries.
  9. For Infrastructure images: Send the file to a Visual Model for deeper visual interpretation.