Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(memory): backfill embeddings for unindexed memories

Steven Enamakel60952273b4bc
diff --git a/crates/openhuman-core/src/memory/backfill.rs b/crates/openhuman-core/src/memory/backfill.rs
index 8335d46165..ec46e3e19f 100644
--- a/crates/openhuman-core/src/memory/backfill.rs
+++ b/crates/openhuman-core/src/memory/backfill.rs
@@ -132,17 +132,18 @@ struct ThreadPlan {
}
async fn plan(
+ ctx: &DispatchCtx,
workspace_dir: &Path,
bound: Option<&BoundEngine>,
stored: &BTreeMap<String, u32>,
) -> MemoryResult<Vec<ThreadPlan>> {
- let listed = threads::list_threads(DispatchCtx::ambient(), workspace_dir.to_path_buf())
+ let listed = threads::list_threads(ctx.clone(), workspace_dir.to_path_buf())
.await
.map_err(|error| MemoryError::Engine(format!("reading chat threads failed: {error}")))?;
let mut plans = Vec::new();
for thread in listed {
let messages = match threads::get_messages(
- DispatchCtx::ambient(),
+ ctx.clone(),
workspace_dir.to_path_buf(),
thread.id.clone(),
)
@@ -187,7 +188,7 @@ fn is_running(workspace_dir: &Path) -> bool {
}
/// `memory_conversations_backfill_status`.
-pub async fn status(config: &Config) -> MemoryResult<BackfillView> {
+pub async fn status(ctx: &DispatchCtx, config: &Config) -> MemoryResult<BackfillView> {
let workspace_dir = &config.workspace_dir;
let file = read_file(workspace_dir);
let mut state = file.state;
@@ -196,7 +197,7 @@ pub async fn status(config: &Config) -> MemoryResult<BackfillView> {
state.error = Some("the sync was interrupted; start it again to resume".to_string());
}
let bound = engine::resolve(config).engine().ok();
- let plans = plan(workspace_dir, bound.as_ref(), &file.stored).await?;
+ let plans = plan(ctx, workspace_dir, bound.as_ref(), &file.stored).await?;
Ok(BackfillView {
state,
pending_threads: plans.len() as u64,
@@ -205,7 +206,10 @@ pub async fn status(config: &Config) -> MemoryResult<BackfillView> {
}
/// `memory_conversations_backfill_start`: requires `consent` and memory on.
-pub async fn start(config: &Config, params: BackfillStartParams) -> MemoryResult<BackfillView> {
+pub async fn start(
+ ctx: &DispatchCtx,
+ config: &Config,
+ params: BackfillStartParams) -> MemoryResult<BackfillView> {
if !params.consent {
return Err(MemoryError::invalid(
"storing past chats uploads them to the selected engine; pass consent: true",
@@ -221,7 +225,7 @@ pub async fn start(config: &Config, params: BackfillStartParams) -> MemoryResult
return status(config).await;
}
let mut file = read_file(&workspace_dir);
- let plans = match plan(&workspace_dir, Some(&bound), &file.stored).await {
+ let plans = match plan(ctx, &workspace_dir, Some(&bound), &file.stored).await {
Ok(plans) => plans,
Err(error) => {
release(&workspace_dir);
diff --git a/crates/openhuman-core/src/memory/schemas/handlers.rs b/crates/openhuman-core/src/memory/schemas/handlers.rs
index 50846925e9..c156df8bc4 100644
--- a/crates/openhuman-core/src/memory/schemas/handlers.rs
+++ b/crates/openhuman-core/src/memory/schemas/handlers.rs
@@ -167,7 +167,7 @@ pub(super) fn conversations_backfill_status(
) -> ControllerFuture {
Box::pin(async move {
parse::<EmptyParams>(params)?;
- finish(backfill::status(&load(&ctx).await?).await)
+ finish(backfill::status(&ctx, &load(&ctx).await?).await)
})
}
@@ -177,7 +177,7 @@ pub(super) fn conversations_backfill_start(
) -> ControllerFuture {
Box::pin(async move {
let params = parse::<backfill::BackfillStartParams>(params)?;
- finish(backfill::start(&load(&ctx).await?, params).await)
+ finish(backfill::start(&ctx, &load(&ctx).await?, params).await)
})
}