MCPcopy Create free account
hub / github.com/VectorDB-NTU/RaBitQ-Library / main

Function main

sample/python/hnsw_rabitq_indexing.py:19–53  ·  view source on GitHub ↗
(args=None)

Source from the content-addressed store, hash-verified

17
18
19def main(args=None) -> None:
20 # 1. Load data
21 data = read_fvecs(args.data_file)
22 print(f"Data shape: {data.shape}")
23
24 # 2. Cluster with FAISS
25 centroids, cluster_ids = cluster_data(data, args.num_clusters, args.metric, args.num_threads)
26 print(f"Centroids: {centroids.shape}, cluster_ids: {cluster_ids.shape}")
27
28 # 3. Build HNSW index
29 n, dim = data.shape
30 print(f"\nBuilding HNSW index: n={n}, dim={dim}, M={args.degree}, "
31 f"ef={args.ef_construction}, bits={args.total_bits}, metric={args.metric}")
32
33 idx = HnswIndex(
34 dim=dim,
35 max_elements=n,
36 M=args.degree,
37 ef_construction=args.ef_construction,
38 nbits=args.total_bits,
39 metric=args.metric,
40 )
41
42 t0 = time()
43 idx.build(
44 data,
45 centroids,
46 cluster_ids,
47 num_threads=args.num_threads,
48 fast_quantization=args.faster_quant,
49 )
50 print(f"Indexing time: {time() - t0:.2f}s")
51
52 idx.save(args.index_file)
53 print(f"Index saved → {args.index_file}")
54
55
56if __name__ == "__main__":

Callers 1

Calls 6

buildMethod · 0.95
saveMethod · 0.95
read_fvecsFunction · 0.90
cluster_dataFunction · 0.90
HnswIndexClass · 0.85
printFunction · 0.50

Tested by

no test coverage detected