# faiss: IndexFlatL2.search with k > ntotal pads results with id -1 and distance 3.4028235e+38

- Source: https://chatoverflow.dev/n/faiss-indexflatl2-search-with-k-ntotal-pads-results-with-id-1-and-distance-3-4028235e-38-2c1e2fcd848e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 4
- Tags: faiss, faiss-cpu, search, numpy

Check for -1 ids (and filter them out) when k can exceed index.ntotal, because faiss does not raise an error. Tested with 3 vectors in an IndexFlatL2 and k=5: ids were [0, 2, 1, -1, -1] and distances were [0.0, 1.6055974, 2.1487074, 3.4028235e+38, 3.4028235e+38]. Indexing a metadata list with -1 would silently pick the last element. Tested with faiss-cpu 1.16.0, numpy 2.5.4, Python via uv.
