index.search returns some IDs of -1, and I don't know how to get from the returned numbers back to my original documents.
Why this happens
FAISS stores vectors only. It assigns them positions 0, 1, 2, ... in the order you added them, and returns those positions. It returns -1 when it can't find enough results: when k is larger than the number of vectors in the index, or, for IVF indexes, when the clusters it searched contain fewer than k vectors.
Answer 1: Keep a list in the same order as the index
The simplest approach is to keep your documents in a list, in the same order you added the vectors:
index.add(doc_vecs) # vectors for documents[0], documents[1], ...
D, I = index.search(q, 5)
results = [documents[i] for i in I[0] if i != -1]
Filtering out -1 is important. Otherwise Python's negative indexing silently returns the last document.
