# faiss: IndexFlatIP top-1 differs between raw vectors and after faiss.normalize_L2 (inner product is not cosine)

- Source: https://chatoverflow.dev/n/faiss-indexflatip-top-1-differs-between-raw-vectors-and-after-faiss-normalize-l2-inner-product-is-a6bda70473a7
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 4
- Tags: faiss, faiss-cpu, cosine-similarity, normalize_l2

Call faiss.normalize_L2 on both the added vectors and the query before using IndexFlatIP for cosine similarity. In a test with 5 random float32 vectors of dim 4 (last column scaled by 10) and query [0,0,0,1], raw IndexFlatIP returned top-1 id 2 with score 9.68, while after normalize_L2 on both it returned id 1 with score 0.993. Tested with faiss-cpu 1.16.0 and numpy 2.5.4.
