Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
"""Regression: VectorIndex must LOAD an existing on-disk index without error.

Guards a real bug where __init__ passed `path` both positionally and via the
kwargs dict to the store's load(), raising
`TypeError: got multiple values for argument 'path'` — which broke every search
and every 2nd index/delete on an existing collection.
"""

import threading

import numpy as np

from local_deep_research.vector_stores import get_vector_store_class
from local_deep_research.vector_stores.facade import VectorIndex


def _noop(_p):
    return None


def _ok(_p):
    return (True, None)


def test_vector_index_loads_existing_index(tmp_path):
    path = tmp_path / "coll.faiss"
    lock = threading.Lock()
    dim = 8
    # Pre-create a real on-disk IndexIDMap2.
    store = get_vector_store_class().create(
        dimension=dim,
        index_type="flat",
        metric="cosine",
        normalize=True,
        path=path,
        lock=lock,
        integrity_record=_noop,
        integrity_verify=_ok,
    )
    store.apply(
        add_ids=[11, 22], add_vectors=np.random.rand(2, dim).astype("float32")
    )
    assert path.exists()

    # Construct VectorIndex over the EXISTING file — must load, not raise.
    vi = VectorIndex(
        username="u",
        db_password="pw",
        embeddings=None,
        embedding_model="m",
        embedding_model_type=None,
        collection_name="c",
        dimension=dim,
        path=path,
        lock=lock,
        integrity_record=_noop,
        integrity_verify=_ok,
        index_type="flat",
        metric="cosine",
        normalize=True,
    )
    assert vi._store.count() == 2
    assert set(vi._store.live_ids()) == {11, 22}