frontmatter_refresher
zocrates.rag.frontmatter_refresher ¶
Frontmatter refresher and metadata synchronization engine for Zocrates.
Synchronizes OKF v0.2 YAML frontmatter in cached Markdown bundles with the latest bibliographic metadata from Zotero (titles, authors, year, publication, DOI, URL) without triggering PDF/HTML reconversion, OCR, or embedding models.
_FRONTMATTER_RE
module-attribute
¶
VectorStore ¶
Hybrid vector + keyword search index for Zotero document chunks. Uses versioned Chroma collections per embedding model/dimension.
Initialize the VectorStore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chroma_dir
|
Path
|
Directory for ChromaDB persistent storage. |
required |
fts_db_path
|
Path
|
Filesystem path for the SQLite FTS5 database. |
required |
embedder
|
EmbedFn
|
Callable that maps a list of strings to a list of
embedding vectors and exposes |
required |
Source code in zocrates/rag/vector_store.py
acquire_write_lock ¶
Return the store's RLock for external write operations (e.g., model swap).
Returns:
| Type | Description |
|---|---|
Any
|
The |
close ¶
Close the Chroma client and release underlying storage handles.
Source code in zocrates/rag/vector_store.py
delete_document ¶
Remove all chunks for the given item_key from both Chroma and FTS5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key identifying the document to delete. |
required |
get_all_chunk_ids_for_item ¶
Return all chunk IDs for an item key in chunk_index order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of chunk IDs. |
Source code in zocrates/rag/vector_store.py
get_all_ingested_item_keys ¶
Return the set of all unique item_key strings currently ingested in the active collection.
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of unique item_key strings. |
Source code in zocrates/rag/vector_store.py
get_all_item_keys ¶
Return the set of all unique item keys indexed in the chunk_meta SQLite table.
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of unique item_key strings. |
Source code in zocrates/rag/vector_store.py
get_intersecting_chunk_ids ¶
Return chunk IDs for an item key that intersect the given line range [start_line, end_line].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key. |
required |
start_line
|
int
|
1-indexed start line of the range. |
required |
end_line
|
int
|
1-indexed end line of the range. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of chunk IDs in chunk_index order. |
Source code in zocrates/rag/vector_store.py
ingest_document ¶
Index all chunks from a single document into Chroma and FTS5.
Deletes any existing chunks for item_key before inserting, making
the operation idempotent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Unique Zotero item key used as the primary document ID. |
required |
item_id
|
int
|
Numeric Zotero item ID stored as chunk metadata. |
required |
chunks
|
list[ChunkResult]
|
Ordered list of |
required |
extra_metadata
|
dict[str, Any] | None
|
Additional key/value pairs merged into every chunk's Chroma metadata dict. |
None
|
Source code in zocrates/rag/vector_store.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
is_ingested ¶
Check whether any chunks exist for item_key in the active collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key to look up. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in zocrates/rag/vector_store.py
list_collections ¶
List all stored versioned Chroma collections with their metadata and chunk counts.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dicts, each with keys |
list[dict[str, Any]]
|
|
Source code in zocrates/rag/vector_store.py
reset_collection ¶
Reset/clear vector store collection(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Which collection(s) to reset:
- |
'active'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys |
dict[str, Any]
|
|
Source code in zocrates/rag/vector_store.py
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
search ¶
search(query, top_k=RETRIEVAL_TOP_K, final_k=RETRIEVAL_FINAL_K, item_key_filter=None, chunk_type_filter=None, exclude_chunk_ids=None, reranker=None)
Hybrid (semantic + BM25) search with RRF fusion and raw score metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Natural language query string. |
required |
top_k
|
int
|
Number of candidates retrieved from each index before fusion. |
RETRIEVAL_TOP_K
|
final_k
|
int
|
Maximum number of results to return after fusion. |
RETRIEVAL_FINAL_K
|
item_key_filter
|
list[str] | None
|
If provided, restrict search to these Zotero item keys. |
None
|
chunk_type_filter
|
str | list[str] | None
|
Optional chunk type or list of chunk types to filter by. |
None
|
exclude_chunk_ids
|
set[str] | list[str] | None
|
Optional set or list of chunk IDs to exclude from results. |
None
|
reranker
|
Callable[[str, list[str]], list[float]] | None
|
Optional callable |
None
|
Returns:
| Type | Description |
|---|---|
list[SearchResult]
|
List of |
list[SearchResult]
|
capped at |
Source code in zocrates/rag/vector_store.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
update_chunk_text_preserve_vector ¶
Update stored document text in Chroma while explicitly preserving existing vector.
Passing existing embeddings explicitly bypasses Chroma's internal embedding function, guaranteeing zero ML overhead, zero network roundtrips, and strict dimension alignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_id
|
str
|
Canonical chunk identifier (e.g. |
required |
new_text
|
str
|
New document text for the chunk. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if chunk was found, had embeddings, and was updated; False otherwise. |
Source code in zocrates/rag/vector_store.py
update_metadata ¶
Update metadata for all chunks belonging to item_key without re-embedding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key. |
required |
metadata
|
dict[str, Any]
|
Key/value pairs to merge into existing chunk metadatas. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if chunks were found and updated, False if item was not found. |
Source code in zocrates/rag/vector_store.py
ZoteroDB ¶
Read-only façade over zotero.sqlite.
Initialize ZoteroDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sqlite_path
|
Path
|
Absolute path to the |
required |
storage_dir
|
Path
|
Absolute path to the Zotero |
required |
Source code in zocrates/rag/zotero_db.py
get_active_item_keys ¶
Return a set of item keys that exist in the library and are not deleted or parent-deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_keys
|
list[str]
|
List of Zotero item keys (can include regular items, attachments, notes). |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of active item keys. |
Source code in zocrates/rag/zotero_db.py
get_all_arxiv_ids ¶
Return a set of all normalized arXiv IDs across active non-deleted items in the library.
Source code in zocrates/rag/zotero_db.py
get_all_attachments ¶
Return all file attachments with a parent item across the library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_types
|
tuple[str, ...]
|
Tuple of MIME types to include. |
('application/pdf', 'text/html', 'text/markdown', 'text/plain')
|
Returns:
| Type | Description |
|---|---|
list[ZoteroAttachment]
|
List of |
Source code in zocrates/rag/zotero_db.py
get_all_convertible_attachments ¶
Return all valid document attachments in the library in a single fast query.
Source code in zocrates/rag/zotero_db.py
get_all_dedup_records ¶
Return lightweight records (title, year, creators, doi, arxiv_id) for active items for fuzzy dedup.
Source code in zocrates/rag/zotero_db.py
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 | |
get_all_dois ¶
Return a set of all normalized DOIs across active non-deleted items in the library.
Source code in zocrates/rag/zotero_db.py
get_all_item_relations ¶
Return all explicit item relations as (source_key, target_key) pairs.
Source code in zocrates/rag/zotero_db.py
get_all_items ¶
Return all non-attachment, non-deleted items in the library.
Returns:
| Type | Description |
|---|---|
list[ZoteroItem]
|
List of fully populated |
Source code in zocrates/rag/zotero_db.py
get_all_notes ¶
Return all notes (standalone and child notes) in the library.
Returns:
| Type | Description |
|---|---|
list[ZoteroNote]
|
List of |
Source code in zocrates/rag/zotero_db.py
get_all_titles ¶
Return a list of all titles across active non-deleted items in the library.
Source code in zocrates/rag/zotero_db.py
get_attachment_by_id ¶
Fetch a single file attachment by its item ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
int
|
Numeric Zotero item ID of the attachment. |
required |
Returns:
| Type | Description |
|---|---|
ZoteroAttachment | None
|
|
ZoteroAttachment | None
|
or deleted. |
Source code in zocrates/rag/zotero_db.py
get_attachment_by_key ¶
Fetch a single file attachment by its item key or parent item key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key string (attachment key or parent item key). |
required |
Returns:
| Type | Description |
|---|---|
ZoteroAttachment | None
|
|
Source code in zocrates/rag/zotero_db.py
get_attachments ¶
get_attachments(parent_item_id, content_types=('application/pdf', 'text/html', 'text/markdown', 'text/plain'))
Return file attachments for a given parent item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_item_id
|
int
|
Numeric ID of the parent Zotero item. |
required |
content_types
|
tuple[str, ...]
|
Tuple of MIME types to include; defaults to PDF, HTML, Markdown, and plain text. |
('application/pdf', 'text/html', 'text/markdown', 'text/plain')
|
Returns:
| Type | Description |
|---|---|
list[ZoteroAttachment]
|
List of |
list[ZoteroAttachment]
|
paths ( |
list[ZoteroAttachment]
|
The |
list[ZoteroAttachment]
|
available, otherwise the attachment filename. |
Source code in zocrates/rag/zotero_db.py
get_item ¶
Fetch a single item with full metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
int
|
Numeric Zotero item ID. |
required |
Returns:
| Type | Description |
|---|---|
ZoteroItem | None
|
Fully populated |
ZoteroItem | None
|
and relations), or |
Source code in zocrates/rag/zotero_db.py
get_item_by_key ¶
Fetch a single item by its string key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key string (e.g. '89X2ELQ6'). |
required |
Returns:
| Type | Description |
|---|---|
ZoteroItem | None
|
Fully populated |
Source code in zocrates/rag/zotero_db.py
get_item_date_modified ¶
Fetch the last modified timestamp for an item as timezone-aware UTC datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
8-character Zotero alphanumeric key. |
required |
Returns:
| Type | Description |
|---|---|
datetime | None
|
Timezone-aware UTC datetime, or None if item not found. |
Source code in zocrates/rag/zotero_db.py
get_item_keys_in_collection ¶
Return the unique item keys for all items belonging to a collection name or key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
Name or key of the collection. |
required |
recursive
|
bool
|
If True and parentCollectionID exists, includes items in all subcollections. |
True
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of unique item keys. |
Source code in zocrates/rag/zotero_db.py
get_item_relations ¶
Return target item keys related to the specified item.
Source code in zocrates/rag/zotero_db.py
get_item_tags ¶
Return tag names for an item, optionally filtered by tag type (0=user, 1=automatic).
Source code in zocrates/rag/zotero_db.py
get_items_by_ids ¶
Fetch multiple items by their numeric IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_ids
|
list[int]
|
List of numeric Zotero item IDs. |
required |
Returns:
| Type | Description |
|---|---|
list[ZoteroItem]
|
List of fully populated |
list[ZoteroItem]
|
tags, and collections). Items not found or deleted are silently |
list[ZoteroItem]
|
omitted. |
Source code in zocrates/rag/zotero_db.py
get_new_item_ids_since ¶
Return item IDs created after last_seen_item_id for incremental sync.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_seen_item_id
|
int
|
The highest item ID already processed. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted list of numeric item IDs greater than |
list[int]
|
that are not attachments, notes, or deleted items. |
Source code in zocrates/rag/zotero_db.py
get_note_by_id ¶
Fetch a single note by note item ID.
Source code in zocrates/rag/zotero_db.py
get_note_by_key ¶
Fetch a single note by its Zotero item key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_key
|
str
|
The alphanumeric Zotero item key of the note. |
required |
Returns:
| Type | Description |
|---|---|
ZoteroNote | None
|
A |
ZoteroNote | None
|
or the item has been deleted. |
Source code in zocrates/rag/zotero_db.py
get_notes_for_item ¶
Return child notes attached to a specific parent item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_item_id
|
int
|
Numeric ID of the parent Zotero item. |
required |
Returns:
| Type | Description |
|---|---|
list[ZoteroNote]
|
List of |
Source code in zocrates/rag/zotero_db.py
get_stale_item_keys ¶
Identify cached items whose Zotero metadata has been modified since conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
converted_map
|
dict[str, str]
|
Mapping of attachment/note item_key -> converted_at ISO string. |
required |
key_to_atts
|
dict[str, list[str]]
|
Mapping of query key (parent_item_key or direct item_key) to list of associated attachment/note item_keys. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted, unique list of attachment/note item_keys whose metadata is stale. |
Source code in zocrates/rag/zotero_db.py
get_standalone_attachments ¶
get_standalone_attachments(content_types=('application/pdf', 'text/html', 'text/markdown', 'text/plain'))
Return standalone file attachments (attachments without a parent item).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_types
|
tuple[str, ...]
|
Tuple of MIME types to include. |
('application/pdf', 'text/html', 'text/markdown', 'text/plain')
|
Returns:
| Type | Description |
|---|---|
list[ZoteroAttachment]
|
List of |
Source code in zocrates/rag/zotero_db.py
get_standalone_notes ¶
Return top-level standalone notes (notes without a parent item).
Returns:
| Type | Description |
|---|---|
list[ZoteroNote]
|
List of |
Source code in zocrates/rag/zotero_db.py
invalidate_schema_cache ¶
is_item_active ¶
Check if a single item key exists and is not deleted (or parent-deleted).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_key
|
str
|
Zotero item key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the item exists and is active, False otherwise. |
Source code in zocrates/rag/zotero_db.py
_open_fts_db ¶
Open (or create) the FTS5 and chunk metadata SQLite databases.
Creates the chunks_fts FTS5 virtual table (trigram tokenizer) and
the chunk_meta table if they do not already exist. Migrates missing
columns on chunk_meta if opened on a legacy database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the SQLite database file. |
required |
Returns:
| Type | Description |
|---|---|
Connection
|
An open |
Connection
|
|
Source code in zocrates/rag/vector_store.py
_open_meta_db ¶
Open (or create) the conversion metadata SQLite database.
Creates the conversion_meta table if it does not already exist.
Enables WAL mode for concurrent readers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path
|
Directory containing the |
required |
Returns:
| Type | Description |
|---|---|
Connection
|
An open |
Connection
|
|
Source code in zocrates/rag/document_processor.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
build_frontmatter ¶
build_frontmatter(item_key, parent_item_type, title, collections, source_path, source_hash, content_type, converter_id, converter_version, converted_at, parent_item_key=None, parse_quality_score=None, checkpoint_id=None, authors=None, year=None, publication=None, doi=None, url=None, keywords=None, bundle_dir=None)
Build OKF-0.2 YAML frontmatter string.
Args:
item_key: Zotero item key.
parent_item_type: Zotero item type (e.g., 'journalArticle'). Defaults to 'document'.
title: Title of the parent item.
collections: List of ZoteroCollection objects or dicts with name and key/collection_key.
source_path: Absolute path to the source file on disk.
source_hash: SHA-256 hex digest of the source file.
content_type: MIME type of the source file.
converter_id: Converter engine ID.
converter_version: Converter engine version string.
converted_at: ISO-8601 timestamp string.
parent_item_key: Parent item key if item is an attachment.
parse_quality_score: Optional parse quality score (e.g. 0.0 to 5.0 from Datalab).
checkpoint_id: Optional converter checkpoint ID.
authors: Optional list of creator/author name strings.
year: Optional publication year (int or string).
publication: Optional publication venue or publisher string.
doi: Optional normalized DOI string.
url: Optional source URL string.
bundle_dir: Optional bundle directory (e.g. cache_dir / item_key). If provided,
source.path is computed as a relative POSIX path from bundle_dir.
Returns:
Formatted YAML frontmatter block ending with '---
'.
Source code in zocrates/rag/bundle_catalog.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
generate_item_index_md ¶
Generate item-level index.md catalog inside item_dir.
Catalogs main document as well as all associated image and table assets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_dir
|
Path
|
Bundle directory (corpus/ |
required |
item_key
|
str
|
Zotero item key. |
required |
title
|
str | None
|
Title of the parent item. |
required |
converter_id
|
str
|
Converter engine ID. |
required |
converter_version
|
str
|
Converter engine version string. |
required |
Source code in zocrates/rag/bundle_catalog.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
generate_root_index_md ¶
Regenerate root-level index.md catalog from conversion_meta.db.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path
|
Corpus directory containing conversion_meta.db. |
required |
Source code in zocrates/rag/bundle_catalog.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
generate_toc ¶
generate_toc(document_md, title=None, abstract=None, abstract_source='zotero', item_key='', parent_item_key=None)
Generate dual-format Table of Contents from a converted Markdown document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_md
|
str
|
Full converted Markdown text (including YAML frontmatter). |
required |
title
|
str | None
|
Document title. |
None
|
abstract
|
str | None
|
Abstract or summary text. |
None
|
abstract_source
|
str
|
Source of abstract ('zotero', 'generated', 'extractive'). |
'zotero'
|
item_key
|
str
|
Zotero item key. |
''
|
parent_item_key
|
str | None
|
Parent Zotero item key if item is an attachment. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], str]
|
A 2-tuple of |
Source code in zocrates/rag/toc_generator.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
get_corpus_dir ¶
Return (and create if needed) the document corpus directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path
|
Root Zotero data directory. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to |
Source code in zocrates/config.py
get_fts_db_path ¶
Return the path to the FTS5 SQLite database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path
|
Root Zotero data directory. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to |
Source code in zocrates/config.py
refresh_bundle_frontmatter ¶
refresh_bundle_frontmatter(zotero_dir, target_keys=None, dry_run=False, sanitize_images=False, store=None, cache_dir=None)
Refresh YAML frontmatter and associated artifacts across target or all cached bundles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_dir
|
Path
|
Root Zotero profile directory containing zotero.sqlite and storage/. |
required |
target_keys
|
list[str] | None
|
Optional list of attachment or note item keys to refresh. If None, scans all cached bundles in conversion_meta.db. |
None
|
dry_run
|
bool
|
If True, previews changes without writing to disk or database. |
False
|
sanitize_images
|
bool
|
If True, converts legacy file:/// URIs in document.md to images/. |
False
|
store
|
VectorStore | None
|
Optional existing VectorStore instance for FTS5 and Chroma updates. |
None
|
cache_dir
|
Path | None
|
Optional explicit corpus directory. Defaults to zotero_dir / "zocrates-data" / "corpus". |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Summary dict containing counts of total, updated, skipped, and errored items. |
Source code in zocrates/rag/frontmatter_refresher.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
resolve_source_path ¶
Resolve a stored source_path to a local physical Path or verbatim URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stored_path
|
str | Path | None
|
Storage-relative path ('storage/...'), note URI, or absolute path. |
required |
zotero_profile_dir
|
Path
|
Root Zotero profile directory. |
required |
Returns:
| Type | Description |
|---|---|
Path | str
|
Resolved physical Path on disk or URI string. |
Source code in zocrates/rag/bundle_catalog.py
sanitize_image_links_in_markdown ¶
Sanitize legacy file:///.../images/ absolute links in markdown text.
Ensures strict line-count invariance to preserve ToC and chunk line offsets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw markdown text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Markdown text with file:///.../images/ |
Source code in zocrates/rag/document_processor.py
save_toc_files ¶
Safely persist toc.json and toc.md inside bundle_dir using atomic writes.
Writes to temporary files within the target bundle directory and renames via os.replace to prevent partial reads or corrupt states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle_dir
|
Path
|
OKF document bundle directory (e.g. corpus/ |
required |
toc_json
|
dict[str, Any]
|
Dictionary representation of toc.json. |
required |
toc_md
|
str
|
String contents for toc.md. |
required |
Source code in zocrates/rag/toc_generator.py
sync_stale_metadata ¶
Scan all cached items and refresh any whose Zotero metadata has been modified.
Performs a lightweight timestamp comparison (<5ms) between conversion_meta.db and zotero.sqlite. Only items whose source metadata was modified since conversion are dispatched to refresh_bundle_frontmatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_dir
|
Path
|
Root Zotero profile directory. |
required |
dry_run
|
bool
|
If True, previews changes without writing to disk or database. |
False
|
sanitize_images
|
bool
|
If True, sanitizes legacy file:/// image links. |
False
|
store
|
VectorStore | None
|
Optional existing VectorStore instance for Chroma and FTS updates. |
None
|
cache_dir
|
Path | None
|
Optional explicit markdown cache directory. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Summary dict containing counts of total, updated, skipped, and errored items. |
dict[str, int]
|
When stale items are found, total reflects the count of stale items dispatched |
dict[str, int]
|
to refresh_bundle_frontmatter; when no items are stale, total and skipped reflect |
dict[str, int]
|
the full count of checked cached bundles. |
Source code in zocrates/rag/frontmatter_refresher.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |