Vector similarity search is becoming increasingly important for data science pipelines, particularly in Retrieval-Augmented Generation (RAG), where it enhances large language model inference by enabling efficient retrieval of relevant external knowledge. As RAG expands with table-augmented generation to incorporate structured data, workloads integrating table and vector search are becoming more prevalent. However, efficiently executing such queries remains challenging due to inaccurate cardinality estimation for vector search components, leading to suboptimal query plans. In this paper, we propose Exqutor, an extended query optimizer for vector-augmented analytical queries. Exqutor is a pluggable cardinality estimation framework designed to address this issue, leveraging exact cardinality query optimization techniques to enhance estimation accuracy when vector indexes (e.g., HNSW, IVF) are available. In scenarios lacking these indexes, we employ a sampling-based approach with adaptive sampling size adjustment, dynamically tuning the sample size to balance estimation accuracy and sampling overhead. This allows Exqutor to efficiently approximate vector search cardinalities while minimizing computational costs. We integrate our framework into pgvector, VBASE, and DuckDB, demonstrating performance improvements of up to four orders of magnitude on vector-augmented analytical queries.
翻译:向量相似性搜索在数据科学流水线中日益重要,尤其在检索增强生成(RAG)中,它通过高效检索相关外部知识增强大语言模型推理能力。随着RAG扩展到表增强生成以融合结构化数据,整合表查询与向量搜索的工作负载愈发普遍。然而,由于向量搜索组件基数估计不准确导致查询计划次优,高效执行此类查询仍具挑战性。本文提出Exqutor,一种面向向量增强分析查询的扩展查询优化器。Exqutor是一种可插拔基数估计框架,旨在解决该问题,通过利用精确基数查询优化技术,在现有向量索引(如HNSW、IVF)时提升估计精度。针对缺乏此类索引的场景,我们采用基于采样的方法,通过自适应调整采样规模,动态调节样本大小以平衡估计精度与采样开销。这使得Exqutor能高效近似向量搜索基数,同时最小化计算成本。我们将该框架集成至pgvector、VBASE及DuckDB中,实验表明其在向量增强分析查询上的性能提升可达四个数量级。