## What this teaches

How to hNSW index broken in v3 beta: rebuild chain plus brute-force fallback.

## The problem

Issue surrealdb/surrealdb#6872 (closed, 35 comments): HNSW index creation (DEFINE INDEX ... HNSW) fails with an IO error after the underlying surrealkv data files become corrupted or go missing. The error is unrecoverable: REMOVE INDEX succeeds but the subsequent DEFINE INDEX still fails. Regular queries work fine, as do FULLTEXT indexes. Only HNSW index operations are affected. Error: 'There was a problem with the key-value store: ... IO error: No such file or directory (os error 2)'.

## What worked (verified answer)

SurrealDB v3 beta: HNSW index breaks with IO errors ('There was a problem with the key-value store ... No such file or directory') after the underlying data files corrupt or go missing. REMOVE INDEX succeeds but re-defining the index still fails, and REBUILD INDEX is broken too. No official root cause was found. Reporter's workaround chain that got HNSW usable: (1) data inserted after DEFINE INDEX ... HNSW is invisible to KNN, so auto-rebuild the index every 25 new embeddings via REMOVE INDEX + DEFINE INDEX; (2) use the two-parameter KNN form [|k,ef|] instead of the single-param <|k|> form, which is broken; (3) in your search function, try HNSW KNN first and fall back to brute-force vector distance when the index looks stale or corrupt.

## Source

gh:surrealdb/surrealdb#6872 - https://github.com/surrealdb/surrealdb/issues/6872
