Skip to content

Commit

Permalink
feat(searching): add similarity threshold to search function
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 24, 2024
1 parent 6101380 commit dd8cd73
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ class SemanticService(val project: Project) {
return chunks
}

suspend fun searching(input: String): List<String> {
suspend fun searching(input: String, threshold: Double = 0.5): List<String> {
val inputEmbedding = embed(input)

return index.findClosest(inputEmbedding, 10).map(ScoredText::text)
return index.findClosest(inputEmbedding, 10)
.filter { it.similarity > threshold }
.map {
"Similarity: ${it.similarity}, Text: ${it.text}"
}
}

suspend fun splitting(path: List<VirtualFile>): List<IndexEntry> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ open class PatternFuncProcessor(open val myProject: Project, open val hole: Hobb
}

is PatternActionFunc.Searching -> {
semanticService.searching(action.text)
semanticService.searching(action.text, action.threshold)
}

is PatternActionFunc.Caching -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ object HobbitHoleParser {
}

"searching" -> {
PatternActionFunc.Searching(args[0])
PatternActionFunc.Searching(args[0], args.getOrNull(1)?.toDouble() ?: 0.5)
}

"caching" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sealed class PatternActionFunc(open val funcName: String) {
/**
* searching text
*/
class Searching(val text: String) : PatternActionFunc("searching")
class Searching(val text: String, val threshold: Double = 0.5) : PatternActionFunc("searching")

/**
* Caching semantic
Expand Down

0 comments on commit dd8cd73

Please sign in to comment.