oxibrain_cli/cmd/
import_oxios.rs1use oxibrain::{Brain, BrainConfig, SourceRef, TrustTier};
8use oxibrain_connectors::read_oxios_memory;
9use std::path::Path;
10
11pub async fn run(dir: &Path, db: &Path, space: &str) -> anyhow::Result<()> {
12 let entries = read_oxios_memory(db)?;
13 let total = entries.len();
14
15 if total == 0 {
16 println!("no entries found in {}", db.display());
17 return Ok(());
18 }
19
20 println!(
21 "importing {total} entries from {} into space '{space}'…",
22 db.display()
23 );
24
25 let brain = Brain::open(BrainConfig::at(dir)).await?;
26 let space_id = brain.ensure_space(space).await?;
27
28 let mut ok = 0usize;
29 let mut fail = 0usize;
30
31 for entry in &entries {
32 let content = if let Some(summary) = &entry.summary {
34 format!(
35 "[Imported from oxios-memory. Type: {}. Created: {}. Source: {}. Summary: {}]\n\n{}",
36 entry.memory_type, entry.created_at, entry.source, summary, entry.content,
37 )
38 } else {
39 format!(
40 "[Imported from oxios-memory. Type: {}. Created: {}. Source: {}]\n\n{}",
41 entry.memory_type, entry.created_at, entry.source, entry.content,
42 )
43 };
44
45 match brain
46 .ingest(
47 &space_id,
48 content,
49 SourceRef::AgentTrace,
50 TrustTier::SemiTrusted,
51 "import-oxios/v1",
52 )
53 .await
54 {
55 Ok(_) => ok += 1,
56 Err(e) => {
57 eprintln!(" WARN: failed to import entry {}: {e}", entry.id);
58 fail += 1;
59 }
60 }
61 }
62
63 println!("done: {ok} imported, {fail} failed (out of {total})");
64 if ok > 0 {
65 println!(
66 "\nRun `oxibrain reextract --space {space}` to extract knowledge from imported entries."
67 );
68 }
69 Ok(())
70}