MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / insert_memory

Method insert_memory

core/src/memory/store.rs:75–98  ·  view source on GitHub ↗

Insert a new memory.

(&self, memory: &Memory)

Source from the content-addressed store, hash-verified

73
74 /// Insert a new memory.
75 pub async fn insert_memory(&self, memory: &Memory) -> GraphBitResult<()> {
76 let id = memory.id.to_string();
77 let content = memory.content.clone();
78 let user_id = memory.scope.user_id.clone();
79 let agent_id = memory.scope.agent_id.clone();
80 let run_id = memory.scope.run_id.clone();
81 let hash = memory.hash.clone();
82 let metadata = serde_json::to_string(&memory.metadata)?;
83 let created_at = memory.created_at.to_rfc3339();
84 let updated_at = memory.updated_at.to_rfc3339();
85
86 let conn_arc = Arc::clone(&self.conn);
87 tokio::task::spawn_blocking(move || -> GraphBitResult<()> {
88 let conn = conn_arc.blocking_lock();
89 conn.execute(
90 "INSERT INTO memories (id, content, user_id, agent_id, run_id, hash, metadata, created_at, updated_at)
91 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
92 rusqlite::params![id, content, user_id, agent_id, run_id, hash, metadata, created_at, updated_at],
93 )?;
94 Ok(())
95 })
96 .await
97 .map_err(|e| GraphBitError::memory(format!("Join error: {e}")))?
98 }
99
100 /// Get a single memory by ID.
101 pub async fn get_memory(&self, memory_id: &MemoryId) -> GraphBitResult<Option<Memory>> {

Callers 4

create_memoryMethod · 0.80
test_metadata_store_crudFunction · 0.80

Calls 3

to_stringMethod · 0.80
cloneMethod · 0.80
executeMethod · 0.45

Tested by 3

test_metadata_store_crudFunction · 0.64