# One crawl, three vector stores: code for "Best Vector Database for RAG"

Everything ran in Docker on 2026-11-21 (Docker 24.0.6, linux/arm64): the scripts in a `python:3.12-slim` runner,
the stores in their own containers on a user-defined network `ragvdb`. No host ports were published.
Each `*.out` file is the raw output of the script with the same name.

## Run order

1. `./setup.sh`: network, model cache volume, `ragvdb-pg`, `ragvdb-qdrant`, `ragvdb-chroma`, runner image (`Dockerfile` + `requirements.txt`).
2. `./versions.sh` -> `versions.out` (image digests, Postgres/pgvector/Qdrant versions, Python, pip freeze; same list in `pip-freeze.txt`).
3. `./crawl.sh` (runs `crawl.py`, needs `WEBCRAWLERAPI_API_KEY` exported; `YOUR_API_KEY` in docs) -> `crawl.out`, writes `pages/*.md`.
4. `questions.json`: 12 questions with exact expected URLs, written from the crawled URL list before any retrieval ran.
5. `./run.sh chunk_embed.py` -> `chunk_embed.out`, writes `chunks.jsonl`.
6. `./run.sh load_all.py` -> `load_all.out` (pgvector, Chroma and four Qdrant configurations from the same file).
7. `./run.sh test_filter_topk.py` -> `test_filter_topk.out` (Test 1, selective filter, k=5, with EXPLAIN).
8. `./run.sh test_hybrid.py` -> `test_hybrid.out` (Test 2, exact terms, plus how each engine tokenises them).
9. `./run.sh test_tenants.py` -> `test_tenants.out` (Test 3, two synthetic tenants).
10. `./run.sh test_answers_replace.py` -> `test_answers_replace.out` (hit@1/hit@5, replace by URL). Mutates the stores: run it last.
10b. `./run.sh test_hybrid_wide.py` -> `test_hybrid_wide.out` (Test 2 wide: 20 exact-term queries from `queries_wide.json`, i.e. all 13 error codes from the errors page plus 7 API parameters; hit@1/hit@5 per method and which queries flipped). `queries_wide.json` was written before any retrieval. Run in a second session on 2026-11-21 against rebuilt containers loaded from the same `chunks.jsonl` (same sha256); no new crawl. In that session `test_hybrid.py` gave the same ranks as `test_hybrid.out`, and one tie in a top-3 list (`/docs/api/markdown` vs `/docs/api/markdown-content`) came back in swapped order.
11. `./run.sh inspect_misses.py` -> `inspect_misses.out` (what came back for the two hit@5 misses).
12. Gotchas: `./run.sh gotcha_prepared_plan.py` -> `gotcha_prepared_plan.out`, `./run.sh gotcha_qdrant_indexed_count.py` -> `gotcha_qdrant_indexed_count.out`.
13. `./loc.sh` -> `loc.out` (non-blank lines per adapter and for `common.py`).
14. `./teardown.sh`.

Shared harness: `common.py`. Adapters with the same functions (`setup`, `upsert`, `search`, `replace_url`, `count`, plus
`hybrid` / `keyword`): `store_pgvector.py`, `store_qdrant.py`, `store_chroma.py`.

## Versions

- `pgvector/pgvector:0.8.7-pg17` (PostgreSQL 17.12, extension 0.8.7), `sha256:b513c48566e4777cd3370451400000c78eda6a08131d68f4c31d4a76f27bd8fd`
- `qdrant/qdrant:v1.20.2`, `sha256:d277592721d2e3b73f9b797b53cf05e6a5bb2134f6d13fdbda4ca51782afbcac`
- `chromadb/chroma:1.5.9`, `sha256:1e0b73a187a28757c572acba508c46f48c9e8b0acaf5c20e6d95cdedce1acdf6` (its `/api/v2/version` answers `1.0.0`)
- `python:3.12-slim` (Python 3.12.16), `sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b`
- `webcrawlerapi` 2.1.8, `fastembed` 0.9.1, `psycopg[binary]` 3.3.9, `pgvector` 0.5.1, `qdrant-client` 1.20.0, `chromadb-client` 1.5.9 (all latest on PyPI on the run day)
- Embeddings: `BAAI/bge-small-en-v1.5` (384 dims) and `Qdrant/bm25` sparse, both via fastembed inside the runner. Model cache: 65 MB in the `ragvdb-models` volume.

## Crawl and chunk stats

- Crawl of `https://webcrawlerapi.com/docs`, `items_limit=60`, `max_age=0`, `main_content_only=True`, `respect_robots_txt=True`:
  54 pages done, 0 failed, summed item cost $0.1080, 65.1 s wall time. The job response carried `recommended_pull_delay_ms`.
- 486 chunks (heading split, 1,500-character cap), median 7.5 and max 28 chunks per page. Embedding took 38.6 s including model load.
- Selective filter for Test 1: `section = "guides"`, 19 of 486 chunks (3.9%).

## Inputs NOT included

- `pages/` (54 markdown files, 348 KB; sha256 of `cat pages/*.md`: `e4a249dab8af2c0a6bbeade30bbf753d0f8f32685f869e03c0ff77d52eab3b0a`).
- `chunks.jsonl` (486 rows, 2.6 MB with dense and sparse vectors; sha256 `cd5790f8a41a7f2f8f75554a31de1e32d226b2a002c332209d58e13a0a7048b0`).
  Fields: id, url, section, topic, heading, text, embedding, sparse, model, dim.
- Rebuild both with steps 3 and 5. A fresh crawl returns the docs as they are on that day, so counts can differ.

## Notes on the outputs

- `chunk_embed.out`: the Hugging Face download progress bars and the "unauthenticated requests" warning from the first model download were removed. Nothing else was edited in any `.out` file.
- `test_filter_topk_autoprepare_bug.out` is an earlier, discarded Test 1 run. psycopg had auto-prepared the query, so the "planner defaults" row kept the forced HNSW plan (1/5 results) while EXPLAIN showed a seq scan. The adapter now connects with `prepare_threshold=None`; `gotcha_prepared_plan.py` reproduces the effect on purpose.
- The Postgres password is generated by `setup.sh` and read from the container at run time. The `kb_reader` role password in `test_tenants.py` is generated at run time too. Neither appears in any file.
