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.

3.9 KB
Raw Blame
"""Assert the actual original CLI workloads in owned, serial child processes."""

import json
import os
from pathlib import Path
import subprocess
import sys

import pytest

from local_deep_research.vector_stores.implementations.segmented_faiss import (
    SEGMENT_VECTORS,
    ORPHAN_SCAN_INTERVAL,
)

# The dedicated performance job selects this integration explicitly. Keeping
# it out of the parallel default lane isolates native RSS and global caches.
pytestmark = [pytest.mark.integration, pytest.mark.timeout(360)]


@pytest.mark.parametrize("index_type", ["flat", "hnsw"])
@pytest.mark.parametrize("workload", ["pdf", "vectors"])
def test_original_workload_has_asserted_bounded_ci_coverage(
    tmp_path, rag_scale_settings, index_type, workload
):
    root = Path(__file__).resolve().parents[3]
    settings = rag_scale_settings
    reports = Path(os.environ.get("LDR_PERF_RAGSCALE_REPORT_DIR") or tmp_path)
    reports.mkdir(parents=True, exist_ok=True)
    report = reports / f"{workload}-{index_type}.json"
    script = (
        "rag_index_workload.py"
        if workload == "pdf"
        else "rag_vector_scale_benchmark.py"
    )
    command = [
        sys.executable,
        str(root / "scripts/ci" / script),
        "--dimension",
        str(settings["dimension"]),
        "--index-type",
        index_type,
        "--max-rss-mib",
        str(settings["max_rss_mib"]),
        "--report",
        str(report),
    ]
    if workload == "pdf":
        command.extend(
            [
                "--documents",
                str(settings["documents"]),
                "--pages",
                str(settings["pages"]),
            ]
        )
    else:
        command.extend(
            [
                "--vectors",
                str(settings["vectors"]),
                "--writes",
                str(settings["writes"]),
                "--chunks-per-document",
                str(settings["chunks_per_document"]),
                "--searches",
                str(settings["searches"]),
                "--verify-known-query",
            ]
        )
    environment = dict(
        os.environ,
        PYTHONPATH=f"{root / 'src'}{os.pathsep}{root}",
        OMP_NUM_THREADS="1",
        OPENBLAS_NUM_THREADS="1",
        MKL_NUM_THREADS="1",
        HF_HUB_OFFLINE="1",
        TRANSFORMERS_OFFLINE="1",
        TOKENIZERS_PARALLELISM="false",
    )
    completed = subprocess.run(
        command,
        cwd=root,
        env=environment,
        capture_output=True,
        text=True,
        timeout=120 if settings["profile"] == "ci" else 300,
    )
    assert completed.returncode == 0, (
        completed.stdout[-4000:] + completed.stderr[-4000:]
    )
    result = json.loads(report.read_text(encoding="utf-8"))
    assert result["dimension"] == settings["dimension"]
    assert result["index_type"] == index_type
    assert result["peak_rss_mib"] <= settings["max_rss_mib"]
    assert result["segments"] >= 2  # CI must really cross a segment boundary.
    assert result["largest_segment_vectors"] <= SEGMENT_VECTORS
    assert result["elapsed_seconds"] > 0
    if workload == "pdf":
        assert result["document_count"] == settings["documents"]
        assert result["pages_per_document"] == settings["pages"]
        assert result["initial_vectors"] > SEGMENT_VECTORS
        assert 0 < result["remaining_vectors"] == result["rebuilt_vectors"]
        assert result["faiss_bytes_written"] > 0
        assert result["metadata_bytes_written"] > 0
    else:
        assert result["initial_vectors"] == settings["vectors"]
        assert result["writes_completed"] == settings["writes"]
        assert result["writes_completed"] > ORPHAN_SCAN_INTERVAL
        assert (
            result["final_vectors"]
            == settings["vectors"]
            + settings["writes"] * settings["chunks_per_document"]
        )
        assert result["searches_completed"] == settings["searches"]
        assert result["known_query_top1_matches"] == 1