#7758·chroma

[错误]: 在删除和插入操作后,通过 query() 无法访问实时记录,而 get() 仍然返回这些记录(1.5.9)

作者: ltattrah创建于 2026年9月17日更新于 2026年9月17日

Reproducibility: live records unreachable by search in Chroma after heavy deletes/upserts. No vfo dependency. ~1 minute. pip install chromadb numpy && repro_chroma_unreachable.py [seed] Builds the collection, lists live records that a query with their own stored vector does not return (top-100 and top-1,000), then reopens the store in a fresh process and checks again. The affected records differ between runs even with the same seed (index construction is not deterministic), so run it a few times. import subprocess, sys, tempfile import chromadb, numpy as np def unreachable(col, k_top): g = col.get(include=["embeddings"]) out = [] for i, e in zip(g["ids"], g["embeddings"]): r = col.query(query_embeddings=[list(e)], n_results=k_top) if i not in r["ids"][0]: out.append(int(i)) return len(g["ids"]), sorted(out) def check(path, label): col = chromadb.PersistentClient(path=path).get_collection("repro") n_live, miss100 = unreachable(col, 100) _, miss1000 = unreachable(col, 1000) print(f"{label}: {n_live} live records; not returned for their own vector: top-100 {len(miss100)} {miss100}, top-1000 {len(miss1000)} {miss1000}", flush=True) for k in miss1000: g = col.get(ids=[str(k)], include=["embeddings"]) print(f" id {k}: get() found={bool(g['ids'])}", flush=True) if len(sys.argv) > 2 and sys.argv[1] == "--check": check(sys.argv[2], "after reopen in a new process") sys.exit(0) seed = int(sys.argv[1]) if len(sys.argv) > 1 else 3 rng = np.random.default_rng(seed) path = tempfile.mkdtemp() col = chromadb.PersistentClient(path=path).get_or_create_collection("repro", metadata={"hnsw:space": "l2"}) n, d = 4000, 32 X = rng.standard_normal((n, d)).astype(np.float32) for i in range(0, n, 500): col.add(ids=[str(j) for j in range(i, i + 500)], embeddings=X[i:i + 500].tolist()) live = set(range(n)) dele = rng.choice(n, n // 2, replace=False) col.delete(ids=[str(int(k)) for k in dele]) live

内容来源: chroma-core/chroma