Connect Zotero¶
Papers, books and reports belong in Zotero. The
knowledge base keeps a Source page per item, with a pointer to it, and the
kb tool reads the item's metadata and full text on demand. It never writes
to Zotero.
1. Enable the local API¶
In Zotero, open Settings → Advanced and tick Allow other applications
on this computer to communicate with Zotero. kb reads through this
local API while Zotero is running. If a dialog ever asks for write access,
do not grant it.
2. Pin citation keys (recommended)¶
Install Better BibTeX, set a citation-key pattern, and pin all keys, so that they never change and sync to zotero.org.
The citation key names the Source page. It is converted to kebab-case, the source slug:
| Citation key | Source slug | Source page | Citation in pages |
|---|---|---|---|
hoppeProgressiveMeshes1996 |
hoppe-progressive-meshes-1996 |
/sources/hoppe-progressive-meshes-1996.md |
[^hoppe-progressive-meshes-1996] |
The exact key stays in the page's zotero.citekey.
3. Set the data directory (recommended)¶
Add the Zotero data directory to .env:
When both APIs fail (Zotero is closed, and the web API is not configured
or does not answer), kb reads a read-only
snapshot of zotero.sqlite, copied to a temporary directory, and takes full
text from the storage cache (.zotero-ft-cache files).
4. Add a web API key (optional)¶
The web API is a fallback for when Zotero is closed, or on a machine without Zotero.
- At zotero.org/settings/keys, create a key with Allow library access only (read-only).
-
Put it in
.env: -
Put your numeric user id, shown on the same page, in
schema/resources.yaml. It is not a secret:Both ids are numbers;
kb checkreports anything else (H061).
The web API serves full text only for items whose full-text index was synced (Zotero's "Sync full-text content" setting).
kb tries the local API first, then the web API, then the database
snapshot. The web API is also asked when the local API does not know an
item, for example one that has not synced to this computer yet.
Group libraries¶
Set group_id in schema/resources.yaml to read a group library. All three
ways then read that group: the local API at /api/groups/<id>, the web API
at /groups/<id>, and, in the database snapshot, only the group's items.
Without group_id, the snapshot reads only your own library.
5. Use it¶
uv run kb zotero search roofline model # key, citekey, year, title
uv run kb zotero show williams2009roofline # the item as JSON
uv run kb zotero new-source williams2009roofline # Source page with metadata, status draft
uv run kb fetch zotero:williams2009roofline # full text into .cache/sources/
uv run kb open zotero:ABCD2345 # select the item in Zotero
Items are addressed by their 8-character Zotero key (ABCD2345) or by
citation key. In practice you ask the agent to "ingest" a paper: the
kb-ingest skill runs kb zotero search, asks you to add the item to
Zotero if it is missing, then runs new-source and fetch.
The Source page created by new-source carries the pointer:
Troubleshooting¶
- No results while Zotero is closed: set
ZOTERO_DATA_DIR, or a web API key anduser_id. kb checkreports H010 onzotero.key: the key must be the 8-character item key, in capitals.- "cannot read the Zotero database snapshot": the copy was taken while Zotero was writing. Run the command again, or close Zotero first.
publisheddates:kb zotero new-sourcetakes the date from the API's parsed date when there is one. It keeps only the known parts: a date with an unknown month (2009-00-15) becomes2009.
See also: External resources, environment variables.