DuckDB and Infino on SQL, keyword, vector and hybrid search

· · engineering

DuckDB is a popular analytics database, and like a lot of analytics tools it has added search: its fts extension does BM25 full-text search and its vss extension does HNSW vector search. We wanted to see how far those extensions go, so we ran DuckDB against Infino on four workloads: SQL analytics, keyword search, vector search and hybrid search.

DuckDB is faster on SQL analytics over its own storage format. Infino is faster on the three search workloads: about 2x on vector search at the same recall, 10x on hybrid search, and thousands of times on keyword search.

Setup

The SQL numbers come from the public ClickBench results. For search, we ran DuckDB 2.0.1 and Infino 0.13.2 (the Python package) on one Azure Standard_D8ds_v7 (8 vCPU, 32 GiB, local NVMe), with Lucene 10.6.0 as a reference for keyword search. Data was on local disk, not object storage.

Every engine got the same data and the same queries. Queries ran one at a time on a warm engine, with a warm-up pass before timing. We used default settings, except for DuckDB’s HNSW ef_search, which we swept so DuckDB could reach the same recall as Infino. A query an engine couldn’t run counted as unsupported.

SQL analytics

ClickBench runs 43 analytical queries over 100 million rows of web traffic. These are the hot-run totals from the latest public results: for each query, the faster of the second and third runs, summed.

MachineDuckDBDuckDB on ParquetInfino
c6a.4xlarge (16 vCPU)25.1 s33.9 s30.5 s
c8g.metal-48xl (192 vCPU)4.99 s8.10 s6.08 s

On its own format, DuckDB is about 20% faster than Infino on both machines. On Parquet, the format Infino stores its data in, DuckDB is 11% slower than Infino on the smaller machine and 33% slower on the larger one.

ClickBench doesn’t test text ranking, vector search or score fusion, so we measured those ourselves.

We used Search Benchmark, the Game, which runs 962 real queries against 5 million English Wikipedia articles on a single thread. We added a DuckDB engine that uses match_bm25.

DuckDB took about 6 seconds per query, so it ran a stratified sample of 101 queries, timed once after a warm-up. Infino and Lucene ran the same sample with the harness’s usual best of 10. DuckDB can’t run phrase or exclusion queries, which ruled out 38 of the 101. Mean latency on the other 63:

QueryDuckDBInfinoLucene
Top 106,241 ms0.30 ms0.62 ms
Top 1006,025 ms0.47 ms0.97 ms
Top 10006,049 ms0.80 ms1.74 ms
Top 100 and count6,006 ms1.12 ms3.43 ms
Count6,009 ms0.27 ms0.68 ms

DuckDB, Infino and Lucene returned the same hit counts on all 63 queries. DuckDB’s time barely changes between query types because match_bm25 scores every document in the table. It doesn’t skip through posting lists or stop once it has the top k. DuckDB’s full-text index also doesn’t update when rows change. It has to be rebuilt.

On the full 962 queries, Infino takes 0.49 of Lucene’s time on top-k queries and 0.39 on counts.

Index buildTimeSize
Infino133 s2.5 GB
Lucene129 s2.7 GB
DuckDB165 s13 GB, including the article text

We used Cohere 1M from VectorDBBench: 1 million 768-dimension embeddings, cosine similarity, and 1,000 queries with exact ground truth, at k = 10. DuckDB used the vss HNSW index at four ef_search values. Infino used its defaults.

Engineef_searchRecall@10p50p95
DuckDB64 (default)0.9373.2 ms
DuckDB1280.9674.0 ms
DuckDB2560.9795.3 ms
DuckDB5120.9898.1 ms9.6 ms
Infinon/a0.9913.9 ms6.2 ms

At recall 0.99, Infino’s median is 3.9 ms and DuckDB’s is 8.1 ms. DuckDB at its default ef_search is faster, at recall 0.937.

DuckDB builds its HNSW index in memory. Keeping it on disk needs an experimental setting, so by default every new process builds it again, which took 212 s on this data. Infino loaded the data and built its index in 92 s, and the table is 4.5 GB on disk.

We took 1 million English passages from Cohere’s Wikipedia 2023-11 embeddings (1024 dimensions) and used the next 1,000 passages as queries. Each query searches the passage title as keywords and its embedding as the vector.

DuckDB and Infino can both answer a hybrid question in one SQL statement, and both can add a graph hop to that statement: Infino with its graph_walk table function, DuckDB with the DuckPGQ extension. We measured text and vector here, not graph.

DuckDB and Infino each take the BM25 top 100 and the vector top 100 and combine them with reciprocal rank fusion (k = 60). Infino uses its hybrid_search table function. DuckDB uses two CTEs and fuses them in SQL.

Enginep50p95
DuckDB80 ms340 ms
Infino8.0 ms12.1 ms

Infino’s median is 10 times lower and its p95 28 times lower. DuckDB and Infino share 80% of their top 10 results. The rest comes down to how each tokenizes text for BM25.

Limitations of the extensions

Apart from speed, the extensions leave gaps that showed up in the tests above.

DuckDBInfino
Phrase and exclusion queriesNot supported by match_bm25, which ruled out 38 of the 101 sampled queriesSupported
Top-k keyword searchScores every document in the tableSkips through posting lists and stops at the top k
Full-text index when rows changeRebuilt by handKept up to date as rows are written
Vector index on diskNeeds an experimental setting. By default it is rebuilt in every new process, 212 s on Cohere 1MStored with the table
Hybrid searchTwo CTEs and rank fusion written by hand in SQLOne hybrid_search table function

Summary

DuckDB is an analytical database with search extensions. Infino is a search engine that runs SQL over Parquet. If your queries scan and aggregate columns, DuckDB on its own format is faster. If they rank text, vectors or both, Infino was faster on the keyword, vector and hybrid tests above.

What it means for agents

The questions agents ask mix all of these at once. “How many errors last night mention disk full or look like a capacity incident, and which team owns the service?” needs a keyword search, a vector search, a filter, a count and a join. To Infino that is one SQL statement, and the search parts of it are the ones measured above.

An agent also asks many of these questions to finish one task, each building on what the last one returned, so retrieval time adds up. At DuckDB’s 6 seconds per keyword search, ten steps take a minute. At Infino’s 0.3 ms per keyword search and 8 ms per hybrid search, ten steps take under a tenth of a second.