r/Rag • u/Acceptable-Week957 • 16h ago
Discussion Building a Document-Agnostic RAG Agent for Heterogeneous Documents — Looking for Ingestion and Retrieval Pipeline Recommendations
I'm currently building an AI chatbot with an agentic architecture for querying internal documents and data. One of the main challenges I'm facing is designing a reliable ingestion and retrieval pipeline that can handle a wide variety of document types without sacrificing answer accuracy.
1. The document types I need to support
The system needs to work with a fairly broad range of content, including:
- Legal documents and regulations: Long documents with nested sections, articles, clauses, and cross-references.
- Reports and business documents: Documents containing tables, charts, figures, and mixed layouts.
- General text documents: DOCX, TXT, Markdown, and similar formats.
- Excel files: Multiple sheets, structured tables, headers, and potentially complex relationships between cells.
- PDFs: Both digitally generated PDFs and scanned PDFs that require OCR.
- Images embedded in documents: Diagrams, charts, screenshots, scanned pages, and other visual information that may contain essential context.
The challenge is that these formats have very different structures and require different extraction and preprocessing strategies.
2. Problems with my current approach
Currently, I'm experimenting with separate ingestion pipelines for different document types. Each pipeline handles extraction, preprocessing, chunking, and indexing according to the input format.
However, I'm running into several issues:
- Ingestion complexity: Each format requires different handling, and maintaining multiple pipelines introduces edge cases and inconsistent outputs.
- Structure preservation: Naive text extraction and chunking can lose relationships between legal articles, tables, spreadsheet headers and values, or text and its associated images.
- Scanned PDFs and visual content: OCR can introduce errors, while extracting text alone may miss important information in charts, diagrams, and complex layouts.
- Retrieval accuracy: A single retrieval strategy doesn't seem suitable for every type of content. For example, semantic search may work well for conceptual questions but perform poorly on exact legal clauses, numerical values, or spreadsheet lookups.
- Query routing: Since this is an agentic chatbot, I also need to determine how to route each question to the appropriate retrieval strategy or data source. Some questions may require a combination of document retrieval, structured data lookup, and visual content analysis.
My main concern is that adding more document-specific logic will make the system increasingly difficult to maintain, while using a single generic pipeline may compromise retrieval quality.
3. What I'm looking for
For those who have built production RAG systems handling heterogeneous enterprise documents:
- Ingestion architecture: Would you recommend a unified ingestion framework with format-specific extractors, or completely separate pipelines for each document type? Is there a good way to normalize their outputs while preserving document structure?
- Document parsing: What tools or frameworks have worked well for complex PDFs, scanned documents, Excel files, and image-heavy reports? I've been exploring tools such as Docling, Unstructured, and OCR-based solutions, but I'm still unsure how to combine them into a robust pipeline.
- Indexing and retrieval: How do you handle different retrieval requirements across legal text, ordinary documents, tables, spreadsheets, and visual content? Do you use separate indexes, hybrid retrieval, parent-child chunking, multimodal embeddings, or a combination of these?
- Agent and query routing: How do you decide whether a question should go through vector search, keyword search, structured table or spreadsheet lookup, OCR-derived content, or a vision-capable model? Do you use a lightweight classifier, an LLM-based router, or a more explicit query-planning approach?
- Practical recommendations: If you were designing this system from scratch today, what architecture and open-source components would you choose? Are there any approaches that seem promising in demos but become unreliable or expensive in real-world use?
I'm particularly interested in approaches that prioritize answer correctness, reliable source citations, and maintainability, rather than simply maximizing retrieval coverage.
Any recommendations, lessons learned, or examples of production architectures would be greatly appreciated. Thanks!