This project is entirely coded by LLM agents. It is an experiment to learn how to use those.
A local-first research library that unifies a Firefox bookmark collection, a Zotero academic library, a Calibre ebook collection, and an unstructured images folder into a single semantically indexed, searchable knowledge base.
Inference runs through swappable providers — on-device via Ollama by default, or against a hosted endpoint when the local machine cannot run a model large enough to be useful.
Alexandria is local-first, not local-only: the default configuration keeps your library contents and your queries on the machine, and every outbound path is a separate named setting that is off until you turn it on. Nothing phones home, and there is no telemetry or analytics in any configuration. See DESIGN.md §1.1 for the network-access policy and what crosses the wire in each case.
pka/ # Python backend
├── config.py # Pydantic settings (ALEXANDRIA_ env prefix, .env supported)
├── constants.py # Source, FetchStatus, TagOrigin enums
├── pipeline.py # _ingest_text_block + per-source ingestion funcs
├── cli/ # `alexandria` CLI (init, sync, clustering, purge, …)
├── db/ # SQLAlchemy Core schema + queries
├── connectors/ # zotero, firefox, calibre, images
├── ingestion/ # chunker, fetcher, extractors, image_pipeline
├── storage/ # ChromaDB wrapper
├── clustering/ # UMAP + HDBSCAN engine + lifecycle (drift/merge)
└── api/ # FastAPI app (routers + Pydantic schema modules)
scripts/ # thin shims around pka/cli for repo-local runs
tests/ # pytest suite; conftest mocks Ollama, Chroma, HTTP
frontend/ # Vue 3 + Vite + Pinia
├── index.html
├── package.json, vite.config.ts, tsconfig.json
└── src/
├── main.ts, router.ts, App.vue
├── api/client.ts # typed fetch wrappers (timeout + ApiError)
├── stores/ # search, clusters, ingestion, ui, toast
├── views/ # routed views
├── components/ # AppSidebar, DocCard, DocDetailPanel, ScatterPlot, …
└── styles/global.css
# Python 3.11+
pip install -e .
# Optional extras
pip install -e '.[dev]' # pytest, ruff, mypy
# Database — idempotent, safe to re-run
alexandria init # or: python scripts/init_db.py
# Frontend
cd frontend
npm installInstalling the package provides the alexandria console command (also
runnable as python -m pka.cli). The scripts/ files are thin shims kept
for python scripts/<name>.py workflows; both forms run the same code.
System prerequisites:
- Ollama for clustering labels and image vision (
ollama pull llavaor your chat model). Text chunk embeddings run locally throughsentence-transformers(ALEXANDRIA_EMBEDDING_MODEL, defaultintfloat/multilingual-e5-small, downloaded on first use). An archive built before the setting keepsall-MiniLM-L6-v2untilalexandria reembedmoves it to the configured model. - Ollama Cloud (optional) runs bigger models than the machine fits, without
the prompts touching a third-party aggregator. Two routes, both per-capability
so chat can go remote while OCR and embeddings stay local:
- Through the local daemon —
ollama signin,ollama pull gpt-oss:120b-cloud, then setALEXANDRIA_CHAT_MODEL=gpt-oss:120b-cloud. Provider staysollama. - Direct to ollama.com — set
ALEXANDRIA_CHAT_PROVIDER=ollama_cloud(and/or_VISION_PROVIDER), an API key from https://ollama.com/settings/keys asSECRET_ALEXANDRIA_OLLAMA_CLOUD_API_KEY, andALEXANDRIA_OLLAMA_CLOUD_CHAT_MODEL(no-cloudsuffix on this route). No local daemon needed.
- Through the local daemon —
- Reddit reads your saved posts through the private feed URL from
https://www.reddit.com/prefs/feeds/ — no app registration, which currently
needs an API-access clearance personal accounts do not get. Paste either the
RSS or the JSON form into
SECRET_ALEXANDRIA_REDDIT_FEED_URLin.secrets; either is normalised to the Atom (.rss) endpoint, the only one Reddit serves to automated clients. That URL grants read access to your saved list: treat it like a password. This feed URL is the only credential the connector takes — the OAuth API (praw) route has been removed, since the "script" app it needs is no longer obtainable. Every poll is archived todata/reddit/<timestamp>/(the raw feed pages, plus a manifest) and merged intodata/reddit/saved.jsonl, which holds one deduplicated line per saved item;alexandria reddit --from-archivere-ingests from that log with no network access, for when the token dies or the database has to be rebuilt. Turn the archive off withALEXANDRIA_REDDIT_ARCHIVE_ENABLED=0. - Image OCR runs through the vision model by default (
ocr_provider=vlm, no extra install). Setocr_provider=easyocrto use the bundled EasyOCR backend instead — a pip dependency (no system binary); its recognition models download on first use. - Scanned PDFs (Calibre books and Zotero attachments with no text layer) are
marked
no_text_layerand OCR'd byalexandria ocr-scans, off by default (ALEXANDRIA_PDF_OCR_ENABLED=1). Two backends, chosen byALEXANDRIA_PDF_OCR_BACKEND:easyocr(default) — local, no extra install. About 20 s a page on CPU and weak on symbols and numbers; setALEXANDRIA_PDF_OCR_MAX_PAGESto bound a run.pdfcraft— pdf-craft sending each page image to a hosted DeepSeek-OCR 2 endpoint: far better text, maths as LaTeX, a few seconds a page. Page images leave the machine. Install it without PySide6, which it needs only to write text back into PDFs:pip install --no-deps pdf-craft==2.4.1thenpip install -e '.[pdfocr]'(pip checkwill then report PySide6 missing; that is expected). Configure any OpenAI-compatible endpoint serving the model, e.g. Novita:ALEXANDRIA_PDF_OCR_BASE_URL=https://api.novita.ai/v3/openai,ALEXANDRIA_PDF_OCR_MODEL=deepseek/deepseek-ocr-2, and the key asSECRET_ALEXANDRIA_PDF_OCR_API_KEYin.secrets. At Novita's October 2026 price that came to about $0.06 per 1,000 pages. Each OCR'd scan also gets a searchable PDF — the untouched page images with the text as an invisible layer — written by OCRmyPDF from the same OCR result (pip install -e '.[pdflayer]'; no Tesseract or Ghostscript needed). By default it is a copy under the data dir, opened from the document's detail panel. SetALEXANDRIA_PDF_OCR_OUTPUT=replaceto write it over the Calibre / Zotero file instead, so their search finds it too: the original is saved underdata_dir/ocr_originals/first, andalexandria ocr-scans --restore <id>(or--restore-all) puts it back.ALEXANDRIA_PDF_OCR_TEXT_LAYER=0turns the PDF off.
- CLIP visual search is off by default (
ALEXANDRIA_CLIP_ENABLED=1to turn it on). With it off, no image embedding pass runs and no CLIP model is downloaded; images are still searchable through the text the pipeline infers from them (per-type content extraction + description + OCR), which is indexed alongside every other document. Turn it on for purely visual queries whose words appear nowhere in that text./images/searchacceptsmode=hybrid|clip|textand reports which path matched each hit. - Image admission gate (on by default) filters incoming images before the
expensive passes: an image is kept only if EasyOCR finds it is at least 5%
text and a fast VLM (Ollama
moondreamby default) classifies it into a category of interest. Rejected paths are cached in theimage_rejectionstable and skipped on later runs. Tune withALEXANDRIA_IMAGE_GATE_*(see.env.example) or bypass per-run withalexandria images --skip-gate.
alexandria zotero
alexandria firefox # metadata + async fetch + embed
alexandria calibre --fulltext
alexandria imagesCommon flags across the subcommands: --dry-run, --force-reindex. See
alexandria <command> --help for the full set.
alexandria ocr-scans --dry-run # queued scans and their page counts; reads nothing
alexandria ocr-scans --source zotero
alexandria ocr-scans --limit 5 --max-pages 50
alexandria ocr-scans --layer-only # searchable PDFs for scans OCR'd without one
alexandria ocr-scans --restore 1234 # undo one: original back, or copy deletedThe same pass runs from the app: the Ingestion page's Scanned PDFs panel shows how many scans are waiting, starts the run in the background, and reports progress per document with a Stop button.
alexandria domain-report # domains by frequency (prioritize fetch handlers)
alexandria domain-report --source firefox --limit 50
alexandria domain-report --rejected # sorted by unfetchable count insteadSwapping an embedding or summarisation backend does not mean re-ingesting
everything. alexandria purge clears one kind of artifact — leaving the
expensive fetched text, and your own tags and reading lists, in place.
alexandria purge --list # targets, and what regenerates each
alexandria purge summaries --dry-run # counts first; nothing is deleted
alexandria purge summaries --source firefox # or scope it to one connector
alexandria purge vectors # then alexandria reembedBefore this release every Calibre ingest appended another copy of each book's
full-text and summary chunks. duplicate_chunks removes the extra copies and
keeps the first, and only where a document's runs are exact repeats:
alexandria purge duplicate_chunks --dry-run # how many documents and chunks
alexandria purge duplicate_chunksSummaries record which model made them, so swapping a backend does not mean discarding the work you are keeping:
alexandria purge --runs # what ran, when, at what cost
alexandria purge summaries --model qwen2.5:3b # only the old model's work
alexandria purge summaries --unknown # only the unstamped backlogA target whose artifact carries no stamp rejects those filters rather than quietly purging everything.
Clearing an artifact is usually the whole re-trigger: the next sync regenerates whatever is missing. Summaries are the exception — their skip gate is "does this document have chunks", which stays true — so they get an explicit pass:
curl -X POST 'localhost:8420/ingestion/enrich?kind=summary'The body text of anything fetched or extracted is kept verbatim
(document_texts, setting retain_document_text, default on), so changing the
chunker can be applied to documents already in the archive without fetching a
single URL again (an embedding-model change needs only alexandria reembed,
which re-embeds the chunks as they are):
alexandria rechunk --dry-run # how many documents have retained text
alexandria rechunk --source firefox # re-cut with the current chunker settingsIt replaces body chunks and their vectors only; a generated summary, an external synopsis and Calibre's metadata pass are left alone. Documents ingested before retention shipped have no stored text — there is no backfill — so they are skipped until something re-fetches them.
Books are the exception to keeping text whole: Calibre full text is retained
only to its first ALEXANDRIA_BOOK_RETAIN_MAX_PAGES pages (20), since a
several-hundred-page PDF is the only thing that makes this cost real disk and
the file is still on disk anyway. Those documents are skipped by rechunk —
re-cutting a prefix would shrink the index to it — so re-run the full-text pass
for them instead. Fetched pages are never capped. GET /documents/{id}/text serves a
retained body back, which is also how to see what the fetcher actually got when
a page ingests badly.
alexandria purge-source <source> remains the blunt instrument: it removes a
whole connector's documents. It now keeps manually-applied and learned tags plus
reading-list entries, since re-ingesting cannot recreate those; pass
--include-user-data to delete them too.
alexandria clustering # creates a stored, unaccepted run
alexandria clustering --accept # accept it immediately
alexandria clustering --drift # drift report on the active run
alexandria clustering --merges # merge candidates on the active run
alexandria clustering --assign-new # assign new docs to existing clusters# Dev: one command starts both, streams both logs, and opens the browser
alexandria devThis runs uvicorn --reload (port 8421) and npm run dev (port 5173)
together in one terminal and opens http://localhost:5173 once the frontend
is ready. Ctrl+C (or closing the window) stops both, and if either server
doesn't come up within 15s (e.g. the port is already taken by something
else) the command reports that and shuts everything down instead of leaving
a half-working stack running. On Windows, double-clicking
scripts/run_dev.bat does the same — useful as the
target of a Desktop shortcut.
Equivalent manual two-terminal form, if you want the processes' logs kept separate:
# Terminal 1: backend with CORS enabled (frontend on :5173 talks to backend on :8421)
ALEXANDRIA_DEV=1 uvicorn pka.api.main:app --reload --port 8421
# Terminal 2
cd frontend && npm run dev# Production: build the frontend, drop CORS, mount /dist at the API root
cd frontend && npm run build
uvicorn pka.api.main:app --port 8420The build output ships to frontend/dist. The FastAPI app mounts that
directory at / automatically when it exists, so a single uvicorn process
serves both API and UI.
pytest
pytest --cov=pka --cov-report=term-missingAll external calls (Ollama chat/vision, ChromaDB, HTTP) are mocked at the module
boundary by fixtures in tests/conftest.py. No real services are touched.
Frontend unit tests (Vitest, pure TS helpers):
cd frontend && npm run testAll settings can be overridden via the ALEXANDRIA_ environment-variable prefix or
a .env file. See .env.example for the full list. Once the app is running,
/settings shows what the current process actually resolved — provider,
model, endpoint and credential presence per capability (with a reachability
check for local/remote backends), plus every other setting grouped and marked
where it differs from its default. It is read-only; .env / .secrets remain
the way to change anything.
DESIGN.md is the living design specification (data flow, provider layer,
instructions for adding a new source connector). The original design document
is archived at docs/archive/initial_design.pdf;
it records the project's initial intent and is superseded wherever it disagrees
with DESIGN.md. The audit pass that produced v0.2.0 is
recorded in CHANGELOG.md.
Note on naming: the Python package is pka (Personal Knowledge Archive, the
project's original name); "Alexandria" is the user-facing brand. The
ALEXANDRIA_ env prefix and the alexandria CLI follow the brand.