My embeddings come from NumPy or PyTorch, and FAISS rejects them with a cryptic TypeError.
Why this happens
FAISS is a C++ library. It expects a NumPy array of 32-bit floats (float32), stored in one continuous block of memory (C-contiguous). NumPy creates float64 arrays by default, PyTorch tensors aren't NumPy arrays, and operations like slicing or transposing can produce non-contiguous arrays. Recent FAISS versions convert some of these automatically in add and search, but older versions and helper functions like faiss.normalize_L2 do not.
Answer 1: Convert to a contiguous float32 array
This one line fixes almost every FAISS type error:
import numpy as np
vecs = np.ascontiguousarray(vecs, dtype="float32")
index.add(vecs)
Do the same for query vectors.
