-
Notifications
You must be signed in to change notification settings - Fork 33
fix(memory): handle mem_src scopes in retrieval #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,7 +208,7 @@ fn resolve_local( | |
| let mut hits = Vec::new(); | ||
| for (id, _) in ordered { | ||
| if let Some(mut hit) = by_id.remove(&id) { | ||
| if source_scope.is_some_and(|scope| !scope.contains(&hit.tree_scope)) { | ||
| if source_scope.is_some_and(|scope| !source_scope_allows(scope, &hit.tree_scope)) { | ||
| continue; | ||
| } | ||
| hit.score = coverage.get(&id).copied().unwrap_or_default(); | ||
|
|
@@ -239,7 +239,9 @@ async fn dense( | |
| ) | ||
| .await?; | ||
| if let Some(scope) = source_scope { | ||
| response.hits.retain(|hit| scope.contains(&hit.tree_scope)); | ||
| response | ||
| .hits | ||
| .retain(|hit| source_scope_allows(scope, &hit.tree_scope)); | ||
| } | ||
| let total = response.hits.len(); | ||
| response.hits.truncate(limit); | ||
|
|
@@ -282,6 +284,19 @@ fn dedup_ids(ids: impl Iterator<Item = String>) -> Vec<String> { | |
| ids.filter(|id| seen.insert(id.clone())).collect() | ||
| } | ||
|
|
||
| fn source_scope_allows(scope: &HashSet<String>, tree_scope: &str) -> bool { | ||
| if scope.contains(tree_scope) { | ||
| return true; | ||
| } | ||
| extract_mem_src_id(tree_scope).is_some_and(|id| scope.contains(id)) | ||
| } | ||
|
|
||
| fn extract_mem_src_id(value: &str) -> Option<&str> { | ||
| let rest = value.strip_prefix("mem_src:")?; | ||
| let (id, _) = rest.split_once(':')?; | ||
| (!id.is_empty()).then_some(id) | ||
| } | ||
|
Comment on lines
+294
to
+298
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| #[cfg(test)] | ||
| #[path = "fast_tests.rs"] | ||
| mod tests; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mem_srcpath in fast retrievalsource_scope_allowsandextract_mem_src_idare not exercised by any test infast_tests.rs. The existing tests (dense_fallback_filters_scope_before_limit,resolve_local_hydrates_leaf_and_summary_and_skips_missing_or_out_of_scope) always use scopes like"slack:#allowed"that match via the directscope.contains(tree_scope)branch, so they never reach the newextract_mem_src_idcode path. A test seeding a tree with scopemem_src:src_vault_hob_local:path/to/note.mdand asource_scopecontaining only"src_vault_hob_local"would confirm the core fix behaves correctly end-to-end throughfast_retrieve.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!