Scrivio Interview library
DebuggingIntermediate7 min read · updated 13 November 2026

A team loaded 8 million 1536-dimension embeddings into a Redis HNSW index. Memory reached about 70 GB, the build took hours, and query latency during the nightly re-ingestion rose from 5 ms to 90 ms.

Explain where the memory and the latency come from, and what you would change.

Most of the 70 GB is the vectors themselves: 8 million x 1536 x 4 bytes is about 49 GB, and the HNSW neighbour lists, the chunk text and the per-key overhead add the rest. The latency comes from building the graph, which is CPU-heavy and runs on the same server that answers queries. We reduce size with fewer dimensions, 16-bit floats and a smaller M, stop re-ingesting everything by updating only changed chunks or building a new index and switching with FT.ALIASUPDATE, and measure recall before and after each change.

Why this question is asked

Vector search in Redis is easy to start and surprisingly expensive to scale, because every vector lives in RAM and every insert reshapes a graph. Teams often discover this the way this one did: a memory bill far above the raw data they expected, and a nightly job that slows every user query. Interviewers ask it to see whether we can do the arithmetic, explain where CPU goes during an index build, and change the system without quietly making answers worse. In this answer, we will account for the 70 GB, explain the latency during re-ingestion, then look at the size reductions, the safer ingestion pattern and the recall check that keeps us honest.

1A Quick Recap of How an HNSW Index Holds Data

An HNSW index keeps every vector in memory together with a graph: for each vector, a list of links to some of its nearest neighbours. Most nodes exist only on the bottom layer, where each keeps up to 2 x M links (32 with the default M of 16); a small fraction also appear on upper layers that let a search jump across the graph quickly. A query starts at the top and walks towards closer vectors layer by layer.

Inserting a vector is not just appending it. The index must search the graph for that vector's neighbours, using EF_CONSTRUCTION candidates, and then update the neighbour lists of those neighbours. Each insert is therefore a small search plus some rewiring, and that is CPU work.

2Where the 70 GB Comes From

Let us do the arithmetic. One 1536-dimension FLOAT32 vector is 1536 x 4 = 6,144 bytes. Times 8 million, that is 49,152,000,000 bytes, about 49 GB, before any graph or text. The graph adds, for each node, about 32 neighbour ids of 4 bytes at the bottom layer plus upper layers and bookkeeping, roughly 150 to 300 bytes, which is 1 to 2.5 GB in total. The chunk text, say 1.5 KB per chunk, adds about 12 GB, and the hash itself, its field names and the key add some tens of bytes more each.

Text
Vectors 8,000,000 x 1536 x 4 B = 49.2 GB
HNSW graph 8,000,000 x ~250 B = 2.0 GB (grows with M)
Chunk text 8,000,000 x ~1.5 KB = 12.0 GB
Keys, hash and index overhead ~ 4 to 7 GB
Total ~ 70 GB
Memory breakdown for 8 million chunks
PartApproximate sizeWhat changes it
Vectors (FLOAT32, 1536 dims)49 GBdimensions, element type
Chunk text and hash overhead16 to 19 GBchunk size, storing text elsewhere
HNSW neighbour lists1 to 2.5 GBM

The exact split varies by version, and some versions keep a copy of each vector inside the index in addition to the one in the hash, so measure rather than guess: FT.INFO idx:chunks reports the index's own memory, including the vector index, and MEMORY USAGE on a few sample keys shows the per-document size. The lesson is that the vectors dominate, so that is where savings must come from.

3Why Queries Slow Down During Re-ingestion

During the nightly job, 8 million inserts each search the graph and rewire neighbours. That keeps CPU cores busy for hours, and those are the same cores and memory bandwidth that serve user queries. Queries also walk parts of the graph that are being modified, so they wait for locks or do more work. The jump from 5 ms to 90 ms is what CPU contention looks like from the outside.

Re-ingesting everything is also wasteful: most chunks did not change since yesterday, so the job spends hours rebuilding an index that was already correct.

4Making the Index Smaller

Fewer dimensions give the biggest win. Many current embedding models can produce shorter vectors, for example 768 or 512 dimensions instead of 1536, with a small loss in quality. At 768 dimensions the vectors take 24.6 GB instead of 49 GB. Smaller elements give a second win: Redis 7.4 and later accept FLOAT16 and BFLOAT16 vectors, which halve the size again, and newer releases add further compressed options, so check what your version supports. Together, 768 dimensions at 16 bits come to about 12 GB.

A lower M, say 8 instead of 16, shrinks the graph and speeds up inserts, but the graph saving is small compared with the vectors, and recall usually drops, so it is the last knob to turn. Finally, the chunk text does not have to sit in Redis at all; it can stay in the document store and be fetched by id for the five chunks we return.

5Avoiding Full Re-ingestion

The first fix is to re-ingest only what changed. If the pipeline keeps a hash of each chunk's text, it re-embeds and rewrites only chunks whose hash differs, and deletes chunks that disappeared. On a typical night that is a few percent of 8 million, not all of them.

When a full rebuild is truly needed, for example after changing the embedding model, we build a new index next to the old one and switch atomically with an alias. Queries always use the alias, so they never see a half-built index.

Text
FT.CREATE idx:chunks_v2 ON HASH PREFIX 1 chunkv2: SCHEMA tenant TAG
embedding VECTOR HNSW 6 TYPE FLOAT16 DIM 768 DISTANCE_METRIC COSINE -- OK
-- load chunkv2:* keys gradually, off-peak, watching query latency
FT.INFO idx:chunks_v2 -- percent_indexed 1, num_docs 8000000
FT.ALIASUPDATE chunks idx:chunks_v2 -- OK: queries on 'chunks' now use v2
-- after a safe period, delete the chunk:* keys and drop idx:chunks
Step throughSwitching to a rebuilt index
  1. Create idx:chunks_v2 on a new prefix
  2. Load changed and new vectors at a paced ratewatch p99 latency
  3. Recall on the test set acceptable?
    YesContinueNoStop and adjust M or dimensions
  4. FT.ALIASUPDATE chunks idx:chunks_v2instant switch for readers
  5. Delete old keys, drop old indexmemory returns

5 steps in order. Play them, or step through them one at a time.

During the build we pace the loader, with a rate limit tied to query latency, so user queries keep their budget. Note that both versions exist in memory until the old keys are deleted, so the switch needs headroom, or a separate Redis deployment for the new index.

6Measuring Recall So Savings Do Not Cost Quality

Every change above can lower recall, the share of the true nearest neighbours that the index actually returns. So we keep a test set of a few thousand real questions, compute the exact top 10 for each with a FLAT index or brute force on a sample, and compare the HNSW top 10 with it. Recall at 10 of 0.95 means 95 percent of the true neighbours were found. We record it before the change and after each step, and we also check a handful of end-to-end answers, since retrieval quality is what users feel.

7Follow-up questions

How would you size shards for 50 million vectors?

Start with the arithmetic: at 1536 FLOAT32 dimensions the vectors alone are 307 GB; at 768 dimensions and 16 bits they are about 77 GB. Add graph and overhead, then keep each shard well below its memory, for example 20 to 25 GB of data on a node with 64 GB, which suggests four to six shards for the compact version, each with a replica. Also check that your deployment can run a search index across shards; otherwise partition by tenant in the application so each query hits one shard.

Does raising EF_RUNTIME help the latency problem?

No, it makes each query visit more nodes, so latency rises. It is the knob to raise recall after we have reduced M or the dimensions, and we tune it with the same recall test.

Could we pause queries during the nightly build instead?

We could route them to a replica or a second deployment while the primary builds, which is a variation of building on the side. Pausing search outright is rarely acceptable for a support assistant.

8Conclusion

In this answer, we accounted for the 70 GB: about 49 GB of raw FLOAT32 vectors, plus chunk text, overhead and the HNSW neighbour lists that grow with M. We saw that building HNSW is CPU-heavy and competes with queries, which explains the latency during re-ingestion. We reduced size with fewer dimensions, 16-bit floats and moving text out, stopped re-ingesting unchanged chunks, rebuilt on the side and switched with FT.ALIASUPDATE, and measured recall against exact results at every step.

What to say in the interviewAbout 80 seconds aloud

Open with

First I would do the arithmetic. Eight million vectors of 1536 float32 values are about 49 gigabytes on their own. On top of that the HNSW graph keeps neighbour lists for every node, which grow with M, and the hashes hold chunk text and per-key overhead, so 70 gigabytes is plausible.

Then, if they want more

I would confirm the split with FT.INFO and MEMORY USAGE on sample keys. The latency comes from the build: every HNSW insert is a search plus rewiring of neighbour lists, so re-ingesting 8 million chunks keeps the CPU busy for hours on the same server that answers queries.

To reduce memory I would use fewer dimensions, for example 768 from the same model family, and FLOAT16 if our version supports it, which together cut the vectors to about 12 gigabytes; I would also move chunk text out of Redis, and lower M only if recall allows.

To fix the nightly job I would re-embed only chunks whose content changed, and for a real rebuild create a new index on new keys, load it at a paced rate, and switch readers with FT.ALIASUPDATE.

Throughout, I would measure recall at 10 against exact search on a fixed set of questions, so the savings do not quietly make the assistant worse.

About this answer

Last updated
13 November 2026
Versions it names
Redis 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain where the memory and the latency come from, and what you would change.": https://scrivio-interview-library.netlify.app/databases/redis-patterns/88ae63b7af/