Repository navigation
fix(index): restrict find_related to the seed chunk's language #123
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
Changes from all commits
13b1c76
15fcd84
5900043
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -255,17 +255,34 @@ impl CspIndex { | |||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /// Find chunks similar to a seed, excluding the seed itself. | ||||||||||||||||||||||||||||||||||||||||||
| /// Find chunks similar to a seed, excluding the seed itself. Candidates are | ||||||||||||||||||||||||||||||||||||||||||
| /// limited to the seed's language when it has one. | ||||||||||||||||||||||||||||||||||||||||||
| pub fn find_related(&self, seed: &Chunk, options: &QueryOptions) -> Vec<SearchResult> { | ||||||||||||||||||||||||||||||||||||||||||
| let top_k = options.top_k.unwrap_or(DEFAULT_TOP_K); | ||||||||||||||||||||||||||||||||||||||||||
| if top_k == 0 || self.chunks.is_empty() { | ||||||||||||||||||||||||||||||||||||||||||
| return Vec::new(); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Mirror upstream (`if target.language`): an absent or empty language is | ||||||||||||||||||||||||||||||||||||||||||
| // falsy there, so the search stays unrestricted. | ||||||||||||||||||||||||||||||||||||||||||
| let selector = seed | ||||||||||||||||||||||||||||||||||||||||||
| .language | ||||||||||||||||||||||||||||||||||||||||||
| .as_ref() | ||||||||||||||||||||||||||||||||||||||||||
| .filter(|lang| !lang.is_empty()) | ||||||||||||||||||||||||||||||||||||||||||
| .and_then(|lang| { | ||||||||||||||||||||||||||||||||||||||||||
| self.build_selector(&QueryOptions { | ||||||||||||||||||||||||||||||||||||||||||
| filter_languages: Some(vec![lang.clone()]), | ||||||||||||||||||||||||||||||||||||||||||
| ..Default::default() | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+268
to
+277
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. [MEDIUM] Query filters in Problem: The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| if selector.as_ref().is_some_and(Vec::is_empty) { | ||||||||||||||||||||||||||||||||||||||||||
| return Vec::new(); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| let query_embedding = self.model.encode(std::slice::from_ref(&seed.content)); | ||||||||||||||||||||||||||||||||||||||||||
| let batch = self | ||||||||||||||||||||||||||||||||||||||||||
| .semantic_index | ||||||||||||||||||||||||||||||||||||||||||
| .query(&query_embedding, top_k + 1, None) | ||||||||||||||||||||||||||||||||||||||||||
| .query(&query_embedding, top_k + 1, selector.as_deref()) | ||||||||||||||||||||||||||||||||||||||||||
| .unwrap_or_default(); | ||||||||||||||||||||||||||||||||||||||||||
| let Some(first) = batch.into_iter().next() else { | ||||||||||||||||||||||||||||||||||||||||||
| return Vec::new(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.