WikiANN / README.md
suchun's picture
Add files using upload-large-folder tool
abc9430 verified
metadata
license: mit
task_categories:
  - feature-extraction
tags:
  - vector-search
  - approximate-nearest-neighbor
  - filtered-ann
  - retrieval
size_categories:
  - 10M<n<100M

WikiANN — Filtered Vector Search Benchmark

A benchmark for vector search under conjunctive (AND) keyword filters, built on top of Cohere's Wikipedia embeddings. Each base vector and each query vector carries a set of integer keyword labels; a query asks for the nearest neighbors among base vectors whose label set is a superset of the query's label set.

Two scales are provided:

Subset # base vecs # base files # queries dim dtype
wiki_35M/ 35,000,000 70 shards × 500k 5,000 768 float32
wiki_1M/ 980,312 2 shards (500k + 480,312) 5,000 768 float32

The 1M slice is intended for prototyping; the 35M slice is the full benchmark.

Sources

  • Base embeddings (35M): Cohere wikipedia-22-12-en-embeddings
  • Query embeddings (5k): Cohere wikipedia-22-12-simple-embeddings, randomly sampled
  • Labels: words from each passage that also appear in the global top-4000 most-common words across all passages

Layout

wiki_35M/
├── base_data/
│   ├── base_database_{1..70}.bin   # raw float32, 500,000 × 768 each, no header
│   ├── base_labels1.txt            # split base label files
│   └── base_labels2.txt            #   (cat them together for the full file)
├── query.bin                        # int32 num, int32 dim, then float32 data
├── query_labels.txt                 # one line per query
└── combine_base_vecs.py             # merges the 70 shards into base.bin

wiki_1M/
├── base_data/
│   ├── base_1.bin                   # raw float32, 500,000 × 768, no header
│   ├── base_2.bin                   # raw float32, 480,312 × 768, no header
│   └── base_labels.txt              # 980,312 lines
├── query.bin
├── query_labels.txt
└── combine_base_vecs.py

File formats

Base shards (base_*.bin, base_database_*.bin)

Raw little-endian float32, no header. Each shard is exactly vecs_per_shard × dim × 4 bytes.

Query / merged base (query.bin, base.bin after combining)

[int32_le num_vecs][int32_le dim][float32_le data ...]

data is num_vecs × dim values in row-major order. Total size is 8 + num_vecs * dim * 4 bytes.

Base labels (base_labels*.txt)

One line per base vector, in the same order as the vectors. Each line is a comma-separated list of integer label IDs.

12,344,1027
8
3,77,222,891
...

For wiki_35M/, concatenate base_labels1.txt and base_labels2.txt in numeric order to recover the full 35,000,000-line file:

cat base_labels1.txt base_labels2.txt > base_labels.txt

Query labels (query_labels.txt)

One line per query, in the same order as query.bin. Each line is a &-separated list of integer label IDs. Each query carries at most two labels in this dataset.

12&344
77
8&3
...

A retrieval is "correct" iff the candidate base vector's label set contains every query label (set containment, i.e., AND filter).

Reconstructing base.bin

The shards are stored separately to stay under per-file size limits. To get a single contiguous base.bin (the format used by most DiskANN-style index builders), run the bundled script inside each subfolder:

cd wiki_35M && python combine_base_vecs.py    # produces base_data/base.bin (~107 GB)
cd wiki_1M  && python combine_base_vecs.py    # produces base_data/base.bin (~2.9 GB)

The script streams shards 64 MB at a time, so RAM stays flat regardless of total output size. You need free disk equal to the merged file size.

Embeddings note

These are Cohere's original Wikipedia embeddings; they are not L2-normalized. Typical per-vector norms are around 12–14. If your ANN setup assumes unit-norm cosine similarity, normalize at index / query time:

import numpy as np
def l2_normalize(x):
    n = np.linalg.norm(x, axis=-1, keepdims=True)
    return x / np.maximum(n, 1e-12)

Quick start (Python)

import numpy as np

def load_bin(path):
    with open(path, "rb") as f:
        num, dim = np.fromfile(f, dtype=np.int32, count=2)
        data = np.fromfile(f, dtype=np.float32, count=num * dim)
    return data.reshape(num, dim)

def load_query_labels(path):
    with open(path) as f:
        return [tuple(int(x) for x in line.strip().split("&")) for line in f]

def load_base_labels(path):
    with open(path) as f:
        return [tuple(int(x) for x in line.strip().split(",")) for line in f]

queries = load_bin("wiki_1M/query.bin")
q_labels = load_query_labels("wiki_1M/query_labels.txt")

License

MIT.