<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Grégoire Guémas on Medium]]></title>
        <description><![CDATA[Stories by Grégoire Guémas on Medium]]></description>
        <link>https://medium.com/@gguemas?source=rss-a2721d34a645------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*oCwj2khv59bgbTyK</url>
            <title>Stories by Grégoire Guémas on Medium</title>
            <link>https://medium.com/@gguemas?source=rss-a2721d34a645------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:44:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gguemas/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vector Database: Benchmark indexing parameters]]></title>
            <link>https://medium.com/weborama/vector-database-benchmark-indexing-parameters-7e0932387034?source=rss-a2721d34a645------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e0932387034</guid>
            <category><![CDATA[milvus]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[indexing]]></category>
            <dc:creator><![CDATA[Grégoire Guémas]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 13:30:21 GMT</pubDate>
            <atom:updated>2025-01-23T13:30:21.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hm9S6kQWL4-DU2d9mJxAuA.png" /></figure><p>Managing hundreds of millions of vectors in a scalable and efficient way is a persistent challenge in modern data systems. For our use case — ranking URLs from a large-scale dataset — <strong>Milvus</strong> emerged as a natural choice. This state-of-the-art vector database is designed to perform fast and accurate approximate nearest neighbor (ANN) searches, even with datasets containing hundreds of millions of high-dimensional vectors.</p><p>The challenge we faced was identifying the optimal parameters for Milvus’s <strong>IVF-PQ indexing</strong>, balancing indexing time, query latency, and recall to ensure relevant results while maintaining resource efficiency. This article details our experiment to uncover the best parameter configuration for our needs.</p><p>At Weborama, we have several use cases where we need to rank hundreds of millions of vectors for a specific query multiple times per second. Since it’s nearly impossible to compute the cosine similarity across the entire dataset in a reasonable amount of time, we transitioned to a vector database. You can read more about this transition in<a href="https://medium.com/weborama/document-similarities-a-continuous-loop-between-pocs-and-production-db3acdc019a5"> our Medium article</a>.</p><p><strong>Understanding IVF-PQ Indexing</strong></p><p>Although this article focuses on parameter optimization, here’s a brief overview of IVF-PQ indexing for context:</p><p>The <strong>IVF-PQ</strong> indexing mechanism in Milvus combines two powerful techniques:</p><ol><li><strong>Inverted File (IVF)</strong>: Divides the vector space into clusters and assigns vectors to the nearest cluster centroid, reducing the search space during queries.</li><li><strong>Product Quantization (PQ)</strong>: Compresses vectors into compact codes, significantly reducing memory usage and increasing search speed.</li></ol><p><strong>Key Parameters Influencing IVF-PQ Performance:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*MnOe_0m2u_CLoavW1Xkv4Q.png" /></figure><p><strong>PQ Compression</strong></p><p>Product Quantization compresses vectors by dividing them into <strong>m</strong> subvectors and encoding each subvector using a codebook. Each subvector has a size of dim / m, effectively playing a dimension reduction role.</p><p><strong>Experiment Setup</strong></p><h4>Environment</h4><p>We conducted our experiments using a dedicated <strong>n2-standard-16 VM</strong> from Google Cloud Platform (GCP), equipped with 16 CPUs and 64 GiB of RAM. Python 3.11 was used to run the benchmarks.</p><h4>Dataset</h4><p>We utilized <strong>7 million real vectors</strong> extracted from the Weborama Crawler dataset, each vector having <strong>1024 dimensions</strong>. These embeddings provide a realistic dataset for benchmarking, ensuring consistency with real-world use cases.</p><p><strong>Why 7 Million Vectors?</strong></p><blockquote>Although our ultimate goal involves working with hundreds of millions of vectors, we started with a smaller subset of real-world data. This allowed us to design and validate our benchmarks without overloading resources. Once the configurations were tested and optimized, we scaled up the benchmarks to much larger datasets.</blockquote><p><strong>Database and Disk Preparation</strong></p><ol><li><strong>Database Population</strong>: We populated the <strong>Milvus database</strong> with the 7 million vectors.</li><li><strong>Memory-Mapped File</strong>: We created a <strong>numpy memory-mapped (mmap) file</strong> to store the vectors on disk for further computations.</li><li><strong>URL Index</strong>: Using Python’s pickle module, we saved a parallel index mapping each vector to its corresponding URL.</li></ol><blockquote>About <a href="https://numpy.org/doc/2.1/reference/generated/numpy.memmap.html">numpy.mmap</a></blockquote><blockquote>Handling 7 million vectors of 1024 dimensions would require storing: 7 millions vectors 1024 dimensions 32 bits = ~29Gi.</blockquote><blockquote>Since each vector is accessed only once per benchmark, keeping all vectors in memory is inefficient. Instead, we utilized <strong>numpy’s mmap</strong>, which maps the numpy array to a file on disk. This allows the matrix to be accessed as if it were in memory while only loading the necessary portions on demand.</blockquote><blockquote>Using numpy.mmap proved especially beneficial in a <strong>parallelized environment</strong>, where each object in memory is duplicated for each thread. By avoiding in-memory duplication, we significantly reduced resource consumption.</blockquote><p><strong>Parameter Testing (Indexing)</strong></p><p>We tested combinations of the following parameters:</p><ul><li><strong>n_list:</strong> Ranging from 125 to 5000.</li><li><strong>m:</strong> Starting from 16 to 256</li><li><strong>nbits:</strong> Keep default value to 8 bits.</li></ul><p><strong>Average Vector Distribution:</strong></p><p>With 7 million vectors in our database, the data is divided into <strong>nlist</strong> clusters. This means:</p><ul><li>For <strong>nlist = 125</strong>, each cluster contains approximately <strong>56,000 vectors</strong> (7,000,000 ÷ 125).</li><li>For <strong>nlist = 5,000</strong>, each cluster contains approximately <strong>1,400 vectors</strong> (7,000,000 ÷ 5,000).</li></ul><p><strong>Impact of m</strong>:<br>The parameter <strong>m</strong> divides each vector into subvectors for product quantization:</p><ul><li>For <strong>m = 16</strong>, each subvector consists of <strong>1024 ÷ 16 = 64 coefficients</strong>.</li><li>For <strong>m = 256</strong>, each subvector consists of <strong>1024 ÷ 256 = 4 coefficients</strong>.<br>As <strong>m</strong> increases, the size of each subvector decreases, allowing for finer granularity but requiring more memory for encoding.</li><li>Increasing <strong>m</strong> improves recall by providing finer granularity in vector encoding but comes at the cost of increased memory usage.</li></ul><p>With <strong>nbits = 8</strong>, each subvector is encoded using a codebook of 256 entries (2⁸). The size of each cluster impacts how many vectors are represented by a single centroid index in the codebook:</p><ul><li>For <strong>nlist = 125</strong>, each cluster has 56,000 vectors, and each codebook entry represents ~218 vectors (56,000 ÷ 256).</li><li>For <strong>nlist = 5,000</strong>, each cluster has 1,400 vectors, and each codebook entry represents ~5 vectors (1,400 ÷ 256).</li></ul><blockquote>Setting <strong>nbits</strong> higher than 8 (e.g., 16, which allows for 2¹⁶ = 65,536 centroids) does not make sense for our use case because the number of centroids would far exceed the average number of vectors per cluster.</blockquote><blockquote>In contrast, using 8 bits (2⁸ = 256 centroids) strikes a balance by providing sufficient resolution to distinguish between vectors within a cluster while avoiding the inefficiencies of excessive granularity. This ensures both computational efficiency and effective search performance.</blockquote><p><strong>Parameter Testing (Searching)</strong></p><p>For each configuration, we performed searches across a range of <strong>top_k</strong> values: 100, 500, 1,000, 5,000, 10,000, 50,000, 100,000, 500,000, and 1,000,000.</p><p>To evaluate query granularity in relation to <strong>nlist</strong>, we varied the <strong>nprobe </strong>parameter (how many clusters we want to use in a query) using percentages: 1%, 3%, 5%, 10%, and 20% of <strong>nlist</strong>. Using a relative percentage rather than an absolute value (e.g., <strong>nprobe = 10</strong>) ensures consistency across benchmarks, as the impact of <strong>nprobe</strong> depends heavily on the value of <strong>nlist</strong>. For instance, <strong>nprobe = 10</strong> behaves very differently when <strong>nlist = 125</strong> compared to <strong>nlist = 5000</strong>. By adopting a percentage-based approach, we ensured fair comparisons and a scalable evaluation across all configurations.</p><h3>Ground-Truth Comparison</h3><p>To calculate recall, we computed cosine similarity between the query vector and all database vectors. This was achieved using <a href="https://numba.pydata.org/">numba</a> for parallel computation:</p><pre>@numba.jit(nopython=True, parallel=True)<br>def fast_cosine_matrix(u, M):<br>   scores = np.zeros(M.shape[0])<br>   for i in numba.prange(M.shape[0]):<br>       v = M[i]<br>       m = u.shape[0]<br>       udotv = 0<br>       u_norm = 0<br>       v_norm = 0<br>       for j in range(m):<br>           if (np.isnan(u[j])) or (np.isnan(v[j])):<br>               continue<br>           udotv += u[j] * v[j]<br>           u_norm += u[j] * u[j]<br>           v_norm += v[j] * v[j]<br><br><br>       u_norm = np.sqrt(u_norm)<br>       v_norm = np.sqrt(v_norm)<br><br><br>       if (u_norm == 0) or (v_norm == 0):<br>           ratio = 1.0<br>       else:<br>           ratio = udotv / (u_norm * v_norm)<br>       scores[i] = ratio<br>   return scores</pre><p>Using numba like this allows:</p><ul><li><strong>parallel=True</strong>: Parallel computation (i.e spawn many slaves processes to work on each line of the matrix).</li><li><strong>nopython=True</strong>: where Python objects and the Global Interpreter Lock (GIL) are bypassed. This reduces overhead and allows the code to run almost as fast as pure C code.</li></ul><p>As the matrix is considerably large, and since we are only interested in retrieving the top 1 million most similar vectors, we process it in batches. For each batch, a subset of vectors is loaded from the disk into memory and passed to the fast_cosine_matrix function. The function computes similarities and returns an array of shape (1,BATCH_SIZE), which contains the similarity scores. Each score, along with its corresponding vector index, is pushed into a <strong>priority queue</strong>. To maintain only the top <em>K</em> results, any insertion that causes the queue size to exceed <em>K</em> results trigger the removal of the lowest similarity score.</p><h3>Computing Recall at K</h3><p>Recall was measured by comparing Milvus results against the ground-truth top K results, ensuring that Milvus retrieved a significant proportion of the most relevant vectors. This step validated the efficiency and accuracy of each configuration.</p><p><strong>Results</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*EV7xh1NoOU0HAPXd" /><figcaption>Ratio common URLs between Milvus topk and Ground truth topk</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*4xNjKb7Ra9DbBL6c" /></figure><blockquote>As top k is increasing, some statistical events degrade the quality of the recall</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*H9usKpzM7ojNNC2X" /></figure><ul><li>Increasing the <strong>m</strong> parameter significantly boosts recall, but it comes at the cost of higher memory usage, which doubles with each increment of <strong>m, </strong>as theoretically expected.</li><li>Raising the <strong>nlist</strong> value slightly reduces recall but greatly decreases search time up to a certain threshold. Beyond this point, further increasing <strong>nlist</strong> becomes inefficient and yields diminishing returns.</li></ul><h3>Conclusion</h3><p>At Weborama, we have developed an automated benchmarking system to identify the optimal parameters for our use case, balancing recall and cost effectively. As demonstrated in this article, this system allows us to fine-tune configurations dynamically and perform regular evaluations to ensure our parameters continue to deliver high-quality results.</p><h3>Next Steps</h3><p>We plan to extend our testing to datasets containing 100 million and 1 billion vectors to analyze how parameter configurations need to adapt as dataset size scales up.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e0932387034" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weborama/vector-database-benchmark-indexing-parameters-7e0932387034">Vector Database: Benchmark indexing parameters</a> was originally published in <a href="https://medium.com/weborama">Weborama</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>