Skip to content

CausalIQ Knowledge CLI

The command-line interface provides a quick way to test LLM queries about causal relationships.

Installation

The CLI is automatically installed when you install the package:

pip install causaliq-knowledge

Usage

Basic Query

# Query using default model (Groq)
cqknow query smoking lung_cancer

# With domain context
cqknow query smoking lung_cancer --domain medicine

Multiple Models

# Query multiple models for consensus
cqknow query X Y --model groq/llama-3.1-8b-instant --model gemini/gemini-2.5-flash

JSON Output

# Get structured JSON output
cqknow query smoking lung_cancer --json

Options

Option Short Description
--model -m LLM model to query (can be repeated)
--domain -d Domain context (e.g., "medicine")
--strategy -s Consensus strategy: weighted_vote or highest_confidence
--json Output as JSON
--temperature -t LLM temperature (0.0-1.0)

Cache Management

The cache command group provides tools for inspecting and managing the LLM response cache.

Cache Stats

View statistics about a cache database:

# Show cache statistics
cqknow cache stats ./llm_cache.db

# Output:
# Cache: ./llm_cache.db
# ========================================
# Entries:  42
# Tokens:   15,230

Cache Export

Export cache entries to human-readable JSON files:

# Export all entries to a directory
cqknow cache export ./llm_cache.db ./export_dir

# Export to a zip archive (auto-detected from .zip extension)
cqknow cache export ./llm_cache.db ./export.zip

Files are named using a human-readable format:

gpt4_smoking_lung_edge_a1b2.json
gemini25_exercise_health_edge_c3d4.json

JSON Output

# Get stats as JSON for scripting
cqknow cache stats ./llm_cache.db --json

# Get export result as JSON
cqknow cache export ./llm_cache.db ./export_dir --json

Cache Command Options

Command Description
cache stats <path> Show entry and token counts
cache stats <path> --json Output stats as JSON
cache export <path> <dir> Export entries to directory
cache export <path> <file.zip> Export entries to zip archive
cache export <path> <output> --json Output export result as JSON
cache import <cache> <input> Import entries from directory or zip
cache import <cache> <input> --json Output import result as JSON

Cache Import

Import cache entries from JSON files:

# Import from a directory
cqknow cache import ./llm_cache.db ./import_dir

# Import from a zip archive (auto-detected from .zip extension)
cqknow cache import ./llm_cache.db ./export.zip

# Get import result as JSON
cqknow cache import ./llm_cache.db ./import_dir --json

Entry types are auto-detected from JSON structure: - LLM entries: JSON containing cache_key.model, cache_key.messages, and response - Generic JSON: Any other valid JSON file

This enables round-trip operations: export from one cache, import into another.

CLI Entry Point

cli

Command-line interface for causaliq-knowledge.

Functions:

  • cache_export

    Export cache entries to human-readable files.

  • cache_group

    Manage the LLM response cache.

  • cache_import

    Import cache entries from files.

  • cache_stats

    Show cache statistics.

  • cli

    CausalIQ Knowledge - LLM knowledge for causal discovery.

  • list_models

    List available LLM models from each provider.

  • main

    Entry point for the CLI.

  • query_edge

    Query LLMs about a causal relationship between two variables.

cache_export

cache_export(cache_path: str, output_dir: str, output_json: bool) -> None

Export cache entries to human-readable files.

CACHE_PATH is the path to the SQLite cache database. OUTPUT_DIR is the directory or zip file where files will be written.

If OUTPUT_DIR ends with .zip, entries are exported to a zip archive. Otherwise, entries are exported to a directory.

Files are named using a human-readable format

{model}{node_a}edge.json

Examples:

cqknow cache export ./llm_cache.db ./export_dir

cqknow cache export ./llm_cache.db ./export.zip

cqknow cache export ./llm_cache.db ./export_dir --json

cache_group

cache_group() -> None

Manage the LLM response cache.

Commands for inspecting, exporting, and importing cached LLM responses.

Examples:

cqknow cache stats ./llm_cache.db

cqknow cache export ./llm_cache.db ./export_dir

cqknow cache import ./llm_cache.db ./import_dir

cache_import

cache_import(cache_path: str, input_path: str, output_json: bool) -> None

Import cache entries from files.

CACHE_PATH is the path to the SQLite cache database (created if needed). INPUT_PATH is a directory or zip file containing JSON files to import.

Entry types are auto-detected from JSON structure: - LLM entries: contain cache_key.model, cache_key.messages, response - Generic JSON: anything else

Examples:

cqknow cache import ./llm_cache.db ./import_dir

cqknow cache import ./llm_cache.db ./export.zip

cqknow cache import ./llm_cache.db ./import_dir --json

cache_stats

cache_stats(cache_path: str, output_json: bool) -> None

Show cache statistics.

CACHE_PATH is the path to the SQLite cache database.

Examples:

cqknow cache stats ./llm_cache.db

cqknow cache stats ./llm_cache.db --json

cli

cli() -> None

CausalIQ Knowledge - LLM knowledge for causal discovery.

Query LLMs about causal relationships between variables.

list_models

list_models(provider: Optional[str]) -> None

List available LLM models from each provider.

Queries each provider's API to show models accessible with your current configuration. Results are filtered by your API key's access level or locally installed models.

Optionally specify PROVIDER to list models from a single provider: groq, anthropic, gemini, ollama, openai, deepseek, or mistral.

Examples:

cqknow models              # List all providers

cqknow models groq         # List only Groq models

cqknow models mistral      # List only Mistral models

main

main() -> None

Entry point for the CLI.

query_edge

query_edge(
    node_a: str,
    node_b: str,
    model: tuple[str, ...],
    domain: Optional[str],
    strategy: str,
    output_json: bool,
    temperature: float,
) -> None

Query LLMs about a causal relationship between two variables.

NODE_A and NODE_B are the variable names to query about.

Examples:

cqknow query smoking lung_cancer

cqknow query smoking lung_cancer --domain medicine

cqknow query X Y --model groq/llama-3.1-8b-instant                          --model gemini/gemini-2.5-flash