fix(faiss): return [[]] for uninitialized index to honor list() contract (#5725)

This commit is contained in:
Bartok
2026-06-22 02:27:06 -04:00
committed by GitHub
parent ce0531a13e
commit 299c423213
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -603,7 +603,7 @@ class FAISS(VectorStoreBase):
List[OutputData]: List of vectors.
"""
if self.index is None:
return []
return [[]]
results = []
count = 0
+14
View File
@@ -285,6 +285,20 @@ def test_list(faiss_instance):
assert result.payload["category"] == "A"
def test_list_uninitialized_index_returns_nested_list(faiss_instance):
# Regression for the List[List[OutputData]] contract: callers (e.g.
# Memory.delete_all) do `vector_store.list(filters=...)[0]`, so an
# uninitialized index must return [[]] (one level deep) and NOT a bare
# [], which would make result[0] raise IndexError on an empty store.
faiss_instance.index = None
results = faiss_instance.list()
assert results == [[]]
# The contract callers rely on: result[0] is the (empty) memory list.
assert results[0] == []
def test_col_info(faiss_instance, mock_faiss_index):
# Mock index attributes
mock_faiss_index.ntotal = 5