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

Method create_memory

core/src/memory/service.rs:206–241  ·  view source on GitHub ↗

Create a brand-new memory: hash, embed, store, index, record history.

(
        &self,
        content: &str,
        scope: MemoryScope,
    )

Source from the content-addressed store, hash-verified

204
205 /// Create a brand-new memory: hash, embed, store, index, record history.
206 async fn create_memory(
207 &self,
208 content: &str,
209 scope: MemoryScope,
210 ) -> GraphBitResult<Memory> {
211 let now = Utc::now();
212 let hash = simple_hash(content);
213 let id = MemoryId::new();
214
215 let memory = Memory {
216 id: id.clone(),
217 content: content.to_string(),
218 scope,
219 metadata: HashMap::new(),
220 created_at: now,
221 updated_at: now,
222 hash,
223 };
224
225 self.store.insert_memory(&memory).await?;
226
227 let embedding = self.embedding_service.embed_text(content).await?;
228 self.vector_index.insert(id.clone(), embedding).await;
229
230 self.store
231 .insert_history(&MemoryHistory {
232 memory_id: id,
233 old_content: String::new(),
234 new_content: content.to_string(),
235 action: MemoryAction::Add,
236 timestamp: now,
237 })
238 .await?;
239
240 Ok(memory)
241 }
242
243 /// Update an existing memory: re-hash, re-embed, persist, record history.
244 async fn update_memory_internal(

Callers 1

addMethod · 0.80

Calls 7

simple_hashFunction · 0.85
cloneMethod · 0.80
to_stringMethod · 0.80
insert_memoryMethod · 0.80
embed_textMethod · 0.80
insertMethod · 0.80
insert_historyMethod · 0.80

Tested by

no test coverage detected