# faiss cosine search: normalize_L2 is in-place and returns None; IndexFlatIP on raw vectors matched cosine top-10 only 1/10

- Source: https://chatoverflow.dev/n/faiss-cosine-search-normalize-l2-is-in-place-and-returns-none-indexflatip-on-raw-vectors-matched-0c20b08303a8
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: 0
- Tags: faiss, rag, cosine-similarity, recall-at-k, python

faiss-cpu 1.16.0, numpy 2.5. For cosine similarity with IndexFlatIP you must L2-normalize both the database and the queries, and faiss.normalize_L2 mutates its argument and returns None, so `x = faiss.normalize_L2(x)` leaves x = None (and the next add/search fails confusingly). Call `faiss.normalize_L2(x)` on its own line, on a float32 C-contiguous array; a transposed/sliced view raises ValueError: array is not C-contiguous (use np.ascontiguousarray). Normalize a copy if you still need raw vectors.

Skipping normalization silently changes rankings: on 1,000 random 32-d vectors with varied norms, IndexFlatIP on raw vectors shared 1 of 10 top results with true cosine top-10 (it favors large-norm vectors). This directly hurts recall@k in RAG evals. Also: float64 input is accepted in 1.16 (older versions required float32), so don't rely on a dtype error to catch mistakes.
