config
zocrates.config ¶
Central configuration for the Zocrates RAG engine. All settings are read from environment variables with safe defaults.
ALLOW_ORIGINS
module-attribute
¶
ALLOW_ORIGINS = [o.strip() for o in os.getenv('ALLOW_ORIGINS', '').split(',') if o.strip()] if os.getenv('ALLOW_ORIGINS') else list(DEFAULT_ALLOW_ORIGINS)
CHUNK_OVERLAP_CHARS
module-attribute
¶
CONVERSION_TIMEOUT_SECONDS
module-attribute
¶
CONVERSION_TIMEOUT_SECONDS = int(os.getenv('CONVERSION_TIMEOUT_SECONDS', str(DEFAULT_CONVERSION_TIMEOUT_SECONDS)))
DEFAULT_ADAPTIVE_COMPACTION_DECISION_MODEL
module-attribute
¶
DEFAULT_ADAPTIVE_COMPACTION_RETENTION_TURNS
module-attribute
¶
DEFAULT_ADAPTIVE_COMPACTION_THRESHOLD
module-attribute
¶
DEFAULT_ADAPTIVE_COMPACTION_TOKEN_CEILING
module-attribute
¶
DEFAULT_ADAPTIVE_COMPACTION_TOKEN_FLOOR
module-attribute
¶
DEFAULT_ADAPTIVE_DECISION_MODEL
module-attribute
¶
DEFAULT_ALLOW_ORIGINS
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_AUTO_START_LOCAL
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_ENABLED
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_LOCAL_PORT
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_LOCAL_URL
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_MODEL
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_PROVIDER
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_THRESHOLD
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_TIMEOUT_SEC
module-attribute
¶
DEFAULT_CITATION_VERIFICATION_TURN_BUDGET_SEC
module-attribute
¶
DEFAULT_COMPACTION_SUMMARIZER_MODEL
module-attribute
¶
DEFAULT_CONFIG
module-attribute
¶
DEFAULT_CONFIG = {'llm_provider': 'openrouter_llm', 'llm_model': DEFAULT_LLM_MODEL, 'llm_base_url': DEFAULT_LLM_BASE_URL, 'llm_temperature': DEFAULT_LLM_TEMPERATURE, 'llm_max_tokens': DEFAULT_LLM_MAX_TOKENS, 'llm_num_retries': DEFAULT_LLM_NUM_RETRIES, 'ollama_num_ctx': DEFAULT_OLLAMA_NUM_CTX, 'override_agent_models': copy.deepcopy(DEFAULT_OVERRIDE_AGENT_MODELS), 'embedding_provider': 'local', 'embedding_model': 'jinaai/jina-embeddings-v5-text-nano', 'embedding_dimension': 768, 'document_converter_mode': 'local', 'document_converter_id': 'markitdown', 'docling_mode': 'auto', 'datalab_non_pdf_fallback': 'markitdown', 'datalab_merge_cross_page': DEFAULT_DATALAB_MERGE_CROSS_PAGE, 'conversion_timeout_seconds': DEFAULT_CONVERSION_TIMEOUT_SECONDS, 'enable_vlm_captioning': DEFAULT_ENABLE_VLM_CAPTIONING, 'vlm_captioning_provider': DEFAULT_VLM_CAPTIONING_PROVIDER, 'vlm_captioning_model': DEFAULT_VLM_CAPTIONING_MODEL, 'vlm_captioning_backup_model': DEFAULT_VLM_CAPTIONING_BACKUP_MODEL, 'vlm_captioning_local_model': DEFAULT_VLM_CAPTIONING_LOCAL_MODEL, 'vlm_max_images_per_doc': DEFAULT_VLM_MAX_IMAGES_PER_DOC, 'vlm_timeout_seconds': DEFAULT_VLM_TIMEOUT_SECONDS, 'semantic_similarity_threshold': DEFAULT_SEMANTIC_SIMILARITY_THRESHOLD, 'reranker_model': DEFAULT_RERANKER_MODEL, 'search_harness': copy.deepcopy(DEFAULT_SEARCH_HARNESS), 'graph_relations': copy.deepcopy(DEFAULT_GRAPH_RELATIONS), 'citations_enabled': DEFAULT_CITATIONS_ENABLED, 'references_section_enabled': DEFAULT_REFERENCES_SECTION_ENABLED, 'considered_sources_disclosure': DEFAULT_CONSIDERED_SOURCES_DISCLOSURE, 'auto_render_mermaid_diagrams': DEFAULT_AUTO_RENDER_MERMAID_DIAGRAMS, 'enable_mcp_server': DEFAULT_ENABLE_MCP_SERVER, 'auto_spawn_backend': DEFAULT_AUTO_SPAWN_BACKEND, 'enable_predictive_ghost_input': DEFAULT_ENABLE_PREDICTIVE_GHOST_INPUT, 'predictive_prompt_model': DEFAULT_PREDICTIVE_PROMPT_MODEL, 'sentence_attribution_model': DEFAULT_SENTENCE_ATTRIBUTION_MODEL, 'scholar_polite_email': DEFAULT_SCHOLAR_POLITE_EMAIL, 'user_research_profile': DEFAULT_USER_RESEARCH_PROFILE, 'max_research_profile_chars': DEFAULT_MAX_RESEARCH_PROFILE_CHARS, 'citation_verification_enabled': False, 'citation_verification_provider': 'openrouter', 'citation_verification_model': DEFAULT_CITATION_VERIFICATION_MODEL, 'citation_verification_threshold': 0.6, 'citation_verification_local_url': 'http://127.0.0.1:8005/v1/systemone', 'citation_verification_local_port': 8005, 'citation_verification_auto_start_local': True, 'citation_verification_timeout_sec': 10.0, 'citation_verification_turn_budget_sec': 20.0, 'enable_adaptive_compaction': DEFAULT_ENABLE_ADAPTIVE_COMPACTION, 'adaptive_compaction_retention_turns': DEFAULT_ADAPTIVE_COMPACTION_RETENTION_TURNS, 'adaptive_compaction_min_turns': DEFAULT_ADAPTIVE_COMPACTION_MIN_TURNS, 'adaptive_compaction_token_floor': DEFAULT_ADAPTIVE_COMPACTION_TOKEN_FLOOR, 'adaptive_compaction_token_ceiling': DEFAULT_ADAPTIVE_COMPACTION_TOKEN_CEILING, 'adaptive_compaction_threshold': DEFAULT_ADAPTIVE_COMPACTION_THRESHOLD, 'adaptive_compaction_decision_model': DEFAULT_ADAPTIVE_COMPACTION_DECISION_MODEL, 'compaction_summarizer_model': DEFAULT_COMPACTION_SUMMARIZER_MODEL, 'max_saved_sessions': DEFAULT_MAX_SAVED_SESSIONS, 'session_retention_days': DEFAULT_SESSION_RETENTION_DAYS, 'session_db_auto_vacuum_on_startup': DEFAULT_SESSION_DB_AUTO_VACUUM_ON_STARTUP, 'prune_empty_sessions': DEFAULT_PRUNE_EMPTY_SESSIONS, 'backend_port': DEFAULT_BACKEND_PORT, 'bootstrap_handshake_timeout_ms': 300000, 'sync_auto_abort_failures': DEFAULT_SYNC_AUTO_ABORT_FAILURES}
DEFAULT_CONSIDERED_SOURCES_DISCLOSURE
module-attribute
¶
DEFAULT_ENABLE_PREDICTIVE_GHOST_INPUT
module-attribute
¶
DEFAULT_GRAPH_RELATIONS
module-attribute
¶
DEFAULT_GRAPH_RELATIONS = {'enabled': True, 'strategy': 'hybrid_corroborated', 'candidate_pool_size': 50, 'min_hybrid_score': 0.015, 'score_tau': 0.1, 'shared_tags_score': 0.7, 'include_human_curated': True, 'include_shared_tags': True, 'min_shared_tags': 2, 'sync_bundle_files': True}
DEFAULT_OVERRIDE_AGENT_MODELS
module-attribute
¶
DEFAULT_OVERRIDE_AGENT_MODELS = {'coordinator': {'model': None, 'thinking_level': 'medium'}, 'library_search': {'model': None, 'thinking_level': 'low'}, 'library_synthesizer': {'model': None, 'thinking_level': 'high'}, 'online_search': {'model': None, 'thinking_level': 'low'}, 'online_synthesizer': {'model': None, 'thinking_level': 'high'}}
DEFAULT_PREDICTIVE_PROMPT_MODEL
module-attribute
¶
DEFAULT_SEARCH_HARNESS
module-attribute
¶
DEFAULT_SEARCH_HARNESS = {'max_retrieval_tools': 10, 'budget_extension_increment': 5, 'max_absolute_retrieval_limit': 20, 'max_extension_count': 2, 'hard_word_ceiling': 7500, 'word_ceiling_extension_increment': 3750, 'max_absolute_word_ceiling': 15000, 'word_ceiling_hitl_trigger_percent': 80, 'max_rerank_chunks': 15, 'rerank_chunks_extension_increment': 5, 'max_absolute_rerank_chunks': 25, 'hitl_enabled': True, 'max_injected_toc_items': 3, 'max_unique_cached_tocs': 10, 'online_initial_retrieval_tools': 8, 'max_online_extensions': 2, 'online_budget_increment': 5, 'max_absolute_online_tools': 18}
DEFAULT_SEMANTIC_SIMILARITY_THRESHOLD
module-attribute
¶
DEFAULT_SESSION_DB_AUTO_VACUUM_ON_STARTUP
module-attribute
¶
DEFAULT_VLM_CAPTIONING_BACKUP_MODEL
module-attribute
¶
DEFAULT_VLM_CAPTIONING_BACKUP_MODEL = 'openrouter/nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free'
DEFAULT_VLM_CAPTIONING_MODEL
module-attribute
¶
EMBEDDING_DIMENSION
module-attribute
¶
GOOGLE_CLOUD_LOCATION
module-attribute
¶
LOCAL_EMBEDDING_MODEL
module-attribute
¶
PROVIDER_DEFAULT_MODELS
module-attribute
¶
PROVIDER_DEFAULT_MODELS = {'openrouter_llm': 'openrouter/~z-ai/glm-flash-latest', 'openrouter': 'openrouter/~z-ai/glm-flash-latest', 'ollama': 'llama3.1:8b', 'vllm': 'default', 'openai_compatible': 'default'}
ZOTERO_DATA_DIR
module-attribute
¶
_parse_config_backend_port ¶
Read-only peek at backend_port in zocrates_config.json.
Unlike load_zocrates_config this performs no file-lock side effects,
no default backfilling, and no disk writes — it is safe to call during
module import. Returns the port only when it parses to an int > 0.
Source code in zocrates/config.py
_parse_env_backend_port ¶
Parse the BACKEND_PORT environment override, or return None.
_resolve_backend_port ¶
Resolve the backend port.
Precedence
BACKEND_PORTenvironment variable (explicit override).backend_port(int > 0) inzocrates_config.json.- Deterministic offset:
compute_deterministic_portof the resolved zocrates-data directory, stepped forward viafind_free_portto the first free loopback port.
When no Zotero data directory can be resolved, the plain 8765 base port is returned and NO port probing is performed, so module imports stay deterministic in test and scripting environments.
Source code in zocrates/config.py
_resolve_explicit_zotero_data_dir ¶
Resolve Zotero data directory from explicit arg, active syncer, or ZOTERO_DATA_DIR env.
Source code in zocrates/config.py
_resolve_import_time_zotero_data_dir ¶
Best-effort Zotero data-dir resolution that is safe at module import time.
Deliberately avoids resolve_zotero_data_dir's LibrarySyncer branch:
importing app.rag.service_manager while app.config itself is still
initializing would be a circular import, and no syncer exists at import
time anyway. Mirrors the ZOTERO_DATA_DIR env + home-profile discovery
glue used by resolve_zotero_data_dir without any side effects.
Source code in zocrates/config.py
_write_auth_sidecar ¶
Write auth token to sidecar file with 0o600 permissions (best-effort).
Source code in zocrates/config.py
check_config_freshness ¶
Check if zocrates_config.json on disk has been modified since last check.
If _last_config_mtime is uninitialized (0.0), initializes it and returns False. If current mtime > _last_config_mtime, updates _last_config_mtime and returns True. Otherwise returns False. Handles OSError safely.
Source code in zocrates/config.py
clear_config_cache ¶
Clear in-memory config cache for a specific data dir or globally.
Source code in zocrates/config.py
compute_deterministic_port ¶
Return the deterministic backend port for the given data directory.
Pinned formula — MUST stay byte-for-byte identical to the JavaScript
implementation in zotero-plugin/addon/lib/portOffset.js so the Zotero
frontend and the Python backend derive the same port independently::
8765 + (int.from_bytes(hashlib.sha256(str(data_dir).encode("utf-8")).digest()[:8], "big") % 100)
Yields a stable port in the 8765..8864 range per library path, preventing
EADDRINUSE collisions across concurrent Zotero profiles.
Source code in zocrates/config.py
delete_secure_api_key ¶
Delete a named API key from the session environment (os.environ).
Zotero Preferences / Login Manager is the secure persistent vault. Backend keys are in-memory session variables.
Source code in zocrates/config.py
find_free_port ¶
Return the first free loopback TCP port from start (inclusive).
Probes 127.0.0.1 with an outbound TCP connect (250ms timeout). If the
candidate is occupied, steps forward up to span candidates (last
probed candidate is start + span - 1). If every candidate is busy,
returns start itself — the backend will surface the bind error.
Source code in zocrates/config.py
get_auth_token ¶
Resolve or generate the local backend authentication token.
Resolution order
ZOCRATES_AUTH_TOKENenvironment variable.- Sidecar file
<zocrates-data>/backend.auth. - Cached in-memory token, or newly generated 256-bit hex token
(
secrets.token_hex(32)) persisted tobackend.authwith mode0o600.
Source code in zocrates/config.py
get_auto_render_mermaid_diagrams ¶
Return whether auto-rendering Mermaid diagrams is enabled from zocrates_config.json.
Source code in zocrates/config.py
get_auto_spawn_backend ¶
Return whether the Zotero bootstrap may auto-provision/spawn a managed backend.
Source code in zocrates/config.py
get_backend_port ¶
Return configured backend port from environment or zocrates_config.json, or None if dynamic.
Delegates to the shared env/config parse helpers used by
_resolve_backend_port (env BACKEND_PORT > config "backend_port")
instead of duplicating the parsing logic. None means the dynamic
deterministic offset tier applies (see compute_deterministic_port).
Source code in zocrates/config.py
get_chroma_dir ¶
Return (and create if needed) the ChromaDB storage 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_citation_verification_enabled ¶
Return whether citation verification via decision models is enabled from zocrates_config.json.
Source code in zocrates/config.py
get_citations_enabled ¶
Return whether in-text citations are enabled from zocrates_config.json.
Source code in zocrates/config.py
get_collection_name ¶
Generate a sanitized, versioned ChromaDB collection name from model and dimension.
Replaces any non-alphanumeric characters with underscores, collapses consecutive underscores, and appends the dimension suffix.
Example::
get_collection_name("jinaai/jina-embeddings-v5-text-nano", 768)
# -> 'zotero_library_jinaai_jina_embeddings_v5_text_nano_768d'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Hugging Face or Gemini model identifier. |
required |
dimension
|
int
|
Embedding vector dimension. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A lowercase, underscore-delimited collection name string. |
Source code in zocrates/config.py
get_compaction_config ¶
Return adaptive context compaction settings from zocrates_config.json.
Source code in zocrates/config.py
get_config_path ¶
Return the path to the Zocrates config JSON file.
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_considered_sources_disclosure ¶
Return whether considered sources disclosure is enabled from zocrates_config.json.
Source code in zocrates/config.py
get_conversion_timeout_seconds ¶
Return the timeout in seconds for document conversion operations.
Checks CONVERSION_TIMEOUT_SECONDS environment variable first;
if unset, falls back to conversion_timeout_seconds in zocrates_config.json
(defaulting to 360s to accommodate CPU-based layout inference in Docling).
Source code in zocrates/config.py
get_coordinator_model ¶
Return the resolved coordinator model identifier.
Checks coordinator_agent.model at runtime if available; otherwise falls back to (cfg.get("override_agent_models") or {}).get("coordinator", {}).get("model"), then cfg.get("llm_model"), then DEFAULT_LLM_MODEL. Resolves with _resolve_model_name(coord_model, provider).
Source code in zocrates/config.py
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_datalab_api_key ¶
Return the Datalab API key from environment variables.
Zotero Preferences / Login Manager is the authoritative persistent vault for the Datalab API key. The backend stores the key in-memory (synced from Zotero via environment variable DATALAB_API_KEY on startup or POST /config at runtime).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Optional path to the Zotero data directory. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The API key string or None if not configured. |
Source code in zocrates/config.py
get_datalab_merge_cross_page ¶
Return whether Datalab cross-page table and paragraph merging is enabled.
Checks DATALAB_MERGE_CROSS_PAGE environment variable first (evaluating
truthiness: "1", "true", "yes", "on"); if unset, falls back to in-memory
cfg if provided, otherwise loads from zocrates_config.json
(defaulting to False).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in zocrates/config.py
get_datalab_non_pdf_fallback ¶
Return the fallback converter ID for non-PDF items when Datalab is active ('markitdown' or 'docling_local').
Checks DATALAB_NON_PDF_FALLBACK environment variable first;
if unset, falls back to datalab_non_pdf_fallback in zocrates_config.json
(defaulting to "markitdown").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Fallback converter ID string ( |
Source code in zocrates/config.py
get_docling_mode ¶
Return the Docling operating mode ('auto', 'fast', or 'full').
Checks DOCUMENT_CONVERTER_DOCLING_MODE or DOCLING_MODE environment
variable first; if unset, falls back to docling_mode in zocrates_config.json
(defaulting to "auto").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Docling mode string ( |
Source code in zocrates/config.py
get_document_converter_id ¶
Return the document converter ID from the Zocrates config.
Checks DOCUMENT_CONVERTER_ID environment variable first;
if unset, falls back to document_converter_id in zocrates_config.json
(defaulting to "markitdown").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Converter ID string (e.g., |
Source code in zocrates/config.py
get_document_converter_mode ¶
Return the document converter mode ('local' or 'cloud').
Checks the DOCUMENT_CONVERTER_MODE environment variable first;
if unset, falls back to the document_converter_mode in zocrates_config.json
(defaulting to "local").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Mode string ( |
Source code in zocrates/config.py
get_enable_vlm_captioning ¶
Return whether VLM image captioning and figure enrichment is enabled.
Checks ENABLE_VLM_CAPTIONING environment variable first;
if unset, falls back to enable_vlm_captioning in zocrates_config.json
(defaulting to True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in zocrates/config.py
get_force_cpu_pref ¶
Return whether CPU-only execution mode is forced for local embeddings.
Checks the FORCE_CPU environment variable first; if unset or falsy,
falls back to the force_cpu value in the persisted Zocrates config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. If |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
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
get_graph_relations_config ¶
Return the graph relations configuration dict from zocrates_config.json merged with defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | str | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict containing graph relations parameters. |
Source code in zocrates/config.py
get_log_dir ¶
Return (and create if needed) the Zocrates log 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_max_saved_sessions ¶
Return maximum number of saved sessions to retain, or None if disabled/unlimited.
Source code in zocrates/config.py
get_ollama_num_ctx ¶
Return configured Ollama context window size (num_ctx), defaulting to 16384.
Source code in zocrates/config.py
get_openalex_api_key ¶
Retrieve the configured OpenAlex API key from the environment.
get_prune_empty_sessions ¶
Return whether automatic pruning of abandoned empty sessions is enabled.
Source code in zocrates/config.py
get_references_section_enabled ¶
Return whether references section is enabled from zocrates_config.json.
Source code in zocrates/config.py
get_scholar_polite_email ¶
Return configured email for scholarly discovery APIs polite pool.
Source code in zocrates/config.py
get_search_harness_config ¶
Return the search harness configuration dict from zocrates_config.json merged with defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict containing search harness parameters (budget, limits, ceilings, HITL flags). |
Source code in zocrates/config.py
get_secure_api_key ¶
get_secure_api_key(key_name='openrouter_api_key', env_vars=('OPENROUTER_API_KEY', 'OPEN_ROUTER_API_KEY'))
Load a named API key from in-memory session environment variables.
Zotero Preferences / Login Manager serves as the secure persistent vault. Backend keys are in-memory session variables (os.environ) synced from Zotero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_name
|
str
|
Entry identifier (e.g., 'openrouter_api_key', 'openai_api_key'). |
'openrouter_api_key'
|
env_vars
|
list[str] | tuple[str, ...] | None
|
Environment variable names to check. |
('OPENROUTER_API_KEY', 'OPEN_ROUTER_API_KEY')
|
Returns:
| Type | Description |
|---|---|
str | None
|
The API key string or None if not found. |
Source code in zocrates/config.py
get_semantic_similarity_threshold ¶
Return the minimum cosine similarity threshold for semantic vector retrieval.
Reads strictly from semantic_similarity_threshold in zocrates_config.json
(clamped between 0.0 and 1.0, defaulting to 0.50).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Float similarity threshold between 0.0 and 1.0. |
Source code in zocrates/config.py
get_sentence_attribution_model ¶
Return the resolved model identifier for sentence attribution.
If cfg.get("sentence_attribution_model") is set and non-empty, resolves it with _resolve_model_name(custom_model, provider). If empty, null, or unset, delegates to get_coordinator_model(cfg, zotero_data_dir).
Source code in zocrates/config.py
get_session_auto_vacuum_on_startup ¶
Return whether session database auto-vacuum on startup is enabled.
Source code in zocrates/config.py
get_session_maintenance_config ¶
Return session database retention and maintenance settings dictionary from zocrates_config.json.
Source code in zocrates/config.py
get_session_retention_days ¶
Return maximum age in days for session retention, or None if disabled/unlimited.
Source code in zocrates/config.py
get_sync_auto_abort_failures ¶
Return the consecutive-failure auto-abort threshold for full-library sync jobs.
Reads sync_auto_abort_failures from zocrates_config.json (defaulting
to DEFAULT_SYNC_AUTO_ABORT_FAILURES). Values <= 0 disable auto-abort.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Source code in zocrates/config.py
get_user_research_profile ¶
Return the configured user research profile (stripped), or "" if unset.
Source code in zocrates/config.py
get_vlm_captioning_backup_model ¶
Return the backup VLM model identifier for cloud captioning fallback.
Checks VLM_CAPTIONING_BACKUP_MODEL environment variable first;
if unset, falls back to vlm_captioning_backup_model in zocrates_config.json
(defaulting to "openrouter/nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Backup model identifier string. |
Source code in zocrates/config.py
get_vlm_captioning_local_model ¶
Return the local Ollama model name for figure captioning.
Checks VLM_CAPTIONING_LOCAL_MODEL environment variable first;
if unset, falls back to vlm_captioning_local_model in zocrates_config.json
(defaulting to "").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Local model name string. |
Source code in zocrates/config.py
get_vlm_captioning_model ¶
Return the primary VLM model identifier for cloud captioning.
Checks VLM_CAPTIONING_MODEL environment variable first;
if unset, falls back to vlm_captioning_model in zocrates_config.json
(defaulting to "openrouter/nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Model identifier string. |
Source code in zocrates/config.py
get_vlm_captioning_provider ¶
Return the configured VLM provider ('openrouter' or 'ollama').
Checks VLM_CAPTIONING_PROVIDER environment variable first;
if unset, falls back to vlm_captioning_provider in zocrates_config.json
(defaulting to "openrouter").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Provider string ('openrouter' or 'ollama'). |
Source code in zocrates/config.py
get_vlm_max_images_per_doc ¶
Return the maximum number of images to caption per document.
Checks VLM_MAX_IMAGES_PER_DOC environment variable first;
if unset, falls back to vlm_max_images_per_doc in zocrates_config.json
(defaulting to 20).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Max images integer ceiling. |
Source code in zocrates/config.py
get_vlm_timeout_seconds ¶
Return the timeout in seconds for individual VLM captioning requests.
Checks VLM_TIMEOUT_SECONDS environment variable first;
if unset, falls back to vlm_timeout_seconds in zocrates_config.json
(defaulting to 30).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | None
|
Path to the Zotero data directory. |
None
|
cfg
|
dict[str, Any] | None
|
Optional in-memory config dict. If provided, bypasses disk read. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Timeout integer in seconds. |
Source code in zocrates/config.py
get_zocrates_data_dir ¶
Return (and create if needed) the Zocrates data directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | str | None
|
Root Zotero data directory (Path, string, or None for auto-discovery). |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to |
Source code in zocrates/config.py
is_adaptive_compaction_enabled ¶
Return whether adaptive context compaction is enabled from zocrates_config.json.
Source code in zocrates/config.py
is_context_compaction_enabled ¶
Deprecated alias for is_adaptive_compaction_enabled.
Source code in zocrates/config.py
is_local_decision_model ¶
Check if model name indicates local Laya decision model.
Source code in zocrates/config.py
is_mcp_server_enabled ¶
Return whether local MCP server access is enabled from zocrates_config.json.
Source code in zocrates/config.py
load_zocrates_config ¶
Load the Zocrates config from the data directory.
If zotero_data_dir is None, attempts to obtain it from the active
LibrarySyncer service or the ZOTERO_DATA_DIR environment variable.
Returns config merged with standard defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | str | None
|
Root Zotero data directory. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Parsed JSON config dict merged with defaults. |
Source code in zocrates/config.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 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 | |
rearm_config_freshness ¶
Re-arm the config freshness sentinel so a failed hot-swap can be retried immediately.
Sets _last_config_mtime to 1.0 (epoch + 1s). Since any actual file mtime is greater than 1.0, the next check_config_freshness call will re-trigger True.
Source code in zocrates/config.py
resolve_zotero_data_dir ¶
Resolve the active Zotero data directory with auto-discovery fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_data_dir
|
Path | str | None
|
Explicit data directory path or None. |
None
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Resolved Path to the Zotero data directory, or None if not located. |
Source code in zocrates/config.py
save_datalab_api_key ¶
Save the Datalab API key in the session environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | SecretStr | None
|
SecretStr, raw string key, or None/empty to delete. |
required |
Source code in zocrates/config.py
save_openalex_api_key ¶
Save or clear the OpenAlex API key in the session environment.
save_secure_api_key ¶
Store a named API key in the session environment.
Zotero Preferences / Login Manager (via the front-end extension) serves as the authoritative secure persistent vault for user credentials across restarts. The backend server stores keys in-memory as session variables (os.environ) synced from Zotero (via environment variables on startup and POST /config during runtime).
Does NOT persist plain-text keys to disk configuration files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | SecretStr | None
|
SecretStr, raw string key, or None/empty to delete. |
required |
key_name
|
str
|
Entry identifier (e.g., 'openrouter_api_key', 'datalab_api_key'). |
'openrouter_api_key'
|
env_var
|
str | None
|
Associated environment variable name to sync in memory. |
'OPENROUTER_API_KEY'
|
Source code in zocrates/config.py
save_zocrates_config ¶
Persist config (merged into any existing values) to the data directory.
If zotero_data_dir is None, attempts to obtain it from the active
LibrarySyncer service or the ZOTERO_DATA_DIR environment variable.
Uses a FileLock to prevent concurrent write corruption.
API keys are automatically intercepted and routed to the in-memory environment via
save_secure_api_key, ensuring they are never stored in plain text on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Key/value pairs to merge into the existing config file. |
required |
zotero_data_dir
|
Path | None
|
Root Zotero data directory. |
None
|
Source code in zocrates/config.py
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
stamp_config_mtime ¶
Stamp the in-memory config mtime sentinel with the current mtime of zocrates_config.json.