diff --git a/examples/dynamic_update_no_recompute.py b/examples/dynamic_update_no_recompute.py index 6ab70fb..761375d 100644 --- a/examples/dynamic_update_no_recompute.py +++ b/examples/dynamic_update_no_recompute.py @@ -43,7 +43,11 @@ from apps.chunking import create_text_chunks REPO_ROOT = Path(__file__).resolve().parents[1] DEFAULT_QUERY = "What's LEANN?" -DEFAULT_INITIAL_FILES = [REPO_ROOT / "data" / "2501.14312v1 (1).pdf"] +DEFAULT_INITIAL_FILES = [ + REPO_ROOT / "data" / "2501.14312v1 (1).pdf", + REPO_ROOT / "data" / "huawei_pangu.md", + REPO_ROOT / "data" / "PrideandPrejudice.txt", +] DEFAULT_UPDATE_FILES = [REPO_ROOT / "data" / "2506.08276v1.pdf"] diff --git a/packages/leann-backend-hnsw/third_party/faiss b/packages/leann-backend-hnsw/third_party/faiss index ed96ff7..1d51f0c 160000 --- a/packages/leann-backend-hnsw/third_party/faiss +++ b/packages/leann-backend-hnsw/third_party/faiss @@ -1 +1 @@ -Subproject commit ed96ff7dbaea0562b994f8ce7823af41884b1010 +Subproject commit 1d51f0c07420808a18f85a4db6636fd25e4a1daa diff --git a/packages/leann-core/src/leann/api.py b/packages/leann-core/src/leann/api.py index e90c305..bf25666 100644 --- a/packages/leann-core/src/leann/api.py +++ b/packages/leann-core/src/leann/api.py @@ -730,6 +730,7 @@ class LeannBuilder: index = faiss.read_index(str(index_file)) if hasattr(index, "is_recompute"): index.is_recompute = needs_recompute + print(f"index.is_recompute: {index.is_recompute}") if getattr(index, "storage", None) is None: if index.metric_type == faiss.METRIC_INNER_PRODUCT: storage_index = faiss.IndexFlatIP(index.d) @@ -818,7 +819,12 @@ class LeannBuilder: f"{actual_port}; expected {requested_zmq_port}. Make sure the desired ZMQ port is free." ) - index.add(embeddings.shape[0], faiss.swig_ptr(embeddings)) + if needs_recompute: + for i in range(embeddings.shape[0]): + print(f"add {i} embeddings") + index.add(1, faiss.swig_ptr(embeddings[i : i + 1])) + else: + index.add(embeddings.shape[0], faiss.swig_ptr(embeddings)) faiss.write_index(index, str(index_file)) finally: if server_started and server_manager is not None: