Skip to main content

sqlite_graphrag/commands/merge_entities/
args.rs

1//! CLI surface of the `merge-entities` subcommand.
2
3use crate::output::OutputFormat;
4
5#[derive(clap::Args)]
6#[command(after_long_help = "EXAMPLES:\n  \
7    # Merge two source entities into a target\n  \
8    sqlite-graphrag merge-entities --names auth,authentication --into auth-service\n\n  \
9    # Merge three sources into one target across a namespace\n  \
10    sqlite-graphrag merge-entities --names svc-a,svc-b,old-svc --into canonical-service --namespace my-project\n\n  \
11    # Merge by ID (unambiguous when homonyms exist across namespaces)\n  \
12    sqlite-graphrag merge-entities --ids 12,17 --into-id 3\n\n\
13NOTE:\n  \
14    --names is a comma-separated list of source entity names.\n  \
15    --into is the target entity name and must already exist.\n  \
16    --ids / --into-id select entities by ID; IDs are globally unique so they\n  \
17    disambiguate homonyms. They conflict with --names / --into respectively\n  \
18    and must belong to the resolved namespace.\n  \
19    Source entities are deleted after the merge; the target is preserved.\n  \
20    Duplicate relationships (same endpoints + relation) are removed automatically.\n  \
21    Run `sqlite-graphrag cleanup-orphans` afterwards if sources had no other links.")]
22/// Merge entities args.
23pub struct MergeEntitiesArgs {
24    /// Comma-separated list of source entity names to merge into the target.
25    #[arg(
26        long,
27        value_delimiter = ',',
28        value_name = "NAMES",
29        required_unless_present = "ids",
30        conflicts_with = "ids"
31    )]
32    pub names: Vec<String>,
33    /// v1.1.1 (P5): comma-separated list of source entity IDs. IDs are
34    /// globally unique, so they disambiguate homonyms across namespaces.
35    /// Conflicts with --names; every ID must belong to the resolved namespace.
36    #[arg(long, value_delimiter = ',', value_name = "IDS")]
37    pub ids: Vec<i64>,
38    /// Target entity name. Must already exist. All source relationships are redirected here.
39    #[arg(
40        long,
41        value_name = "TARGET",
42        required_unless_present = "into_id",
43        conflicts_with = "into_id"
44    )]
45    pub into: Option<String>,
46    /// v1.1.1 (P5): target entity ID. Unambiguous alternative to --into.
47    #[arg(long, value_name = "TARGET_ID")]
48    pub into_id: Option<i64>,
49    /// Namespace scope.
50    #[arg(long)]
51    pub namespace: Option<String>,
52    /// Output format.
53    #[arg(long, value_enum, default_value = "json")]
54    pub format: OutputFormat,
55    /// Emit machine-readable JSON on stdout.
56    #[arg(long, hide = true, help = "No-op; JSON is always emitted on stdout")]
57    pub json: bool,
58    /// Path to the SQLite database file.
59    #[arg(long)]
60    pub db: Option<String>,
61    /// v1.1.03: allow merging source entities from OTHER namespaces into the
62    /// target. Default false preserves same-namespace safety. When true, each
63    /// --ids source is resolved by its own row (no namespace filter); target
64    /// must still exist in the resolved namespace.
65    #[arg(long, default_value_t = false, hide = false)]
66    pub cross_namespace: bool,
67}