Skip to content

armgit / LEANN

Public Imported from GitHub
0

[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.

add dynamic add test

yichuan520030910320e2b37914ce4a
diff --git a/examples/dynamic_update_no_recompute.py b/examples/dynamic_update_no_recompute.py
index 8641d38..84362dc 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 07d8373..0c18526 100644
--- a/packages/leann-core/src/leann/api.py
+++ b/packages/leann-core/src/leann/api.py
@@ -728,6 +728,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)
@@ -760,7 +761,15 @@ class LeannBuilder:
chunk.setdefault("metadata", {})["id"] = new_id
chunk["id"] = new_id
- index.add(embeddings.shape[0], faiss.swig_ptr(embeddings))
+ if needs_recompute:
+ # sequengtially add embeddings
+ 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))
+
+ # index.add(embeddings.shape[0], faiss.swig_ptr(embeddings))
faiss.write_index(index, str(index_file))
with open(passages_file, "a", encoding="utf-8") as f: