Automating RAG Optimization: Finding Optimal Configurations Through Systematic Testing
Learn how Queryloop automates RAG optimization through systematic testing of parameter combinations to maximize accuracy, minimize latency, and control costs for complex document analysis.
Retrieval Augmented Generation (RAG) systems have emerged as a powerful approach for building accurate and reliable AI applications by connecting language models to external knowledge sources. However, achieving optimal performance requires carefully tuning numerous parameters - a process that traditionally demands extensive manual experimentation.
Testing Ground: The Docugami SEC 10-Q Dataset
- It contains multiple documents from major tech companies (AAPL, AMZN, INTC, MSFT, NVDA)
- The documents are long-form with complex structures (tables, sections, footnotes)
- The questions require different retrieval capabilities, from simple lookups to multi-document synthesis
- 10 Single-Doc, Single-Chunk questions (answers found in one contiguous section)
- 5 Single-Doc, Multi-Chunk questions (answers requiring information from multiple sections)
- 5 Multi-Doc questions (answers synthesized from multiple documents)
Experiment 1: Finding the Optimal Chunk Size
- Metric Type: cosine
- Retrieval Method: basic
- Post Retrieval: none
- Top K: 20
- Embedding Model: text-embedding-3-large
- Document Parser: Basic
- Query Transformation: Basic
Experiment 2: Evaluating Distance Metrics
- Chunk Size: 4200
- Retrieval Method: basic
- Post Retrieval: none
- Top K: 20
- Embedding Model: text-embedding-ada-002
- Document Parser: Basic
- Query Transformation: Basic
Experiment 3: Testing Query Transformation Techniques
- Chunk Size: 4200
- Metric Type: hybrid
- Retrieval Method: basic
- Post Retrieval: none
- Top K: 5
- Embedding Model: text-embedding-ada-002
- Document Parser: Basic
Experiment 4: Optimizing Retrieval Method and Top K
- Chunk Size: 4200
- Metric Type: hybrid
- Post Retrieval: none
- Embedding Model: text-embedding-ada-002
- Document Parser: Basic
- Query Transformation: Basic
The Optimal Configuration
Conclusion: The Value of Automated Parameter Optimization

- Larger chunk sizes (4200 tokens) significantly outperform smaller ones
- Hybrid distance metrics provide better results than standard cosine or euclidean metrics
- Simple query transformation approaches performed better than complex ones
- The sentence-window retrieval method with moderate Top K values (10) achieves optimal results
Related Posts
Why Building Production-Grade RAG Applications Is So Hard
Learn why creating demo RAG applications is easy, but building production-grade systems is exponentially harder, and how Queryloop solves these challenges.
Solving Complex Table Parsing in RAG Systems: A Comparative Analysis
Discover how we compared 8 different parsing solutions to tackle hierarchical tables, merged cells, and horizontally tiled tables in PDFs for RAG applications.