CLI
RetriCo includes a command-line interface for building knowledge graphs, querying them, managing graph data, and more — without writing any Python code.
Installation
The CLI is available as retrico after installing the package:
pip install retrico
retrico --version
Commands Overview
| Command | Description |
|---|---|
retrico connect | Save database connection to .retrico.yaml |
retrico build | Build a knowledge graph from text |
retrico query | Query the knowledge graph |
retrico ingest | Ingest structured JSON data |
retrico community | Detect communities in the graph |
retrico model | Train KG embeddings |
retrico init | Generate a pipeline config YAML interactively |
retrico graph | Direct graph database operations (CRUD) |
retrico shell | Interactive query REPL |
Three Modes of Operation
Most commands (build, query, community, model) support three modes:
- Argument mode — pass all options as flags (scriptable, CI-friendly)
- Config mode — pass a YAML pipeline config with
--config - Interactive mode — a step-by-step wizard (use
--interactiveto force)
If you provide enough flags, the CLI runs in argument mode. If not, it falls back to the interactive wizard automatically.
connect
Save a database connection to .retrico.yaml in the current directory. All subsequent commands will use this connection by default.
Interactive setup
retrico connect
The wizard prompts for store type and connection details.
Flag-based setup
# FalkorDB Lite (default, zero-config)
retrico connect --store-type falkordb_lite --falkordb-lite-db-path retrico.db
# Neo4j
retrico connect --store-type neo4j --neo4j-uri bolt://localhost:7687 \
--neo4j-user neo4j --neo4j-password password
# FalkorDB (server)
retrico connect --store-type falkordb --falkordb-host localhost --falkordb-port 6379
# Memgraph
retrico connect --store-type memgraph --memgraph-uri bolt://localhost:7687
Managing the saved connection
# Show current connection (passwords masked)
retrico connect --show
# Clear saved connection
retrico connect --clear
The .retrico.yaml file looks like:
store:
store_type: neo4j
neo4j_uri: bolt://localhost:7687
neo4j_user: neo4j
neo4j_password: password
Any command can override the saved connection with explicit flags. CLI flags always take precedence over .retrico.yaml.
build
Build a knowledge graph from text. This is the CLI equivalent of retrico.build_graph().
From a YAML config
retrico build --config build_config.yaml --text "Einstein was born in Ulm."
retrico build --config build_config.yaml --file paper.txt --file notes.txt
With flags
retrico build \
--text "Albert Einstein was born in Ulm, Germany." \
--text "Marie Curie worked at the University of Paris." \
--entity-labels "person,organization,location" \
--relation-labels "born in,works at" \
--verbose
From files
retrico build \
--file document.txt \
--file article.txt \
--entity-labels "person,organization,location" \
--relation-labels "born in,works at"
LLM-based extraction
retrico build \
--text "Einstein developed relativity at the Swiss Patent Office." \
--entity-labels "person,concept,organization" \
--relation-labels "developed,works at" \
--method llm \
--api-key sk-... \
--llm-model gpt-4o-mini
The API key can also be set via the LLM_API_KEY environment variable.
Saving the pipeline config
retrico build \
--text "..." \
--entity-labels "person,location" \
--save-config my_pipeline.yaml
This runs the pipeline and saves its configuration for reuse with --config.
Interactive wizard
retrico build --interactive
The wizard walks through each step: input source, database connection, chunking method, NER method, labels, embeddings, and config saving.
All options
| Option | Description |
|---|---|
--config FILE | YAML pipeline config file |
--text TEXT | Input text (repeatable) |
--file FILE | Input text file (repeatable) |
--entity-labels | Comma-separated entity labels |
--relation-labels | Comma-separated relation labels |
--method | NER/relex method: gliner or llm |
--chunk-method | Chunking: sentence, paragraph, or fixed |
--ner-model | NER model name |
--relex-model | Relex model name |
--api-key | LLM API key (or LLM_API_KEY env var) |
--llm-model | LLM model name |
--json-output | Save extracted data as JSON |
--embed-chunks | Generate chunk embeddings |
--embed-entities | Generate entity embeddings |
--verbose | Verbose output |
--interactive | Force interactive wizard |
--save-config FILE | Save pipeline config to YAML |
--store-type | Graph store backend |
--neo4j-* | Neo4j connection options |
--falkordb-* | FalkorDB connection options |
--memgraph-* | Memgraph connection options |
query
Query the knowledge graph. CLI equivalent of retrico.query_graph().
With flags
retrico query "Where was Einstein born?" \
--entity-labels "person,location" \
--api-key sk-... \
--llm-model gpt-4o-mini
With a retrieval strategy
# Entity lookup + k-hop subgraph (default)
retrico query "Where was Einstein born?" \
--entity-labels "person,location" \
--strategy entity --max-hops 2
# Path-based retrieval
retrico query "How are Einstein and Curie related?" \
--entity-labels "person" \
--strategy path
# Community-based retrieval
retrico query "What research groups exist?" \
--entity-labels "person,organization" \
--strategy community
# Multiple strategies (comma-separated)
retrico query "Tell me about Einstein" \
--entity-labels "person,location" \
--strategy entity,path,community
Available strategies: entity, community, path, chunk_embedding, entity_embedding, tool, keyword.
From a YAML config
retrico query "Where was Einstein born?" --config query_config.yaml
Interactive wizard
retrico query --interactive
All options
| Option | Description |
|---|---|
QUERY_TEXT | The query (positional argument) |
--config FILE | YAML pipeline config |
--entity-labels | Comma-separated entity labels |
--strategy | Retrieval strategy (comma-separated for multi) |
--method | NER method for query parsing: gliner or llm |
--api-key | LLM API key |
--llm-model | LLM model name |
--max-hops | Subgraph expansion depth |
--verbose | Verbose output |
--interactive | Force interactive wizard |
Output
The query command displays:
- Answer — LLM-generated answer (if an API key is provided)
- Entities — retrieved entities with types and IDs
- Relations — discovered relationships
- Source chunks — relevant text passages from the original documents
ingest
Ingest structured JSON data into the graph. The JSON file must contain a list of objects with entities (required), and optionally relations, text, and metadata.
retrico ingest data.json
retrico ingest data.json --json-output backup.json --verbose
Expected JSON format
[
{
"entities": [
{"text": "Einstein", "label": "person", "properties": {"birth_year": 1879}},
{"text": "Ulm", "label": "location"}
],
"relations": [
{"head": "Einstein", "tail": "Ulm", "type": "born_in"}
],
"text": "Einstein was born in Ulm.",
"metadata": {"source": "wikipedia"}
}
]
This is the same format produced by --json-output on the build command, so you can extract data once and re-ingest it into different databases.
Options
| Option | Description |
|---|---|
FILE | JSON file to ingest (positional, required) |
--json-output | Save data as JSON |
--verbose | Verbose output |
community
Detect communities in the knowledge graph using Louvain or Leiden algorithms.
With flags
retrico community --method louvain --levels 2 --resolution 1.0
With LLM summarization
retrico community --method leiden --api-key sk-... --llm-model gpt-4o-mini
From a YAML config
retrico community --config community_config.yaml
Interactive wizard
retrico community --interactive
Options
| Option | Description |
|---|---|
--config FILE | YAML pipeline config |
--method | louvain or leiden |
--levels | Hierarchical levels |
--resolution | Resolution parameter |
--api-key | LLM API key for community summarization |
--llm-model | LLM model name |
--verbose | Verbose output |
--interactive | Force interactive wizard |
model
Train knowledge graph embeddings using PyKEEN models (RotatE, TransE, ComplEx).
With flags
retrico model --kg-model RotatE --embedding-dim 128 --epochs 100 --model-path kg_model
Interactive wizard
retrico model --interactive
Options
| Option | Description |
|---|---|
--config FILE | YAML pipeline config |
--kg-model | PyKEEN model: RotatE, TransE, or ComplEx |
--embedding-dim | Embedding dimension |
--epochs | Training epochs |
--batch-size | Batch size |
--lr | Learning rate |
--device | cpu or cuda |
--model-path | Path to save the trained model |
--verbose | Verbose output |
--interactive | Force interactive wizard |
init
Generate a pipeline YAML config file through an interactive wizard. Useful for creating reusable configs without running a pipeline.
retrico init build # Build pipeline config
retrico init query # Query pipeline config
retrico init community # Community detection config
retrico init model # KG embedding config
If no pipeline type is provided, the wizard prompts for it.
The wizard walks through each component step by step and writes the final config to a YAML file.
graph
Direct graph database operations. The graph command is a group of subcommands for CRUD operations on the knowledge graph.
List entities
retrico graph entities
retrico graph entities --type person --limit 20
Show relations
retrico graph relations "Einstein"
retrico graph relations <entity-id>
Looks up by label first, then by ID.
Full-text search
retrico graph search "theory of relativity" --top-k 5
Add an entity
retrico graph add-entity "Albert Einstein" --type person
retrico graph add-entity "MIT" --type organization --properties '{"founded": 1861}'
Add a relation
retrico graph add-relation "Einstein" "Ulm" "BORN_IN"
Update an entity
retrico graph update <entity-id> --label "A. Einstein"
retrico graph update <entity-id> --properties '{"field": "physics"}'
Delete entities or relations
retrico graph delete --entity <entity-id>
retrico graph delete --relation <relation-id>
Merge entities
Merge a source entity into a target entity (moves all relations):
retrico graph merge <source-id> <target-id>
Graph statistics
retrico graph stats
Displays total entity count and breakdown by type.
Run raw Cypher
retrico graph cypher "MATCH (n:Entity) RETURN n.label, n.entity_type LIMIT 10"
Clear all data
retrico graph clear
retrico graph clear --yes # skip confirmation
This permanently deletes all data from the graph.
shell
Interactive query REPL. Type natural-language queries and get answers without restarting the CLI.
retrico shell --entity-labels "person,location" --api-key sk-...
Shell commands
| Command | Description |
|---|---|
:entities [type] | List entities, optionally filtered by type |
:relations ENTITY | Show relations for an entity |
:search TEXT | Full-text search chunks |
:cypher QUERY | Run raw Cypher query |
:labels person,org,... | Set default entity labels |
:help | Show available commands |
:quit | Exit the shell |
Anything that isn't a :command is treated as a query_graph() call using the configured entity labels and LLM settings.
Example session
$ retrico shell --entity-labels "person,location" --api-key sk-...
retrico interactive shell
Type a query or :help for commands. :quit to exit.
retrico> Where was Einstein born?
Answer:
Albert Einstein was born in Ulm, Germany.
Entities (2):
- albert einstein [person] (id: a1b2c3d4...)
- ulm [location] (id: e5f6g7h8...)
Relations (1):
- albert einstein --[BORN_IN]--> ulm
retrico> :entities person
id label entity_type
-------- ----------------- -----------
a1b2c3d4 albert einstein person
f9g0h1i2 marie curie person
retrico> :relations "marie curie"
...
retrico> :quit
Environment Variables
| Variable | Description |
|---|---|
LLM_API_KEY | Default LLM API key (used by --api-key options) |
Common Workflows
Quick local graph (no server needed)
retrico connect --store-type falkordb_lite
retrico build --file paper.txt --entity-labels "person,org,location" --relation-labels "works at,born in"
retrico query "Where was Einstein born?" --entity-labels "person,location"
Full pipeline with Neo4j
retrico connect --store-type neo4j --neo4j-uri bolt://localhost:7687 --neo4j-password secret
retrico build --file corpus.txt --entity-labels "person,org,concept" \
--relation-labels "works at,studies,developed" --embed-chunks --embed-entities
retrico community --method leiden --levels 2
retrico query "What did Einstein develop?" --entity-labels "person,concept" \
--strategy entity,community --api-key sk-...
Config-driven pipeline
retrico init build # generate build_config.yaml
retrico build --config build_config.yaml --file data.txt
retrico init query # generate query_config.yaml
retrico query "my question" --config query_config.yaml
Extract and re-ingest
# Extract to JSON (also writes to DB)
retrico build --file paper.txt --entity-labels "person,location" --json-output extracted.json
# Re-ingest into a different database
retrico connect --store-type neo4j --neo4j-uri bolt://production:7687
retrico ingest extracted.json